Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display custom attribute in cart (Magento)

I have tried a lot of stuf but none of them work. I think I can get the custom attributes on the product page, but I was wondering: how to get them in shopping cart page? (the attribute is just a simple written text)

like image 417
pomaaa Avatar asked Mar 06 '11 20:03

pomaaa


People also ask

What is custom attribute in magento2?

Magento 2 Marketplace Custom Attribute module allows the admin to create custom attribute from the admin panel and can select them to display/hide on the front end. Vendors can use those attributes during product upload and those attributes are displayed on the seller's product page.


1 Answers

$_item->getProduct()->load() 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.

The same can be done with much better performance by loading the attribute along with the quote item. Just create a custom module and add this to the config.xml

<global>
    <sales>
        <quote>
            <item>
                <product_attributes>
                    <one_custom_attribute_code />
                    <another_custom_attribute_code />
                </product_attributes>
            </item>
        </quote>
    </sales>
</global>

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

$_item->getProduct()->getAnotherCustomAttributeCode();

Here is an article about this: https://www.atwix.com/magento/accessing-custom-attribute-at-checkout-or-cart/

like image 135
Andreas Riedmüller Avatar answered Oct 15 '22 15:10

Andreas Riedmüller