Posted on

Magento 2 Custom attribute in checkout summary affects payment method

I have created a module that adds custom attribute “master_id” in checkout summary, I am not sure why the payment method not working it showing no payment method

After adding this module the payment functionality not working when i remove this module it works.

I referred this link https://www.magevision.com/blog/post/get-a-product-attribute-in-checkout-summary-magento-2/

SampWork/ConfigCheckoutDynamicPCB/registration.php

<?php

MagentoFrameworkComponentComponentRegistrar::register(
MagentoFrameworkComponentComponentRegistrar::MODULE,
‘SampWork_ConfigCheckoutDynamicPCB’,
__DIR__
);

SampWork/ConfigCheckoutDynamicPCB/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=”SampWork_ConfigCheckoutDynamicPCB” setup_version=”1.0.0″> </module>
</config>

SampWork/ConfigCheckoutDynamicPCB/etc/catalog_attributes.xml

<?xml version=”1.0″?>

<config xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
xsi:noNamespaceSchemaLocation=”urn:magento:module:Magento_Catalog:etc/catalog_attributes.xsd”>
<group name=”quote_item”>
<attribute name=”master_id”/>
</group>
</config>

SampWork/ConfigCheckoutDynamicPCB/etc/di.xml

<?xml version=”1.0″ encoding=”UTF-8″?>
<config xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:noNamespaceSchemaLocation=”urn:magento:framework:ObjectManager/etc/config.xsd”>
<type name=”MagentoCheckoutModelDefaultConfigProvider”>
<plugin name=”checkout-summary-product-attribute” type=”SampWorkConfigCheckoutDynamicPCBPluginCheckoutModelDefaultConfigProvider” />
</type>
</config>

SampWork/ConfigCheckoutDynamicPCB/Plugin/Checkout/Model/DefaultConfigProvider.php

<?php
namespace SampWorkConfigCheckoutDynamicPCBPluginCheckoutModel;

use MagentoCheckoutModelSession as CheckoutSession;

class DefaultConfigProvider
{
/**
* @var CheckoutSession
*/
protected $checkoutSession;

/**
* Constructor
*
* @param CheckoutSession $checkoutSession
*/
public function __construct(
CheckoutSession $checkoutSession
) {
$this->checkoutSession = $checkoutSession;
}

public function afterGetConfig(
MagentoCheckoutModelDefaultConfigProvider $subject,
array $result
) {
$items = $result[‘totalsData’][‘items’];
foreach ($items as $index => $item) {
$quoteItem = $this->checkoutSession->getQuote()->getItemById($item[‘item_id’]);
$result[‘quoteItemData’][$index][‘master_id’] = $quoteItem->getProduct()->getData(‘master_id’);
}
return $result;
}
}

SampWork/SampWork/ConfigCheckoutDynamicPCB/view/frontend/web/js/view/summary/item/details.js

/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

define(
[
‘uiComponent’
],
function (Component) {
“use strict”;
var quoteItemData = window.checkoutConfig.quoteItemData;
return Component.extend({
defaults: {
template: ‘SampWork_ConfigCheckoutDynamicPCB/summary/item/details’
},
quoteItemData: quoteItemData,
getValue: function(quoteItem) {
return quoteItem.name;
},
getPcb: function(quoteItem) {
var item = this.getItem(quoteItem.item_id);
if(item.master_id){
return ‘Master ID’+item.master_id;
}else{
return ”;
}
},
getItem: function(item_id) {
var itemElement = null;
_.each(this.quoteItemData, function(element, index) {
if (element.item_id == item_id) {
itemElement = element;
}
});
return itemElement;
}
});
}
);

SampWork/ConfigCheckoutDynamicPCB/view/frontend/web/template/summary/item/details.html

<!– ko foreach: getRegion(‘before_details’) –>
<!– ko template: getTemplate() –><!– /ko –>
<!– /ko –>
<div class=”product-item-details”>

<div class=”product-item-inner”>
<div class=”product-item-name-block”>
<strong class=”product-item-name” data-bind=”text: $parent.name”></strong>
<!– ko if: (getPcb($parent))–>
<span class=”product-item-pcb-master” data-bind=”text: getPcb($parent)”></span>
<!– /ko –>
<div class=”details-qty”>
<span class=”label”><!– ko i18n: ‘Qty’ –><!– /ko –></span>
<span class=”value” data-bind=”text: $parent.qty”></span>
</div>
</div>
<!– ko foreach: getRegion(‘after_details’) –>
<!– ko template: getTemplate() –><!– /ko –>
<!– /ko –>
</div>

SampWork/ConfigCheckoutDynamicPCB/view/frontend/layout/checkout_index_index.xml

<item name=”cart_items” xsi:type=”array”>
<item name=”component” xsi:type=”string”>Magento_Checkout/js/view/summary/cart-items</item>
<item name=”children” xsi:type=”array”>
<item name=”details” xsi:type=”array”>
<item name=”component” xsi:type=”string”>SampWork_ConfigCheckoutDynamicPCB/js/view/summary/item/details</item>
<item name=”children” xsi:type=”array”>
<item name=”thumbnail” xsi:type=”array”>
<item name=”component” xsi:type=”string”>Magento_Checkout/js/view/summary/item/details/thumbnail</item>
<item name=”displayArea” xsi:type=”string”>before_details</item>
</item>
<item name=”subtotal” xsi:type=”array”>
<item name=”component” xsi:type=”string”>Magento_Checkout/js/view/summary/item/details/subtotal</item>
<item name=”displayArea” xsi:type=”string”>after_details</item>
</item>
</item>
</item>
</item>
</item>

Leave a Reply

Your email address will not be published. Required fields are marked *