Get Product Attribute into Order Confirmation Email
-
23-02-2021 - |
Question
I'm currently attempting to override the following file in order to add the color
attribute to the Order Confirmation Email:
vendor/magento/module-sales/view/frontend/templates/email/items/order/default.phtml
Under the "sku" line, I've created an additional line to display the color
of the product (this is the only change I've made to the file):
<p class="product-name"><?= $block->escapeHtml($_item->getName()) ?></p>
<p class="sku"><?= /* @escapeNotVerified */ __('SKU') ?>: <?= $block->escapeHtml($block->getSku($_item)) ?></p>
<p class="color"><?= /* @escapeNotVerified */ __('Color') ?>: <?= $block->escapeHtml($block->getColor($_item)) ?></p>
Having tested the email, I can see the label "Color" being output, However it's not returning the actual value.
Solution
Item object has a product property that you can retrieve by
$productcolor = $_item->getProduct()->getAttributeText('color');
Make sure that $_item is instance of Magento\Sales\Model\Order\Item
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange