public function getCouponCode(){
$cartQuote = $this->cart->getQuote();
return $cartQuote->getCouponCode();
}
Here use own create function replace $cartQuote->getCouponCode(); to $cartQuote->getOwnFuction(); And put code in getOwnFuction() for apply custom couponCode
And then i put in my function: Vendor\Shipping\Model\Quote\Address\Rate.php
public function importShippingRate(\Magento\Quote\Model\Quote\Address\RateResult\AbstractResult $rate)
{
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$helper = $objectManager->create('Vendor\Shipping\Helper\Data');
$couponCode = $helper->getCouponCode();
echo 'CouponsCode = '.$couponCode;
}
Best Answer
I believe checkout session can be used instead cartId use below code:
Two steps:
Step 1: Define
\Magento\Checkout\Model\Session
in your constructorStep 2: