2

I have add custom attribute in order summary, it show on checkout first page (#shipping) when shipping method select and go for second page of checkout (#payment) then custom attribute disappear. I am render custom attribute by using after plugin of this method Magento\Checkout\Model\DefaultConfigProvider::getConfig my code is

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="AddAttPlugCOnfig" type="Magerex\Configurator\Plugin\Cart\Summary\DefaultConfigProvider" />
    </type>
    </config>

Magerex\Configurator\Plugin\Cart\Summary\DefaultConfigProvider

namespace Magerex\Configurator\Plugin\Cart\Summary;

class DefaultConfigProvider extends \Magento\Framework\Model\AbstractModel
{
    public function afterGetConfig(\Magento\Checkout\Model\DefaultConfigProvider $subject, array $result)
    {
        $items = $result['totalsData']['items'];
        $Quote = $result['quoteItemData'];
        $index = 0;
        foreach ($items as $idx => $item) {
            $configOption = null;
//            foreach ($Quote as $quoteItem) {
            $decodeJson = json_decode($Quote[$index]['configurator_params'], true);
            $index++;
            if (isset($decodeJson["productDetails"])) {
                foreach ($decodeJson['productDetails']  as $key => $value) {
                    if ($key == 'productImage') {
                        continue;
                    }
                    $configOption.= $key. " : " .$value .' ';
                }
            }
            $items[$idx]['configurator'] = $configOption;
        }

//        }

        // Update the  current items array
        $result['totalsData']['items'] = $items;

        return $result;
    }
}

requirejs-config.js

var config = {
    map: {
        '*': {
            'Magento_Checkout/template/summary/item/details.html':
                'Magerex_Configurator/template/summary/item/details.html'
        }
    }
};

Add this line in

details.html

<span class="c-minicart__highlight" data-bind="text: $parent.configurator"> </span>

Screenshot for shipping page

enter image description here

Screenshot second page of checkout #payment page

.

enter image description here

Please anyone know what the mistake i did, guid me. Thank you.

1 Answer 1

0

This problem is due to the ajax request 'shipping-information' when we click 'next' from the checkout/# shipping page to go to checkout /# payment. This request returns payment_methods and totals. In 'totals', there are the attributes of the items that are the result of filtering according to the attributes declared in the TotalsItemInterface interface. Then Knockout syncs this returned data and the custom attributes you declared will disappear.

To solve this problem we must add setters and getters of the custom attribute in Quote/Api/Data/TotalsItemInterface and in the Quote/Model/ Cart/Totals/Item class, which implements the interface.

Attention: Do not modify the core files directly. This solution is only a confirmation of what I have said above.

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.