0

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.

1 Answer 1

1

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!!

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.