Adding the attribute to the collection is working exactly as you describe, for the cart AND the minicart.
You also need to overwrite \Magento\Checkout\CustomerData\DefaultItem::doGetItemData to provide a new attribute, as shown here with the brand attribute:
protected function doGetItemData()
{
$imageHelper = $this->imageHelper->init($this->getProductForThumbnail(), 'mini_cart_product_thumbnail');
$productName = $this->escaper->escapeHtml($this->item->getProduct()->getName());
$productBrand = $this->escaper->escapeHtml($this->item->getProduct()->getAttributeText('brand'));
return [
'options' => $this->getOptionList(),
'qty' => $this->item->getQty() * 1,
'item_id' => $this->item->getId(),
'configure_url' => $this->getConfigureUrl(),
'is_visible_in_site_visibility' => $this->item->getProduct()->isVisibleInSiteVisibility(),
'product_id' => $this->item->getProduct()->getId(),
'product_name' => $productName,
'product_brand' => $productBrand,
'product_sku' => $this->item->getProduct()->getSku(),
'product_url' => $this->getProductUrl(),
'product_has_url' => $this->hasProductUrl(),
'product_price' => $this->checkoutHelper->formatPrice($this->item->getCalculationPrice()),
'product_price_value' => $this->item->getCalculationPrice(),
'product_image' => [
'src' => $imageHelper->getUrl(),
'alt' => $imageHelper->getLabel(),
'width' => $imageHelper->getWidth(),
'height' => $imageHelper->getHeight(),
],
'canApplyMsrp' => $this->msrpHelper->isShowBeforeOrderConfirm($this->item->getProduct())
&& $this->msrpHelper->isMinimalPriceLessMsrp($this->item->getProduct()),
];
}
Please use a preference for overwriting the method.
And then the html template vendor/magento/module-checkout/view/frontend/web/template/minicart/item/default.html will have to be overwritten in order to add the placeholder like <!-- ko text: product_brand --><!-- /ko --> in it.
\Magento\Checkout\CustomerData\DefaultItem::doGetItemDatabecause it is protected method. Instead plugin should be created forMagento\Checkout\CustomerData\AbstractItem::getItemData which calls doGetItemDataonly then do rewrite. – Trenox Oct 18 '18 at 10:59protectedis used, it's less modern code for which Plugins don't work well. – Andreas von Studnitz Oct 19 '18 at 08:05