Magento:如何在产品列表页面中显示可配置的产品选项?

标签 magento configurable

如何在产品列表页面显示可配置的产品选项?

我想将可配置的产品选项显示为产品列表页面本身的下拉菜单。选择选项后,价格应自动更改。

提前致谢。

最佳答案

转到 app/design/frontend/YOUR_package/YOUR_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 ?>

关于Magento:如何在产品列表页面中显示可配置的产品选项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23950764/

相关文章:

magento在迷你购物车中获取可配置产品添加的简单产品图像

attributes - 向 Magento 报价/订单添加新属性

php - Magento 集合 - 按多个字段过滤

Magento 分层导航可配置产品缺货

php - Magento - 如何将可配置产品图像链接到简单产品图像?

processor - 在 FPGA 板上实现的可配置处理器

php - Magento 客户登录页面在登录后立即再次加载,并且未创建 Frontedn cookie

php - 获取只有子类别有产品的类别的类别计数

php - Magento,添加没有可配置产品的服装尺寸属性

Magento - 将可配置的产品选项附加费添加到分级定价中