Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Access Product Attribute in Catalog XML Layout [SOLVED]
 
silentninja
Jr. Member
 
Total Posts:  6
Joined:  2012-05-29
 

Hi.

I’d like to access product attributes in the catalog xml layout to provide the text for one of the info tabs. One of the info tabs will have “More from [manufacturer]”

The manufacturer will be populated from the product attribute ‘manufacturer’ in the catalog xml layout.

Does anyone have any ideas on how to achieve this?

Thanks,

 
Magento Community Magento Community
Magento Community
Magento Community
 
Egregory
Jr. Member
 
Total Posts:  3
Joined:  2013-03-22
 

Are you trying to just add a custom tab to a product?

 
Magento Community Magento Community
Magento Community
Magento Community
 
silentninja
Jr. Member
 
Total Posts:  6
Joined:  2012-05-29
 

I’m not trying to add a custom tab to a product. Products have attributes some default and some that can be custom.

I’d like to access an attribute in the catalog.xml layout to create the product page tabs with a tab that has attribute specific data. The tabs i’m referring to are the “product.info.tabs” setup as the block below

<block type="catalog/product_view_tabs" name="product.info.tabs" as="info_tabs" template="catalog/product/view/tabs.phtml" >

The idea is to have a tab that would display all the products from the same manufacturer (not recommended items or recently viewed but from the same manufacturer) and then have the tab name set to “More from [Manufacturer]” ie More from Dell, More from Sony.

 
Magento Community Magento Community
Magento Community
Magento Community
 
silentninja
Jr. Member
 
Total Posts:  6
Joined:  2012-05-29
 

I’ve managed to achieve what I wanted to do by doing the following:

1. override the tabs.php from app\code\core\Mage\Catalog\Block\Product\View\Tabs.php with app\code\local\Mage\Catalog\Block\Product\View\Tabs.php

The change was made to pass another argument through - the product attribute

function addTab($alias$title$block$template$attribute)
    
{

        
if (!$title || !$block || !$template{
            
return false;
        
}
        
        
        
if ($attribute{
            $product 
Mage::registry('product');
            
$manufacturer Mage::getModel('catalog/product')->load($product->getId())->getAttributeText($attribute);
            
            
$this->_tabs[] = array(
                
'alias' => $alias,
                
'title' => $title $manufacturer 
            
);
        
else {
            $this
->_tabs[] = array(
                
'alias' => $alias,
                
'title' => $title
            
);
        
}

....
}

2. The second change was in the Catalog.xml file

<block type="catalog/product_view_tabs" name="product.info.tabs" as="info_tabs" template="catalog/product/view/tabs.phtml" >
                    <
action method="addTab" translate="title" module="catalog"><alias>same_manufacturer_products</alias><title>More From </title><block>catalog/product_list_related</block><template>catalog/product/list/samemanufacturer.phtml</template><attribute>manufacturer</attribute></action>
...
</
block>

3. Magento Admin -> System -> Tools -> Compilation and run the compilation.

4. Flush Magento Cache and it now does the desired behavior.

Hope this helps others out there looking at this thread in the future. grin Feel free to mention any improvements.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top