0

I'm trying to publish the custom attribute "flash_sale" (dropdown) on order confirmations.

I've changed the file:

vendor/magento/module-sales/view/frontend/templates/email/items/order/default.phtml

and inserted the additional line:

<p style="color: #aaaaaa;"><?= /* @escapeNotVerified */  __('Flash Sale') ?>: <?= $block>escapeHtml($block->getflash_sale()) ?></p>

with the result:

     <td class="item-info<?php if ($block->getItemOptions()): ?> has-extra<?php endif; ?>" colspan="2" style="position: relative !important; border-top: 0 none !important; padding: 35px 10px; border-bottom: 1px dotted #000000;">
    <p class="item-name" style="margin-top: 0 !important;"><?= $block->escapeHtml($_item->getName()) ?></p>
    <div class="item-detail" style="margin: 5px 0; font-size: 12px;">
    <p style="color: #aaaaaa;"><?= /* @escapeNotVerified */  __('Item') ?>: <?= $block->escapeHtml($block->getSku($_item)) ?></p>
     <p style="color: #aaaaaa;"><?= /* @escapeNotVerified */  __('Flash Sale') ?>: <?= $block>escapeHtml($block->getflash_sale()) ?></p>
        <?php if ($block->getItemOptions()): ?>
            <?php foreach ($block->getItemOptions() as $option): ?>
                <p style="color: #aaaaaa"><?= /* @escapeNotVerified */  $option['label']. ': ' . nl2br($option['value'])?></p>
            <?php endforeach; ?>

But the value is not published on order confirmations. What went wrong?

Thank you advance!

3 Answers 3

0
  1. Coding standard: method name should be getFlashSale instead of getflash_sale.
  2. Try to replace $block->getflash_sale() with $_item->getGiftFlashSale().
1
  • If this answer helps you resolve your issue, please mark it as accepted. That indicates your issue is solved and helps others with the same issue find out the verified answer easily.
    – Tu Van
    Nov 21, 2022 at 21:02
0

You should check some item below:

  • Where did you store the flash_sale value? From order item or order?
  • Did it saved correctly? With order confirmation email, the value of an item should be stored in table sales_order_item.
  • You shouldn't load the value from product.
  • Your code block $block->getflash_sale(), Is function getflash_sale defined in the block class?
0

Thank you for your hits.

These were the changes i have made and now works as expected:

  1. I'm using the Pearl Theme, so i've added the lines 16-18 to weltpixel-default.phtml :

    <?php // @codingStandardsIgnoreFile

    /** @var $block \Magento\Sales\Block\Order\Email\Items\DefaultItems / /* @var $_item \Magento\Sales\Model\Order\Item / $_item = $block->getItem(); $_order = $_item->getOrder(); $prodImg = $block->getImage($block->getProductForThumbnail(), 'cart_page_product_thumbnail'); /* @var $wpHelper \WeltPixel\EnhancedEmail\Helper\Data */ $wpHelper = $this->helper('WeltPixel\EnhancedEmail\Helper\Data'); if ($wpHelper->displaySalesPricesExclTax()) { $itemPrice = $_item->getPrice(); } else { $itemPrice = $_item->getPriceInclTax(); } $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $productRepository = $objectManager->get('\Magento\Catalog\Model\ProductRepository'); $product = $productRepository->get($_item->getSKU()); ?>

and inserted the additional line in the same file:

 <p style="color: #aaaaaa;"><?= /* @escapeNotVerified */  __('Flash Sale') ?>: <?= $product->getAttributeText('FlashSale') ?></p> 

with the result

<td class="item-info<?php if ($block->getItemOptions()): ?> has-extra<?php endif; ?>" colspan="2" style="position: relative !important; border-top: 0 none !important; padding: 35px 10px; border-bottom: 1px dotted #000000;">
    <p class="item-name" style="margin-top: 0 !important;"><?= $block->escapeHtml($_item->getName()) ?></p>
    <div class="item-detail" style="margin: 5px 0; font-size: 12px;">
    <p style="color: #aaaaaa;"><?= /* @escapeNotVerified */  __('Item') ?>: <?= $block->escapeHtml($block->getSku($_item)) ?></p>
     <p style="color: #aaaaaa;"><?= /* @escapeNotVerified */  __('Flash Sale') ?>: <?= $product->getAttributeText('FlashSale') ?></p>
        <?php if ($block->getItemOptions()): ?>
            <?php foreach ($block->getItemOptions() as $option): ?>
                <p style="color: #aaaaaa"><?= /* @escapeNotVerified */  $option['label']. ': ' . nl2br($option['value'])?></p>
            <?php endforeach; ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.