2012-02-12 79 views
2

我想在产品列表页面中显示产品组合产品和分组产品的选项。在产品列表页面上显示产品组合和分组产品选项

我在网上发现了一个脚本来显示可配置的产品,但我正在努力寻找一个捆绑和分组。

基本上我希望它显示的选项完全相同,就像我正在查看实际产品页面一样。

感谢

+0

您是否找到了解决方案? – MatheusJardimB 2013-06-08 16:03:53

回答

1

尝试用下面的代码

1)把这三个以下功能在list.php的文件,如果你有覆盖它,否则第一个覆盖该文件法师/目录/块?产品/列表.PHP

protected function _getProduct($sku) 
    { 
     $_productId = Mage::getModel('catalog/product')->getIdBySku($sku); 
     if($_productId) 
     { 
      return Mage::getModel('catalog/product')->load($_productId);  
     } 
     return null; 
    } 

    public function getAssociatedProducts($sku) 
    { 
     $_product = $this->_getProduct($sku); 
     $simpleProducts = $_product->getTypeInstance(true)->getAssociatedProducts($_product); 
     return $simpleProducts; 
    } 

    /** 
    * Set preconfigured values to grouped associated products 
    * 
    * @return Mage_Catalog_Block_Product_View_Type_Grouped 
    */ 
    public function setPreconfiguredValue($sku) { 
     $_product = $this->_getProduct($sku); 
     $configValues = $_product->getPreconfiguredValues()->getSuperGroup(); 
     if (is_array($configValues)) { 
      $associatedProducts = $this->getAssociatedProducts($sku); 
      foreach ($associatedProducts as $item) { 
       if (isset($configValues[$item->getId()])) { 
        $item->setQty($configValues[$item->getId()]); 
       } 
      } 
     } 
     return $this; 
    } 

2)把下面的代码在你的list.phtml文件设计/前端/预设/默认/模板/ catelog /产品/ list.phtml此行之后

<?php echo $this->getPriceHtml($_product, true) ?> 

<?php if($_product->getTypeId() == 'grouped'){ ?> 
       <?php $this->setPreconfiguredValue($_product->getSku()); ?> 
       <?php $_associatedProducts = $this->getAssociatedProducts($_product->getSku()); ?> 
       <?php $_hasAssociatedProducts = count($_associatedProducts) > 0; ?> 
       <table class="data-table grouped-items-table" id="super-product-table"> 
        <col /> 
        <col /> 
        <col width="1" /> 
        <thead> 
         <tr> 
          <th><?php echo $this->__('Name') ?></th> 
          <?php if ($this->getCanShowProductPrice($_product)): ?> 
          <th class="a-right"><?php echo $this->__('Price') ?></th> 
          <?php endif; ?> 
         </tr> 
        </thead> 
        <tbody> 
        <?php if ($_hasAssociatedProducts): ?> 
        <?php foreach ($_associatedProducts as $_item): ?> 
         <?php $_finalPriceInclTax = $this->helper('tax')->getPrice($_item, $_item->getFinalPrice(), true) ?> 
         <tr> 
          <td><?php echo $this->htmlEscape($_item->getName()) ?></td> 
          <?php if ($this->getCanShowProductPrice($_product)): ?> 
          <td class="a-right"> 
           <?php if ($this->getCanShowProductPrice($_item)): ?> 
           <?php echo $this->getPriceHtml($_item, true) ?> 
           <?php endif; ?> 
          </td> 
          <?php endif; ?> 
         </tr> 
        <?php endforeach; ?> 
        <?php else: ?> 
         <tr> 
          <td colspan="<?php if ($_product->isSaleable()): ?>4<?php else : ?>3<?php endif; ?>"><?php echo $this->__('No options of this product are available.') ?></td> 
         </tr> 
        <?php endif; ?> 
        </tbody> 
       </table> 
       <script type="text/javascript">decorateTable('super-product-table')</script> 
       <?php } ?> 

3)enter image description here

可能对你有帮助! 注意:此代码仅适用于分组产品