0

I am using Magento 1.7.0.2 and have some simple products, with custom attributes, being displayed in a category product listing.

I am looking to split the product listing by the products' custom attribute so each attribute has a list of products within tags so I can use jQuery tabs to split the categories up.

I see that default\template\catalog\product\list.phtml generates the list of products:

$_productCollection=$this->getLoadedProductCollection();

How would I go about splitting the products into separate divs by attribute?

Thanks in advance.

4

1 回答 1

0

就拆分这些产品的逻辑而言,您可以获取加载的产品集合,并在 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 ?>
于 2013-08-01T10:31:30.273 回答