2

I have a phtml file. I want to get the product short description by SKU. I can use ObjectManager to do the work. But looks like this is not a proper way to do it. Anyone can help with recommendation to replace ObjectManager method? Thanks!

<?= $block->getProductName($item->getProductId()) ?>
<?= $item->getProductId() ?>
<?= $item->getSku() ?>
<?php
$objectManager =  \Magento\Framework\App\ObjectManager::getInstance();

   $currentproduct = $objectManager->create('\Magento\Catalog\Model\ProductRepository')->get($item->getSku());
   echo $currentproduct ->getShortDescription();
?>

rest of the code

<?php
// @codingStandardsIgnoreFile

?>
<?php $helper = $this->helper('Magento\Catalog\Helper\Output'); ?>
<?php /** @var $items \Magento\Sales\Model\Order */ $items = $block->getOrder(); ?>
<?php if ($items): ?>
    <?php
    foreach ($items as $item) {
        $order = $item->getOrder();
    }

    ?>
    <div style="width:100%;padding:10px 0 20px 0;height:auto;min-height:360px" class="review-email-form-wrapper">
        <p><?= /* @escapeNotVerified */ __('your purchased items:') ?></p>
        <ul>
            <?php /** @var $item \Magento\Sales\Api\Data\OrderItemInterface */ ?>
            <?php foreach ($items as $item): ?>
            <?php $productUrl=$block->getProductReviewUrl($item->getProductId()) ?>
                <li>
                    <a href="<?= $escaper->escapeUrl($productUrl) ?>"><?= /* @escapeNotVerified */ $block->getProductName($item->getProductId()) ?></a>
                </li>
            <?php endforeach; ?>
        </ul>
        <p><?= /* @escapeNotVerified */ __('Thankyou for your feedback', $order->getStore()->getGroup()->getName()); ?></p>
    </div>
<?php endif; ?>
1
  • Please put your layout file that declares that phtml file and the block class that the phtml using, so I can help.
    – Tu Van
    Commented Oct 14, 2022 at 17:54

0

Your Answer

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

Browse other questions tagged or ask your own question.