Search code examples
xmlmagentoblockmagento-1.7

Adding custom attribute to magento1.7 cart sidebar


I'm trying to display the brand of the items every where the product is displayed, including the checkout cart block that's usually displayed on the right by default.

I've tried as couple of methods but one of them seem to have worked.

cart/sidebar/default.phtml

$_item  = $this->getItem();
$_product   = $_item->getProduct()->load();
$attributes = $_product->getAttributes();

This causes a memory error, So i tried using the get custom attribute and passing it the name of the attribute but that didn't work either. Getting the custom attribute only returned NULL

default/layout/checkout.xml

 <default>

    <!-- Mage_Checkout -->
    <reference name="top.links">
        <block type="checkout/links" name="checkout_cart_link">
            <action method="addCartLink"></action>
            <action method="addCheckoutLink"></action>
        </block>
    </reference>
    <reference name="right">
        <block type="checkout/cart_sidebar" name="cart_sidebar" template="checkout/cart/sidebar.phtml" before="-">
            <action method="addItemRender"><type>simple</type><block>checkout/cart_item_renderer</block><template>checkout/cart/sidebar/default.phtml</template></action>
            <action method="addItemRender"><type>grouped</type><block>checkout/cart_item_renderer_grouped</block><template>checkout/cart/sidebar/default.phtml</template></action>
            <action method="addItemRender"><type>configurable</type><block>checkout/cart_item_renderer_configurable</block><template>checkout/cart/sidebar/default.phtml</template></action>
            <block type="core/text_list" name="cart_sidebar.extra_actions" as="extra_actions" translate="label" module="checkout">
                <label>Shopping Cart Sidebar Extra Actions</label>
                <action method="addAttribute"><attribute>brand</attribute></action>
            </block>
        </block>
    </reference>
</default>

I edited this one to i think include my custom brand attribute which if i understand correctly should make it accessible in the sidebar cart...

I can't tell what I'm missing now from this point.


Solution

  • Please Try this. Remove all thing that you customized. just add below code. and you will see magic

        <?php $_product= Mage::getSingleton('catalog/product')->load($_item->getProductId()) ?>
    
        <?php echo $_product->getResource()->getAttribute('manufacturer')->getFrontend()->getValue($_product); 
    

    Above code is working.Tested in 1.7.0.2