如何在类别列表页面中查看显示可配置的产品选项?

有帮助吗?

解决方案

为了在类别中显示所有可销售选项,请访问 .../app/design/frontend/[package]/[theme]/template/catalog/product/list.phtml 并放在里面 foreach ($_productCollection as $_product) 这样的事情:

<?php if($_product->isConfigurable()): ?>
  //get attributes
  <?php $attributes = $_product->getTypeInstance(true)->getConfigurableAttributes($_product) ?>
  <?php if(count($attributes)): ?>
    <ul>
    <?php foreach($attributes as $att): ?>
      <?php $pAtt=$att->getProductAttribute();
        //get the child products
        $allProducts = $_product->getTypeInstance(true)->getUsedProducts(null, $_product);
        $frontValues =array() ?>
      <li><?php echo $pAtt->getFrontendLabel() ?>
       <ul>
       <?php foreach($allProducts as $p): ?>
         //check stock, status, ...
         //do not show unsaleable options
         <?php if(!$p->isSaleable()) continue; ?>
         <?php $out=$p->getAttributeText($pAtt->getName()); ?>
         <?php $frontValues[$out]=$out; ?>
       <?php endforeach ?>
        <li><?php echo implode('</li><li>', $frontValues) ?></li>
       </ul>
      </li>
    <?php endforeach ?>
    </ul>
  <?php endif ?>
<?php endif ?>

也许您喜欢在 <ul><li> 标签。

这不会增加您的商店的性能!

受这篇文章的启发

http://www.magentocommerce.com/boards/viewthread/73926/#t437146

其他提示

您可以使用类似的东西 if ($_product->getTypeId() == 'configurable') 产品内部循环。

这可以吸收大量的服务器资源,因为每种产品可能有很多选项。最好的方法是使用Ajax在询问时仅加载所有选项。我发现此扩展名将首先加载颜色,然后当您鼠标端接时,它将为您提供所有产品选项。

http://www.consofas.com/plugins/options-quickview-for-configurable-products-in-magento/

尝试一次

<?php $ptype = $_product->getTypeId();?>
<?php 
                                                if($ptype=='configurable'): ?>
                                                <!--get attributes-->
                                                <?php 
                                                $attributes = $_product->getTypeInstance(true)->getConfigurableAttributes($_product) ?>
                                                <?php 
                                                if(count($attributes)): ?>
                                                <?php 
                                                    foreach($attributes as $att): ?>
                                                    <?php 
                                                        $pAtt=$att->getProductAttribute();
                                                        //get the child products
                                                        $allProducts = $_product->getTypeInstance(true)->getUsedProducts($_product,null);
                                                        $frontValues =array();
                                                        foreach($allProducts as $p):
                                                            if($p->isSaleable()):
                                                                $attributeExist =$_product->getResource()->getAttribute($pAtt->getName());
                                                            ?>
                                                                <input type="hidden" name="super_attribute[<?php echo $pAtt->getAttributeId() ?>]" value="<?php  echo $attributeExist->getSource()->getOptionId($p->getAttributeText($pAtt->getName()));?>">
                                                            <?php
                                                                break;
                                                            endif;
                                                        endforeach;
                                                    endforeach;
                                                endif;
                                                    ?>
                                                <?php
                                                endif;
                                                ?>

以下链接可能会帮助您。

http://hkpatel201.blogspot.in/2012/09/get-product-custom-option-in-list-page.html

浏览代码

谢谢

许可以下: CC-BY-SA归因
scroll top