I want to add a custom value to the items in the order summary during checkout ($parent
).
I followed all the other howtos on how to do it:
Create plugin for MagentoCheckoutModelDefaultConfigProvider
:
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="MagentoCheckoutModelDefaultConfigProvider">
<plugin name="my_config_provider" type="MyModulePluginConfigProviderPlugin" />
</type>
</config>
This is my plugin:
namespace MyModulePlugin;
class ConfigProviderPlugin extends MagentoFrameworkModelAbstractModel
{
/**
* @param MagentoCheckoutModelDefaultConfigProvider $subject
* @param array $result
*
* @return array
*/
public function afterGetConfig(MagentoCheckoutModelDefaultConfigProvider $subject, array $result): array
{
foreach ($result['quoteItemData'] as $key => $item) {
$result['quoteItemData'][$key]['display_price'] = $item['row_total'];
$result['quoteItemData'][$key]['display_price'] += $item['tax_amount'];
}
return $result;
}
}
This is a simplyfied version of my plugin. I made sure this is properly implemented. The plugin is being called.
But it seems, that none of the modifications I make to $result['quoteItemData']
make it to the frontend. The new display_price
value is supposed to show up in vendormagentomodule-checkoutviewfrontendwebtemplatesummaryitemdetails.html
(but it does not).
<span class="qty-price" data-bind="text: getFormattedPrice($parent.display_price)"></span>
Also when I add a debug to the template it shows that $parent is unchanged:
<pre data-bind="text: JSON.stringify(ko.toJS($parent), null, 2)"></pre>
What am I doing wrong here?
Thank you
EDIT:
The weird part is that NOTHING I do to quoteItemData
is being reflected in the frontend.
Just for exploring purposes I modified the core file vendormagentomodule-checkoutModelDefaultConfigProvider.php
. I added an extra entry to that array in getQuoteItemData
. It does not get to the frontend whatsoever.