Search code examples
magentomagento-1.7jquery-ui-tabs

Magento jQuery tabs per attribute in list.phmtl


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.


Solution

  • As far as the logic goes for splitting these products up, you could take the loaded product collection, and in a foreach loop check the attributes of each product and assign them to appropriate, new arrays.

    For example:

    <?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 ?>