My website i have updatecart on qty btn change event call so with ajax how to created a plugin for this.
-
you want to update qty to ajax base update the cart and subtotal / order total. – HIren Kadivar Apr 2 '19 at 4:45
Vendor/Module/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\Cart">
<plugin name="update_cart" type="Vendor\Module\Plugin\UpdateCart" sortOrder="999" disabled="false" />
</type>
</config>
Vendor\Module\Plugin\UpdateCart.php
<?php
namespace Vendor\Module\Plugin;
/**
* Class afterUpdateItems
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class UpdateCart {
public function afterUpdateItems($subject, $result, $data)
{
foreach ($data as $itemId => $itemInfo) {
$item = $subject->getQuote()->getItemById($itemId);
$item->setQty(5);
}
return $result;
}
}