Magento - 如何在我的产品页面中显示相关产品?

时间:2014-02-22 20:37:41

标签: php magento

我有这个,我认为这是一个块代码,它在产品页面中显示该产品的相关产品。

/template/catalog/product/list/releated_products.phtml:

<?php if($this->getItems()->getSize()): ?>
<div class="related-products">
  <h2><?php echo $this->__('Related Products') ?></h2>
  <ol class="products-grid row" id="block-related">
    <?php foreach($this->getItems() as $_item): ?>
    <li class="item span3">
      <?php if(!$_item->isComposite() && $_item->isSaleable()): ?>
      <?php endif; ?>
      <div class="product"> <a href="<?php echo $_item->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_item->getName()) ?>" class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_item, 'thumbnail')->resize(590,714) ?>" alt="<?php echo $this->htmlEscape($_item->getName()) ?>" /></a>
        <div class="product-details">
          <p class="product-name"><a href="<?php echo $_item->getProductUrl() ?>"><?php echo $this->htmlEscape($_item->getName()) ?></a></p>
          <?php echo $this->getPriceHtml($_item, true, '-related') ?>
          <?php if ($this->helper('wishlist')->isAllow()) : ?>
          <a href="<?php echo $this->getAddToWishlistUrl($_item) ?>" class="link-wishlist"><?php echo $this->__('Add to Wishlist') ?></a>
          <?php endif; ?>
        </div>
      </div>
    </li>
    <?php endforeach ?>
  </ol>
  <script type="text/javascript">decorateList('block-related', 'none-recursive')</script> 
  <script type="text/javascript">
    //<![CDATA[
    $$('.related-checkbox').each(function(elem){
        Event.observe(elem, 'click', addRelatedToProduct)
    });

    var relatedProductsCheckFlag = false;
    function selectAllRelated(txt){
        if (relatedProductsCheckFlag == false) {
            $$('.related-checkbox').each(function(elem){
                elem.checked = true;
            });
            relatedProductsCheckFlag = true;
            txt.innerHTML="<?php echo $this->__('unselect all') ?>";
        } else {
            $$('.related-checkbox').each(function(elem){
                elem.checked = false;
            });
            relatedProductsCheckFlag = false;
            txt.innerHTML="<?php echo $this->__('select all') ?>";
        }
        addRelatedToProduct();
    }

    function addRelatedToProduct(){
        var checkboxes = $$('.related-checkbox');
        var values = [];
        for(var i=0;i<checkboxes.length;i++){
            if(checkboxes[i].checked) values.push(checkboxes[i].value);
        }
        if($('related-products-field')){
            $('related-products-field').value = values.join(',');
        }
    }
    //]]>
    </script> 
</div>
<?php endif ?>

所以我如何在我的view.phtml中显示这个块,它显示了产品视图页面的信息。我想将其粘贴在产品说明之后。

提前致谢!

1 个答案:

答案 0 :(得分:1)