Magento 显示捆绑&;产品列表页面上的分组产品选项

Magento 显示捆绑&;产品列表页面上的分组产品选项,magento,Magento,我试图在产品列表页面中显示捆绑产品和分组产品的选项 我在互联网上找到了一个显示可配置产品的脚本,但我很难在捆绑包和分组中找到一个 基本上,我希望它显示的选项与我查看实际产品页面时显示的选项完全相同 谢谢请尝试以下代码 1)如果要覆盖list.php文件,请将下面三个函数放在该文件中,否则首先覆盖该文件Mage/Catalog/Block?Product/list.php protected function _getProduct($sku) { $_productId

我试图在产品列表页面中显示捆绑产品和分组产品的选项

我在互联网上找到了一个显示可配置产品的脚本,但我很难在捆绑包和分组中找到一个

基本上,我希望它显示的选项与我查看实际产品页面时显示的选项完全相同

谢谢

请尝试以下代码

1)如果要覆盖list.php文件,请将下面三个函数放在该文件中,否则首先覆盖该文件Mage/Catalog/Block?Product/list.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文件design/frontend/default/default/template/catelog/product/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  }  ?>


你找到解决办法了吗?