Question

i am want to show product short description on refund mail.

My error: Fatal error: Uncaught Error: Call to a member function getId() on null in

i am editing in : Magento_Sales/templates/email/items/creditmemo/default.phtml

My code is:

    <?php
    /**
     * Copyright © Magento, Inc. All rights reserved.
     * See COPYING.txt for license details.
     */
    
    // @codingStandardsIgnoreFile
    
    ?>
    <?php $_item = $block->getItem() ?>
    <?php $_order = $block->getItem()->getOrder(); 
    ?>
    <tr>
        <td class="item-info<?php if ($block->getItemOptions()): ?> has-extra<?php endif; ?>">
            <p class="product-name"><?= $block->escapeHtml($_item->getName()) ?></p>
            <p class="sku"><?= /* @escapeNotVerified */  __('SKU') ?>: <?= $block->escapeHtml($block->getSku($_item)) ?></p>
            <p><?php 
$objectManager =  \Magento\Framework\App\ObjectManager::getInstance();
   $productId = $block->getId($_item);
   $currentproduct = $objectManager->create('Magento\Catalog\Model\Product')->load($productId);
   echo $currentproduct ->getShortDescription();  
         
       ?></p>

Please help me.

Was it helpful?

Solution

If you do not get the product id then you can get product by SKU.

<?php
    /**
     * Copyright © Magento, Inc. All rights reserved.
     * See COPYING.txt for license details.
     */
    
    // @codingStandardsIgnoreFile
    
    ?>
    <?php $_item = $block->getItem() ?>
    <?php $_order = $block->getItem()->getOrder(); 
    ?>
    <tr>
        <td class="item-info<?php if ($block->getItemOptions()): ?> has-extra<?php endif; ?>">
            <p class="product-name"><?= $block->escapeHtml($_item->getName()) ?></p>
            <p class="sku"><?= /* @escapeNotVerified */  __('SKU') ?>: <?= $block->escapeHtml($block->getSku($_item)) ?></p>
            <p><?php 
$objectManager =  \Magento\Framework\App\ObjectManager::getInstance();
   //$productId = $block->getId($_item);
    $sku = $block->getSku($_item);
   $currentproduct = $objectManager->create('\Magento\Catalog\Model\ProductRepository')->get($sku);
   echo $currentproduct ->getShortDescription();  
         
       ?></p>

I hope this is helpful to you!!

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top