I'm using Magento v2.3.4 and i want to modify the cart item, if there is an update on the cart (add to cart, update cart item, and remove cart item). Currently I'm using plugin for quote collectTotals()
function.
Is this the correct way to do it, or is there any other method that i can use ?
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\Quote\Model\Quote">
<plugin disabled="false" name="Vendor_Module_Plugin_Magento_Quote_Model_Quote" sortOrder="10" type="Vendor\Module\Plugin\Magento\Quote\Model\Quote"/>
</type>
</config>
Vendor/Module/Plugin/Magento/Quote/Model/Quote.php
public function beforeCollectTotals(\Magento\Quote\Model\Quote $subject)
{
$quote = $this->getQuote();
foreach($quote->getAllItems() as $item){
$price = $this->getCustomPrice($item->getProductId());
if($price){
$item->setCustomPrice($price);
$item->setOriginalCustomPrice($price);
}
}
return [];
}
the problem with this plugin is, i got this error after i placed an order:
Please check the billing address information. "firstname" is required. Enter and try again. "lastname" is required. Enter and try again. "street" is required. Enter and try again. "city" is required. Enter and try again. "telephone" is required. Enter and try again. "postcode" is required. Enter and try again. "countryId" is required. Enter and try again.
i check the quote address in the database and those field column is empty