Skip to content

Instantly share code, notes, and snippets.

@evgv
Last active April 26, 2017 06:32
Show Gist options
  • Select an option

  • Save evgv/b08bcbf2840ca3496dfc410befa15f10 to your computer and use it in GitHub Desktop.

Select an option

Save evgv/b08bcbf2840ca3496dfc410befa15f10 to your computer and use it in GitHub Desktop.
Magento. Display custom attribute in cart.

How to display custom attribute in cart

Get custom product attribute from quote item.

1. Load product by item and get atribute

Will reload all product data from the database. While this will work, bear in mind that every time you call load() Magento will execute a database query.

    // load product
    
    $_product = $_item->getProduct()->load(); // or Mage::getModel('catalog/product')->load($_item->getProductId());
    
    // then get attribute from product
    
    $_product->getCustomAttributeCode();

2. Add attribute to item

    <global>
        <sales>
            <quote>
                <item>
                    <product_attributes>
                        <custom_attribute_code />
                    </product_attributes>
                </item>
            </quote>
        </sales>
    </global>

Having done that, you can access your custom attribute without additional database queries.

    $_item->getProduct()->getCustomAttributeCode();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment