I have a issue that i need to output a product attribute that isn't option in Mini Cart.
Here is my plugin scructure:
Vendor/Checkout/etc/di.xml:
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Vendor\Checkout\CustomerData\AbstractItem">
<plugin name="Vendor_Checkout::Add_Color_Attribute" type="Vendor\Checkout\Plugin\AddAttribute" disabled="false" sortOrder="1"/>
</type>
</config>
Vendor/Checkout/etc/module.xml:
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
<module name="Vendor_Checkout" setup_version="0.0.1" data_version="0.0.1">
<sequence>
<module name="Magento_Checkout"/>
</sequence>
</module>
</config>
Vendor/Checkout/Plugin/AddAttribute/AddAttribute.php
namespace Vendor\Checkout\Plugin;
class AddAttribute
{
protected function afterGetItemData($subject, $proceed, $item)
{
$result = $proceed($item);
$result['color'] = $this->$item->getProduct()
->load($this->$item->getId())
->getAttributeText('color');
return $result;
}
}
Template
Vendor/default/Magento_Checkout/web/template/minicart/item/default.html
</p>
<div class="product-item-details">
<!-- ko if: options.length -->
<div class="product options" data-mage-init='{"collapsible":{"openedState": "active", "saveState": false}}'>
<span data-role="title" class="toggle"><!-- ko i18n: 'See Details' --><!-- /ko --></span>
<div data-role="content" class="content">
<strong class="subtitle"><!-- ko i18n: 'Options Details' --><!-- /ko --></strong>
<ol class="product options list">
<!-- ko foreach: { data: options, as: 'option' } -->
<li>
<span class="label"><!-- ko text: option.label --><!-- /ko --></span>:
<span class="values">
<!-- ko if: Array.isArray(option) -->
<span data-bind="html: option.value.join('<br>')"></span>
<!-- /ko -->
<!-- ko ifnot: Array.isArray(option) -->
<span data-bind="html: option.value"></span>
<!-- /ko -->
</span>
</li>
<!-- /ko -->
<!-- ko if: color.length -->
<li>
<span class="label" data-bind="i18n: 'Color'"></span>:
<span class="values">
<span data-bind="html: color"></span>
</span>
</li>
<!-- /ko -->
</ol>
</div>
</div>
<!-- /ko -->
<div class="product-item-pricing">
<!-- ko if: canApplyMsrp -->
<div class="details-map">
<span class="label" data-bind="i18n: 'Price'"></span>
<span class="value" data-bind="i18n: 'See price before order confirmation.'"></span>
</div>
<!-- /ko -->
<!-- ko ifnot: canApplyMsrp -->
<!-- ko foreach: $parent.getRegion('priceSidebar') -->
<!-- ko template: {name: getTemplate(), data: item.product_price, as: 'price'} --><!-- /ko -->
<!-- /ko -->
<!-- /ko -->
</div>
<div class="product actions">
<div class="secondary">
<a href="#" data-bind="attr: {'data-cart-item': item_id, title: $t('Remove item')}"
class="action delete">
<span data-bind="i18n: 'Remove'"></span>
</a>
</div>
</div>
</div>
</div>
I cannot get color attribute passed to quote.
In result i get this error http://prntscr.com/ct1a9r
Looks like color attribute isn't passed to quote item.
item.color, notcolor. – Aaron Allen Oct 12 '16 at 19:42magento setup:upgradethenmagento cache:flush. – Aaron Allen Oct 13 '16 at 00:39