SalesQuoteCollectTotalsBefore
This observer will dispatch when the shipment is selected. After that, I need to apply a coupon code.
public function execute(\Magento\Framework\Event\Observer $observer)
{
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$cart = $objectManager->get('\Magento\Checkout\Model\Cart');
$couponCode = "FIRSTORDER";
$quote = $cart->getQuote()->setCouponCode($couponCode)
->collectTotals()
->save();
}
I created a coupon code FIRSTORDER. But I try to execute the function I am getting the following error.
"SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data"
How to solve this issue?. How can I apply the coupon code? please share your valuable feedback