【问题标题】:Magento jQuery tabs per attribute in list.phmtllist.phmtl 中每个属性的 Magento jQuery 选项卡
【发布时间】:2013-08-01 10:23:27
【问题描述】:
我正在使用 Magento 1.7.0.2 并且有一些简单的产品,具有自定义属性,显示在类别产品列表中。
我希望通过产品的自定义属性来拆分产品列表,因此每个属性在标签中都有一个产品列表,因此我可以使用 jQuery 选项卡来拆分类别。
我看到 default\template\catalog\product\list.phtml 生成了产品列表:
$_productCollection=$this->getLoadedProductCollection();
如何按属性将产品拆分为单独的 div?
提前致谢。
【问题讨论】:
标签:
magento
magento-1.7
jquery-ui-tabs
【解决方案1】:
就拆分这些产品的逻辑而言,您可以获取加载的产品集合,并在 foreach 循环中检查每个产品的属性并将它们分配给适当的新数组。
例如:
<?php
$_productSegments = array(
'attribute1' => array(),
'attribute2' => array(),
);
foreach ($_productCollection as $_product) {
if ($_product->hasAttribute1()) {
$_productSegments['attribute1'][] = $_product;
}
if ($_product->hasAttribute2()) {
$_productSegments['attribute1'][] = $_product;
}
}
?>
<?php foreach ($_productSegments as $_productSegment): ?>
<?php if (!empty($_productSegment)): ?>
<div>
<?php // Whatever product info you want here. Use jQuery logic to make it into tabs ?>
<?php foreach ($_productSegment as $_product): ?>
<?php echo $_product->getName() ?>
<?php endforeach ?>
</div>
<?php endif; ?>
<?php endforeach ?>