如何在产品列表页面显示可配置的产品选项?
我想将可配置的产品选项显示为产品列表页面本身的下拉菜单。选择选项后,价格应自动更改。
提前致谢。
最佳答案
转到 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/