Magento – Magento 2 : Get custom product attribute in minicart

attributesmagento2mini-cart

In my magento 2 store I need to return and print a custom product attribute in mini cart for each product in the cart. But it seems data are load using KO js so I have no idea , how to get attribute value please help me

Best Answer

Whole minicart rendering process is explained clearly here https://mage2.pro/t/topic/905

Under checkout module, you have CustomerData/Cart.php folder which does the rendering of the cart items. Each items are rendered based on the product type.

So, for Example, if you want to modify configurable product, go to configurable product module CustomerData folder.

For simple products, you need to look into the checkout module CustomerData/DefaultItem.php doGetItemData() To load Custom attributes over there and pass it as additional JSON param, you can load the product obj and get the value

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$productObj = $objectManager->get('Magento\Catalog\Model\Product')->load($product_id);
$short_desc = $productObj->getShortDescription();

You need to rewrite the Core modules to add your custom attribute values on minicart.

Related Topic