0

I want to show a Simple product with a Configurable product name on ( Mini-cart, Cart page, and checkout page ). I have successfully achieved to show the name on Mini-cart and Cart page but on the Checkout page I have created a module that is successfully showing the Name on the shipping page but it doesn't show on the Payment page can anyone have any idea why it is not showing there.

I have shown the value by

<?php
namespace Hl\Checkoutname\Plugin;
class ConfigProviderPlugin extends \Magento\Framework\Model\AbstractModel
{
 public function afterGetConfig(\Magento\Checkout\Model\DefaultConfigProvider 
$subject, array $result)
   {
 $items = $result['totalsData']['items'];
 $objectManager = \Magento\Framework\App\ObjectManager::getInstance();          

 for($i=0;$i<count($items);$i++){

  $quoteId = $items[$i]['item_id'];
  $quoteNext = ($quoteId + 1);

  $quote = $objectManager->create('\Magento\Quote\Model\Quote\Item')->load($quoteNext);
  $simpleProName = $quote->getName();
  $simpleProType = $quote->getProductId();

  $items[$i]['childname'] = $simpleProName;
  $items[$i]['producttype'] = $simpleProType;
}
 $result['totalsData']['items'] = $items;
 return $result;
 }
}

My di.xml file path: app/code/Hl/Checkoutname/etc/di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
 <type name="Magento\Checkout\Model\DefaultConfigProvider"> 
 <plugin name="AddAttPlug" type="Hl\Checkoutname\Plugin\ConfigProviderPlugin" />
 </type>
  <type name="Magento\Quote\Model\Cart\CartTotalRepository">
    <plugin name="Hl_Checkoutname_Plugin_Frontend_Magento_Catalog_Model_Layer" type="Hl\Checkoutname\Plugin\Frontend\Magento\Catalog\Model\Layer\CartTotalRepository" sortOrder="15" disabled="false"/>
  </type>
 </config>

My Plugin file path : app/code/Hl/Checkoutname/Plugin/Frontend/Magento/Catalog/Model/Layer/CartTotalRepository.php

<?php
    declare(strict_types=1);

    namespace Hl\Checkoutname\Plugin\Frontend\Magento\Catalog\Model\Layer;

    use Magento\Catalog\Api\ProductRepositoryInterface;

    class CartTotalRepository
    {
    /**
     * @var ProductRepositoryInterface
     */
    private $productRepository;

    public function __construct(ProductRepositoryInterface $productRepository)
    {
        $this->productRepository = $productRepository;
    }

    public function afterGet(
        \Magento\Quote\Model\Cart\CartTotalRepository $subject,
        $result,
        $cartId
    ) {
        if ($result instanceof \Magento\Quote\Api\Data\TotalsInterface) {
            $items = $result->getItems();
            $resultItems = [];
            foreach ($items as $eachItem) {
                $name = $eachItem->getName();
                $eachItem->setName($name);
                // Do your code
                $resultItems['childname'] = $eachItem;
            }
            $result->setItems($resultItems);
        }
        return $result;
    }
    }

As in my app/design/frontend/Mgs/claue_child/Magento_Checkout/web/template/summary/item/details.html I have used

 <strong class="product-item-childname" data-bind="html: $parent.childname"></strong> 

to show the name so that's why I have returned the value with this but still not getting a name.

enter image description here

Any help is appreciated.

1 Answer 1

1

You have to create an after plugin on Magento\Quote\Model\Cart\CartTotalRepository:get as the payment step details coming from the rest api.

di.xml for declare the plugin

 <?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Quote\Model\Cart\CartTotalRepository">
        <plugin name="StackExchanges_Magento_Plugin_Magento_Quote_Model_Cart_CartTotalRepository" type="StackExchanges\Magento\Plugin\Magento\Quote\Model\Cart\CartTotalRepository" sortOrder="15" disabled="false"/>
    </type>
</config>

and Plugin class

<?php
declare(strict_types=1);

namespace StackExchanges\Magento\Plugin\Magento\Quote\Model\Cart;

use Magento\Catalog\Api\ProductRepositoryInterface;

class CartTotalRepository
{
    /**
     * @var ProductRepositoryInterface
     */
    private $productRepository;

    public function __construct(ProductRepositoryInterface $productRepository)
    {
        $this->productRepository = $productRepository;
    }

    public function afterGet(
        \Magento\Quote\Model\Cart\CartTotalRepository $subject,
        $result,
        $cartId
    ) {
        if ($result instanceof \Magento\Quote\Api\Data\TotalsInterface) {
            $items = $result->getItems();
            $resultItems = [];
            foreach ($items as $eachItem) {
                $name = $eachItem->getName();
                //$eachItem->setName($name . ' ' . __METHOD__);
                // Do your code
                $resultItems[] = $eachItem;
            }
            $result->setItems($resultItems);
        }
        return $result;
    }
    private function getName($eachItem)
    {

    }
}
8
  • Thanks for your answer @amit Can you please explain how to achieve as it is new thing to me like how to extend it using di.xml or using any other file.
    – Prits
    Commented Sep 29, 2021 at 7:57
  • 1
    For plugin check devdocs.magento.com/guides/v2.4/extension-dev-guide/…
    – Amit Bera
    Commented Sep 29, 2021 at 9:46
  • 1
    i use devdocs.magento.com/guides/v2.4/extension-dev-guide/…
    – Amit Bera
    Commented Sep 29, 2021 at 9:47
  • Thanks @amit i have updated the files in question with its paths can you please check and tell me what is wrong with it as my product name is still not there.
    – Prits
    Commented Sep 29, 2021 at 10:14
  • sorry, mistake.Provided wrong di.xml.Please check updated di.xml
    – Amit Bera
    Commented Sep 29, 2021 at 10:32

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.