3

I need to get the simple product name of configurable into checkout order summary. So I need to know how to do it?

enter image description here

  • Override getTotalsData() function from vendor/magento/module-checkout/Model/DefaultConfigProvider.php. Here you can change item array. – Prince Patel Dec 28 '17 at 9:57
  • I override as below. But it will display same simple product name when i choose other option. – Hasitha Anuruddha Dec 28 '17 at 11:50
2

You have to write a small extension for that.

1.app/code/Vendor/Namespace/etc/module.xml

  <?xml version="1.0"?>
   <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd"> 
     <module name="Vendor_Namespace" setup_version="1.0.0">
     </module>
   </config>

2.app/code/Vendor/Namespace/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="Vendor\Namespace\Plugin\ConfigProviderPlugin" />
      </type>
    </config>

3. app/code/Vendor/Namespace/Plugin/ConfigProviderPlugin.php

   <?php
       namespace Vendor\Namespace\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();

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

           } 

4.app/code/Vendor/Namespace/registration.php

      <?php
         \Magento\Framework\Component\ComponentRegistrar::register(
            \Magento\Framework\Component\ComponentRegistrar::MODULE,
              'Vendor_Namespace',
                __DIR__
               );

5.Copy the file (details.html) from below path for your theme.

 vendor/magento/module-checkout/view/frontend/web/template/summary/item/details.html

And then Replace the

 <strong class="product-item-name" data-bind="text: $parent.name">

by

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

Thanks. Sejal Shah. I refer your extension to do this.

  • In next tab you click for payment and review section again you'll see main product name. Can you please see it. – Ravi Soni Oct 5 '18 at 10:19
  • I need to get the simple product name of configurable into a cart, checkout Order summary, mini-cart and also order and email template. So I need to know how to do it? – Rahul Singh Jan 23 at 13:31
0

Thanks @Hasitha Anuruddha for your solution. There's only one problem I've faced with your plugin.

In the provided solution the childname always is set as the name of the next quote item, unless if the item is a configurable product or not. To avoid this, I've introduced a check if the parentItemId of the "child" quote item matches the itemId of the original quote item.

Further I've cleaned the usage of the object manager in favor of dependency injection.

Update version for app/code/Vendor/Namespace/Plugin/ConfigProviderPlugin.php:

<?php
namespace Vendor\Namespace\Plugin;

class ConfigProviderPlugin extends \Magento\Framework\Model\AbstractModel
{
    /**
     * @var \Magento\Quote\Model\Quote\Item
     */
    private $quoteItem;

    public function __construct(
        \Magento\Quote\Model\Quote\Item $quoteItem,
        \Magento\Framework\Model\Context $context,
        \Magento\Framework\Registry $registry,
        \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
        \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
        array $data = []
    ) {
        $this->quoteItem = $quoteItem;

        parent::__construct($context, $registry, $resource, $resourceCollection, $data);
    }

    public function afterGetConfig(
        \Magento\Checkout\Model\DefaultConfigProvider $subject,
        array $result
    ) {
        $items = $result['totalsData']['items'];
        for ($i = 0; $i < count($items); $i++) {
            $originalQuoteId = $items[$i]['item_id'];
            $nextQuoteId = ($originalQuoteId + 1);
            $nextQuote = $this->quoteItem->load($nextQuoteId);

            if ($nextQuote->getParentItemId() === $originalQuoteId) {
                $productName = $nextQuote->getName();
            } else {
                $productName = $items[$i]['name'];
            }

            $items[$i]['childname'] = $productName;
        }
        $result['totalsData']['items'] = $items;

        return $result;
    }

}
  • I need to get the simple product name of configurable into a cart, checkout Order summary, mini-cart and also order and email template. So I need to know how to do it? – Rahul Singh Jan 23 at 13:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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