I need to get and display custom product attribute in magento 2 minicart . But the issue is minicart render using html files with KO js , so I can not use PHP directly there . I tried by extending “Magento\Checkout\CustomerData\DefaultItem” class and overriding “doGetItemData()” protected method using a custom module but no success , could someone help me please?
You should not “override” a standard class in Magento 2, because you will break all the other poor-written extensions, which try to “override” the same class too.
Learn and use the plugins.
See how is a mini-cart rendered.
As you can see, the
\Magento\Checkout\CustomerData\DefaultItem::doGetItemData() is called only from the public
\Magento\Checkout\CustomerData\AbstractItem::getItemData() method, and you can use an
after-plugin for it and modify its result.