0

I want to display Attribute Group set Name on frontend of compare page. i tired due to searching. anybody knows how to make attribute group set on compare product page list. please help. your help be appreciated.

my code is

In app/design/frontent/sm-market/default/template/catalog/product/compare/list.phtml

<?php
<div class="page-title title-buttons">
    <h1><?php echo $this->__('Compare Products') ?></h1>
    <a href="#" onclick="window.print(); return false;" class="link-print"><?php echo $this->__('Print This Page') ?></a>
</div>
<?php $_total=$this->getItems()->getSize() ?>
<?php if($_total): ?>
    <table class="data-table compare-table" id="product_comparison">
    <?php $_i=0 ?>
    <?php foreach($this->getItems() as $_item): ?>
        <?php if($_i++%10==0): ?>
            <col width="1" />
        <?php endif; ?>
            <col width="<?php echo floor(100/$_total); ?>%" />
    <?php endforeach; ?>
<?php if ($_total>2): ?>
        <thead>
            <tr>
            <?php $_i=0 ?>
            <?php foreach($this->getItems() as $_item): ?>
                <?php if($_i++%10==0): ?>
                    <th>&nbsp;</th>
                <?php endif; ?>
                <td class="a-right"><a href="#" class="btn-remove" onclick="removeItem('<?php echo $this->helper('catalog/product_compare')->getRemoveUrl($_item) ?>');" title="<?php echo $this->__('Remove This Item') ?>"><?php echo $this->__('Remove This Item') ?></a></td>
            <?php endforeach; ?>
            </tr>
        </thead>
<?php endif ?>
        <tbody>
            <tr class="product-shop-row">
            <?php $_i=0 ?>
            <?php foreach($this->getItems() as $_item): ?>
                <?php if($_i++%10==0): ?>
                    <th>&nbsp;</th>
                <?php endif; ?>
                <td>
                    <a class="product-image" href="#" onclick="setPLocation('<?php echo $this->getProductUrl($_item) ?>', true)" title="<?php echo $this->stripTags($_item->getName(), null, true) ?>"><img src="<?php echo $this->helper('catalog/image')->init($_item, 'small_image')->resize(125, 125); ?>" width="125" height="125" alt="<?php echo $this->stripTags($_item->getName(), null, true) ?>" /></a>
                    <h2 class="product-name"><a href="#" onclick="setPLocation('<?php echo $this->getProductUrl($_item) ?>', true)" title="<?php echo $this->stripTags($_item->getName(), null, true) ?>"><?php echo $this->helper('catalog/output')->productAttribute($_item, $_item->getName(), 'name') ?></a></h2>
                    <?php echo $this->getReviewsSummaryHtml($_item, 'short') ?>
                    <?php echo $this->getPriceHtml($_item, true, '-compare-list-top') ?>
                    <?php if($_item->isSaleable()): ?>
                        <p><button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setPLocation('<?php echo $this->helper('catalog/product_compare')->getAddToCartUrl($_item) ?>', true)">                        
                        <span class="addcard-text"><?php echo $this->__('Add to Cart') ?></span>
                        </button></p>
                    <?php else: ?>
                        <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
                    <?php endif; ?>
                    <?php if ($this->helper('wishlist')->isAllow()) : ?>
                        <ul class="add-to-links">
                            <li>                                
                                <a href="<?php echo $this->getAddToWishlistUrl($_item) ?>" class="link-wishlist button" onclick="setPLocation(this.href, true)"><?php echo $this->__('Add to Wishlist') ?></a>
                            </li>
                        </ul>
                    <?php endif; ?>
                </td>
            <?php endforeach; ?>
            </tr>
        </tbody>
        <tbody>
        <?php foreach ($this->getAttributes() as $_attribute): ?>
            <tr>
                <?php $_i=0 ?>
                <?php foreach($this->getItems() as $_item): ?>
                <?php if($_i++%10==0): ?>
                <th><span class="nobr"><?php echo $_attribute->getStoreLabel() ?></span></th>
                <?php endif; ?>
                <td>
                    <?php switch ($_attribute->getAttributeCode()) {
                        case "price": ?>
                            <?php echo $this->getPriceHtml($_item, true, '-compare-list-' . $_attribute->getCode()) ?>
                            <?php break;
                        case "small_image": ?>
                            <img src="<?php echo $this->helper('catalog/image')->init($_item, 'small_image')->resize(125, 125); ?>" width="125" height="125" alt="<?php echo $this->htmlEscape($_item->getName()) ?>" title="<?php echo $this->htmlEscape($_item->getName()) ?>" />
                            <?php break;
                        case "date":
                              echo substr($this->getProductAttributeValue($_item, $_attribute),0,10);
                              break;
                        default: ?>
                            <div class="std">
                                <?php echo $this->helper('catalog/output')->productAttribute($_item, $this->getProductAttributeValue($_item, $_attribute), $_attribute->getAttributeCode()) ?>
                            </div>
                            <?php break;
                    } ?>
                </td>
                <?php endforeach; ?>
            </tr>
        <?php endforeach; ?>
        </tbody>
        <tbody>
                <tr class="add-to-row">
                <?php $_i=0 ?>
                <?php foreach($this->getItems() as $_item): ?>
                <?php if($_i++%10==0): ?>
                <th>&nbsp;</th>
                <?php endif; ?>
                <td>
                    <?php echo $this->getPriceHtml($_item, true, '-compare-list-bottom') ?>
                    <?php if($_item->isSaleable()): ?>
                        <p><button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setPLocation('<?php echo $this->helper('catalog/product_compare')->getAddToCartUrl($_item) ?>', true)">                        
                        <span class="addcard-text"><?php echo $this->__('Add to Cart') ?></span>
                        </button></p>
                    <?php else: ?>
                        <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
                    <?php endif; ?>
                    <?php if ($this->helper('wishlist')->isAllow()) : ?>
                        <ul class="add-to-links">
                            <li>                                
                                <a href="<?php echo $this->getAddToWishlistUrl($_item);?>" class="link-wishlist button" onclick="setPLocation(this.href, true)"><?php echo $this->__('Add to Wishlist') ?></a>
                            </li>
                        </ul>
                    <?php endif; ?>
                </td>
                <?php endforeach; ?>
            </tr>
        </tbody>
    </table>
    <div class="buttons-set">
        <button type="button" title="<?php echo $this->__('Close Window') ?>" class="button" onclick="window.close();"><span><span><?php echo $this->__('Close Window') ?></span></span></button>
        <span class="please-wait" id="compare-list-please-wait" style="display:none;">
            <img src="<?php echo $this->getSkinUrl('images/opc-ajax-loader.gif') ?>" alt="<?php echo $this->__('Please wait...') ?>" title="<?php echo $this->__('Please wait...') ?>" class="v-middle" /> <?php echo $this->__('Please wait...') ?>
        </span>
    </div>
    <script type="text/javascript">
        decorateTable('product_comparison');

        function removeItem(url)
        {
            new Ajax.Request(url, {
                parameters: {isAjax: 1, method: 'POST'},
                onLoading: function(){$('compare-list-please-wait').show();},
                onSuccess: function(transport) {
                    $('compare-list-please-wait').hide();
                    window.location.reload();
                    window.opener.location.reload();
                }
            });
        }
    </script>
<?php else: ?>
    <script type="text/javascript">window.close();</script>
<?php endif; ?>

Please help me.

!http://imgur.com/a/KlZVq

go to this link and see the screen shot of what i have required. i want to display group like this.

  • this is for magento1 or magento2? You want to create new attribute set or display existing one? – Pallavi Jul 20 '16 at 8:01
  • this is for magento 1.9 – Neeya Jul 21 '16 at 9:20
  • want to display existing attribute in group set – Neeya Jul 21 '16 at 9:21
  • please help me. i am new in magento – Neeya Jul 21 '16 at 11:42
0

For fetching an Attribute Set Name of particular product, you need to have a product object. Then use below code to get Attribute Set Name :

$attrSetModel = Mage::getModel("eav/entity_attribute_set");
//Here $product is an object of product.
$attrSetModel->load($product->getAttributeSetId());
$attrSetName  = $attrSetModel->getAttributeSetName();

// OR you can use a single line of code below:
$attrSetName = Mage::getModel('eav/entity_attribute_set')->load($product->getAttributeSetId())->getAttributeSetName();

UPDATE : Replace your phtml (app/design/frontent/sm-market/default/template/catalog/product/compare/list.phtml) with following code :

<?php
<div class="page-title title-buttons">
    <h1><?php echo $this->__('Compare Products') ?></h1>
    <a href="#" onclick="window.print(); return false;" class="link-print"><?php echo $this->__('Print This Page') ?></a>
</div>
<?php $_total=$this->getItems()->getSize() ?>
<?php if($_total): ?>
    <table class="data-table compare-table" id="product_comparison">
    <?php $_i=0 ?>
    <?php foreach($this->getItems() as $_item): ?>
        <?php if($_i++%10==0): ?>
            <col width="1" />
        <?php endif; ?>
            <col width="<?php echo floor(100/$_total); ?>%" />
    <?php endforeach; ?>
<?php if ($_total>2): ?>
        <thead>
            <tr>
            <?php $_i=0 ?>
            <?php foreach($this->getItems() as $_item): ?>
                <?php if($_i++%10==0): ?>
                    <th>&nbsp;</th>
                <?php endif; ?>
                <td class="a-right"><a href="#" class="btn-remove" onclick="removeItem('<?php echo $this->helper('catalog/product_compare')->getRemoveUrl($_item) ?>');" title="<?php echo $this->__('Remove This Item') ?>"><?php echo $this->__('Remove This Item') ?></a></td>
            <?php endforeach; ?>
            </tr>
        </thead>
<?php endif ?>
        <tbody>
            <tr class="product-shop-row">
            <?php $_i=0 ?>
            <?php foreach($this->getItems() as $_item): ?>
                <?php if($_i++%10==0): ?>
                    <th>&nbsp;</th>
                <?php endif; ?>
                <td>
                    <a class="product-image" href="#" onclick="setPLocation('<?php echo $this->getProductUrl($_item) ?>', true)" title="<?php echo $this->stripTags($_item->getName(), null, true) ?>"><img src="<?php echo $this->helper('catalog/image')->init($_item, 'small_image')->resize(125, 125); ?>" width="125" height="125" alt="<?php echo $this->stripTags($_item->getName(), null, true) ?>" /></a>
                    <h2 class="product-name"><a href="#" onclick="setPLocation('<?php echo $this->getProductUrl($_item) ?>', true)" title="<?php echo $this->stripTags($_item->getName(), null, true) ?>"><?php echo $this->helper('catalog/output')->productAttribute($_item, $_item->getName(), 'name') ?></a></h2>
                    <?php echo $this->getReviewsSummaryHtml($_item, 'short') ?>
                    <?php echo $this->getPriceHtml($_item, true, '-compare-list-top') ?>
                    <?php if($_item->isSaleable()): ?>
                        <p><button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setPLocation('<?php echo $this->helper('catalog/product_compare')->getAddToCartUrl($_item) ?>', true)">                        
                        <span class="addcard-text"><?php echo $this->__('Add to Cart') ?></span>
                        </button></p>
                    <?php else: ?>
                        <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
                    <?php endif; ?>
                    <?php if ($this->helper('wishlist')->isAllow()) : ?>
                        <ul class="add-to-links">
                            <li>                                
                                <a href="<?php echo $this->getAddToWishlistUrl($_item) ?>" class="link-wishlist button" onclick="setPLocation(this.href, true)"><?php echo $this->__('Add to Wishlist') ?></a>
                            </li>
                        </ul>
                    <?php endif; ?>
                </td>
            <?php endforeach; ?>
            </tr>
        </tbody>
        <tbody>
        <?php foreach ($this->getAttributes() as $_attribute): ?>
            <tr>
                <?php $_i=0 ?>
                <?php foreach($this->getItems() as $_item): ?>
                <?php if($_i++%10==0): ?>
                <th><span class="nobr"><?php echo $_attribute->getStoreLabel() ?></span></th>
                <?php endif; ?>
                <td>
                    <?php switch ($_attribute->getAttributeCode()) {
                        case "price": ?>
                            <?php echo $this->getPriceHtml($_item, true, '-compare-list-' . $_attribute->getCode()) ?>
                            <?php break;
                        case "small_image": ?>
                            <img src="<?php echo $this->helper('catalog/image')->init($_item, 'small_image')->resize(125, 125); ?>" width="125" height="125" alt="<?php echo $this->htmlEscape($_item->getName()) ?>" title="<?php echo $this->htmlEscape($_item->getName()) ?>" />
                            <?php break;
                        case "date":
                              echo substr($this->getProductAttributeValue($_item, $_attribute),0,10);
                              break;
                        default: ?>
                            <div class="std">
                                <?php echo $this->helper('catalog/output')->productAttribute($_item, $this->getProductAttributeValue($_item, $_attribute), $_attribute->getAttributeCode()) ?>
                            </div>
                            <?php break;
                    } ?>
                </td>
                <?php endforeach; ?>
            </tr>
        <?php endforeach; ?>
        <!-- CHANGES ADDED -->
        <tr>
            <?php $attrSetModel = Mage::getModel("eav/entity_attribute_set"); ?>
            <th><span class="nobr"><?php echo $this->__("Attribute Group") ?></span></th>
            <?php foreach($this->getItems() as $_item): ?>
                <td>
                    <div class="std">
                    <?php echo $attrSetName = Mage::getModel('eav/entity_attribute_set')->load($_item->getAttributeSetId())->getAttributeSetName(); ?>
                    </div>
                </td>
            <?php endforeach; ?>
        </tr>
        <!-- CHANGES ENDED -->
        </tbody>
        <tbody>
                <tr class="add-to-row">
                <?php $_i=0 ?>
                <?php foreach($this->getItems() as $_item): ?>
                <?php if($_i++%10==0): ?>
                <th>&nbsp;</th>
                <?php endif; ?>
                <td>
                    <?php echo $this->getPriceHtml($_item, true, '-compare-list-bottom') ?>
                    <?php if($_item->isSaleable()): ?>
                        <p><button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setPLocation('<?php echo $this->helper('catalog/product_compare')->getAddToCartUrl($_item) ?>', true)">                        
                        <span class="addcard-text"><?php echo $this->__('Add to Cart') ?></span>
                        </button></p>
                    <?php else: ?>
                        <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
                    <?php endif; ?>
                    <?php if ($this->helper('wishlist')->isAllow()) : ?>
                        <ul class="add-to-links">
                            <li>                                
                                <a href="<?php echo $this->getAddToWishlistUrl($_item);?>" class="link-wishlist button" onclick="setPLocation(this.href, true)"><?php echo $this->__('Add to Wishlist') ?></a>
                            </li>
                        </ul>
                    <?php endif; ?>
                </td>
                <?php endforeach; ?>
            </tr>
        </tbody>
    </table>
    <div class="buttons-set">
        <button type="button" title="<?php echo $this->__('Close Window') ?>" class="button" onclick="window.close();"><span><span><?php echo $this->__('Close Window') ?></span></span></button>
        <span class="please-wait" id="compare-list-please-wait" style="display:none;">
            <img src="<?php echo $this->getSkinUrl('images/opc-ajax-loader.gif') ?>" alt="<?php echo $this->__('Please wait...') ?>" title="<?php echo $this->__('Please wait...') ?>" class="v-middle" /> <?php echo $this->__('Please wait...') ?>
        </span>
    </div>
    <script type="text/javascript">
        decorateTable('product_comparison');

        function removeItem(url)
        {
            new Ajax.Request(url, {
                parameters: {isAjax: 1, method: 'POST'},
                onLoading: function(){$('compare-list-please-wait').show();},
                onSuccess: function(transport) {
                    $('compare-list-please-wait').hide();
                    window.location.reload();
                    window.opener.location.reload();
                }
            });
        }
    </script>
<?php else: ?>
    <script type="text/javascript">window.close();</script>
<?php endif; ?>
  • Sir , i just want to display attribute groups for those product which are in compare list. i mean to say when we view compare product list the those product have to display attribute group set. I am using magento 1.9 . please suggest me. Your help will be appreciated. – Neeya Jul 21 '16 at 9:24
  • I have provided the same code. You can use it anywhere. Just need to pass product object, that's it – Anil Suthar Jul 21 '16 at 9:31
  • Please tell me details process of displaying attribute group set of compare list product – Neeya Jul 21 '16 at 9:33
  • please help me. i am new in magento – Neeya Jul 21 '16 at 11:42
  • sir i have edit my question and shown you compare controller so please edit it. – Neeya Jul 22 '16 at 5:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.