duangang4001 2013-02-13 08:34
浏览 70
已采纳

Magento代码自适应在比较页面中显示自定义属性值

I'm running magento 1.7.0.2, I have an extension that overwrites the attribute values in navigation and product page but not in compare page.

For that i need to adapt code from attributes.phtml to list.phtml, but as my programming skills are very limited i really have no idea how to do this.

product attributes.phtml file that is giving me the required output:

<?php
/**
 * Product additional attributes template
 *
 * @see Mage_Catalog_Block_Product_View_Attributes
 */
?>

<?php
    $_helper = $this->helper('catalog/output');
    $_product = $this->getProduct()
?>
<?php if($_additional = $this->getAdditionalData()): ?>
<div class="box-collateral box-additional">
    <table class="data-table" id="product-attribute-specs-table">
        <col width="25%" />
        <col />
        <tbody>
        <?php foreach ($_additional as $_data): ?>
            <tr>
                <th class="label"><?php echo $this->htmlEscape($this->__($_data['label'])) ?></th>

//edited to check and print custom value

                   <?php if (($numberOptions = Mage::getModel('mana_filters/filter2')->load($_data['code'], 'code')) && $numberOptions->getDisplay() == 'slider') : ?> 
                       <td class="data"><?php  echo Mage::helper('manapro_filtersuperslider')->formatNumber($_product->getData($_data['code']), $numberOptions) ?></td> 
                   <?php else : ?>
                       <td class="data"><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td> 
                   <?php endif; ?>
//edit end

            </tr>
        <?php endforeach; ?>
        </tbody>
    </table>
    <script type="text/javascript">decorateTable('product-attribute-specs-table')</script>
</div>
<?php endif;?>

The edited code should be adapted to this this lists.phtml

<?php
/**
 * @category    design
 * @package     base_default
 * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
/* @var $this Mage_Catalog_Block_Product_Compare_List */
?>
<div class="page-title title-buttons">
    <h1><?php echo $this->__('Compare Products') ?></h1>
    <a href="#" onclick="window.print(); return false;" class="link-print"><?php echo $this->__('Print This Page') ?></a>
</div>
<?php $_total=$this->getItems()->getSize() ?>
<?php if($_total): ?>
    <table class="data-table compare-table" id="product_comparison">
    <?php $_i=0 ?>
    <?php foreach($this->getItems() as $_item): ?>
        <?php if($_i++%10==0): ?>
            <col width="1" />
        <?php endif; ?>
            <col width="<?php echo floor(100/$_total); ?>%" />
    <?php endforeach; ?>
<?php if ($_total>2): ?>
        <thead>
            <tr>
            <?php $_i=0 ?>
            <?php foreach($this->getItems() as $_item): ?>
                <?php if($_i++%10==0): ?>
                    <th>&nbsp;</th>
                <?php endif; ?>
                <td class="a-right"><a href="#" class="btn-remove" onclick="removeItem('<?php echo $this->helper('catalog/product_compare')->getRemoveUrl($_item) ?>');" title="<?php echo $this->__('Remove This Item') ?>"><?php echo $this->__('Remove This Item') ?></a></td>
            <?php endforeach; ?>
            </tr>
        </thead>
<?php endif ?>
        <tbody>
            <tr class="product-shop-row">
            <?php $_i=0 ?>
            <?php foreach($this->getItems() as $_item): ?>
                <?php if($_i++%10==0): ?>
                    <th>&nbsp;</th>
                <?php endif; ?>
                <td>
                    <a class="product-image" href="#" onclick="setPLocation('<?php echo $this->getProductUrl($_item) ?>', true)" title="<?php echo $this->stripTags($_item->getName(), null, true) ?>"><img src="<?php echo $this->helper('catalog/image')->init($_item, 'small_image')->resize(125, 125); ?>" width="125" height="125" alt="<?php echo $this->stripTags($_item->getName(), null, true) ?>" /></a>
                    <h2 class="product-name"><a href="#" onclick="setPLocation('<?php echo $this->getProductUrl($_item) ?>', true)" title="<?php echo $this->stripTags($_item->getName(), null, true) ?>"><?php echo $this->helper('catalog/output')->productAttribute($_item, $_item->getName(), 'name') ?></a></h2>
                    <?php echo $this->getReviewsSummaryHtml($_item, 'short') ?>
                    <?php echo $this->getPriceHtml($_item, true, '-compare-list-top') ?>
                    <?php if($_item->isSaleable()): ?>
                        <p><button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setPLocation('<?php echo $this->helper('catalog/product_compare')->getAddToCartUrl($_item) ?>', true)"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button></p>
                    <?php else: ?>
                        <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
                    <?php endif; ?>
                    <?php if ($this->helper('wishlist')->isAllow()) : ?>
                        <ul class="add-to-links">
                            <li><a href="<?php echo $this->getAddToWishlistUrl($_item) ?>" class="link-wishlist" onclick="setPLocation(this.href, true)"><?php echo $this->__('Add to Wishlist') ?></a></li>
                        </ul>
                    <?php endif; ?>
                </td>
            <?php endforeach; ?>
            </tr>
        </tbody>
        <tbody>
        <?php foreach ($this->getAttributes() as $_attribute): ?>
            <tr>
                <?php $_i=0 ?>
                <?php foreach($this->getItems() as $_item): ?>
                <?php if($_i++%10==0): ?>
                <th><span class="nobr"><?php echo $_attribute->getStoreLabel() ?></span></th>
                <?php endif; ?>

//I think the adapted code should go somewhere here

                    <td>
                    <?php switch ($_attribute->getAttributeCode()) {
                        case "price": ?>
                            <?php echo $this->getPriceHtml($_item, true, '-compare-list-' . $_attribute->getCode()) ?>
                            <?php break;
                        case "small_image": ?>
                            <img src="<?php echo $this->helper('catalog/image')->init($_item, 'small_image')->resize(125, 125); ?>" width="125" height="125" alt="<?php echo $this->htmlEscape($_item->getName()) ?>" title="<?php echo $this->htmlEscape($_item->getName()) ?>" />
                            <?php break;
                        case "date":
                              echo substr($this->getProductAttributeValue($_item, $_attribute),0,10);
                              break;
                        default: ?>
                            <div class="std">
                                <?php echo $this->helper('catalog/output')->productAttribute($_item, $this->getProductAttributeValue($_item, $_attribute), $_attribute->getAttributeCode()) ?>
                            </div>
                            <?php break;
                    } ?>
                </td>
                <?php endforeach; ?>
            </tr>
        <?php endforeach; ?>
        </tbody>
        <tbody>
                <tr class="add-to-row">
                <?php $_i=0 ?>
                <?php foreach($this->getItems() as $_item): ?>
                <?php if($_i++%10==0): ?>
                <th>&nbsp;</th>
                <?php endif; ?>
                <td>
                    <?php echo $this->getPriceHtml($_item, true, '-compare-list-bottom') ?>
                    <?php if($_item->isSaleable()): ?>
                        <p><button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setPLocation('<?php echo $this->helper('catalog/product_compare')->getAddToCartUrl($_item) ?>', true)"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button></p>
                    <?php else: ?>
                        <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
                    <?php endif; ?>
                    <?php if ($this->helper('wishlist')->isAllow()) : ?>
                        <ul class="add-to-links">
                            <li><a href="<?php echo $this->getAddToWishlistUrl($_item);?>" class="link-wishlist" onclick="setPLocation(this.href, true)"><?php echo $this->__('Add to Wishlist') ?></a></li>
                        </ul>
                    <?php endif; ?>
                </td>
                <?php endforeach; ?>
            </tr>
        </tbody>
    </table>
    <div class="buttons-set">
        <button type="button" title="<?php echo $this->__('Close Window') ?>" class="button" onclick="window.close();"><span><span><?php echo $this->__('Close Window') ?></span></span></button>
        <span class="please-wait" id="compare-list-please-wait" style="display:none;">
            <img src="<?php echo $this->getSkinUrl('images/opc-ajax-loader.gif') ?>" alt="<?php echo $this->__('Please wait...') ?>" title="<?php echo $this->__('Please wait...') ?>" class="v-middle" /> <?php echo $this->__('Please wait...') ?>
        </span>
    </div>
    <script type="text/javascript">
        decorateTable('product_comparison');

        /**
         * Send remove item request, after that reload windows
         */
        function removeItem(url)
        {
            new Ajax.Request(url, {
                parameters: {isAjax: 1, method: 'POST'},
                onLoading: function(){$('compare-list-please-wait').show();},
                onSuccess: function(transport) {
                    $('compare-list-please-wait').hide();
                    window.location.reload();
                    window.opener.location.reload();
                }
            });
        }
    </script>
<?php else: ?>
    <script type="text/javascript">window.close();</script>
<?php endif; ?>
  • 写回答

1条回答 默认 最新

  • douju6850 2013-02-13 12:50
    关注

    You should add your code in the default case of your switch :

    default: ?>
                            <div class="std">
                                <?php echo $this->helper('catalog/output')->productAttribute($_item, $this->getProductAttributeValue($_item, $_attribute), $_attribute->getAttributeCode()) ?>
                            </div>
                            <?php break;
    

    becomes

     default: ?>
                            <div class="std">
                                <?php if (($numberOptions = Mage::getModel('mana_filters/filter2')->load($_attribute->getAttributeCode(), 'code')) && $numberOptions->getDisplay() == 'slider') : ?> 
                      <?php  echo Mage::helper('manapro_filtersuperslider')->formatNumber($_item->getData($_attribute->getAttributeCode()), $numberOptions) ?>
                   <?php else : ?>
                      <?php echo $this->helper('catalog/output')->productAttribute($_item, $this->getProductAttributeValue($_item, $_attribute), $_attribute->getAttributeCode()) ?>
                   <?php endif; ?>
                            </div>
                            <?php break;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿