How to Get the custom product attribute in the Checkout summary page in Magento 2?

Today we will learn How to display extra product attributes in the checkout summary in Magento 2.How to Get the custom product attribute in the Checkout summary page in Magento 2?

I have my custom product attribute that we want to use on our order summary page. so here is the process by which we are going to perform this task.

You will have to create a plugin for that. I wanted to add a product test to the order summary.

Files you have to create:

  1. Registration.php : app\code\Vendor\Extension\registration.php and this code.
<?php

\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Vendor\Extension',
    __DIR__
);

2. di.xml : app\code\Vendor\Extension\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\Extension\Plugin\ConfigProviderPlugin" />
    </type>
</config>

3. module.xml : app\code\Vendor\Extension\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_Extension" setup_version="1.0.0">
    </module>
</config>

4. ConfigProviderPlugin.php : app\code\Vendor\Extension\Plugin\ConfigProviderPlugin.php

<?php

namespace Vendor\Extension\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'];
            $quote = $objectManager->create('\Magento\Quote\Model\Quote\Item')->load($quoteId);
            $productId = $quote->getProductId();
            $product = $objectManager->create('\Magento\Catalog\Model\Product')->load($productId);
            $products = $product->getResource()->getAttribute('Your_atrribute_code')->getFrontend()->getValue($product);         
            if($products == 'No' || $products == 'NA'){
                $products = '';
            }
            $items[$i]['test'] = $products;
        }
        $result['totalsData']['items'] = $items;
        return $result;
    }

}

now in details.html file

Copy vendor\magento\module-checkout\view\frontend\web\template\summary\item\details.html in theme and add

<div class="product-item-test" data-bind="text: $parent.test"></div>

Here ,Test-123 is my product custom attribute.

Hope this blog is helpful for you Thanks for following and reading this blog.

expoundsofttechsolution

How to Get the custom product attribute in the Checkout summary page in Magento 2?

d