I have created a plugin to add custom functionaly before Coupon apply it's working fine on checkout page but not working on cart page:
/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\CouponManagement">
<plugin name="checkout_coupon_apply" type="Geekay\Rewardpoint\Plugin\CheckoutCouponApply"/>
</type>
/Plugin/CheckoutCouponApply.php
<?php
namespace Geekay\Rewardpoint\Plugin;
use Magento\Framework\Exception\NoSuchEntityException;
class CheckoutCouponApply {
protected $_customerSession;
protected $_cart;
protected $_rewardHelper;
protected $_jsonFactory;
protected $_rule;
protected $_storeManager;
protected $_coupon;
protected $logger;
public function __construct(
\Magento\Customer\Model\Session $customerSession,
\Magento\Checkout\Model\Cart $cart,
\Geekay\Rewardpoint\Helper\Data $asplHelper,
\Magento\Framework\Controller\Result\JsonFactory $jsonFactory,
\Magento\SalesRule\Model\Rule $rule,
\Magento\SalesRule\Model\Coupon $coupon,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Psr\Log\LoggerInterface $logger
) {
$this->_customerSession = $customerSession;
$this->_cart = $cart;
$this->_rewardHelper = $asplHelper;
$this->_jsonFactory = $jsonFactory;
$this->_storeManager = $storeManager;
$this->_rule = $rule;
$this->_coupon = $coupon;
$this->logger = $logger;
}
public function beforeSet(\Magento\Quote\Model\CouponManagement $subject, $cartId, $couponCode)
{
// code here
}
}
What's wrong here?