Magento 2 Get Coupon Code Programmatically [Android]
<?php namespace YourNamespace\YourModule\Model; use Magento\Sales\Api\OrderRepositoryInterface;
public function fromCurrentSession( \Magento\Checkout\Model\Session $checkoutSession, \Magento\Customer\Model\Session $customerSession ): ?string if ($customerSession->isLoggedIn()) $quote = $this->quoteRepository->getActiveForCustomer($customerSession->getCustomerId()); else $quote = $checkoutSession->getQuote(); return $quote->getCouponCode(); magento 2 get coupon code programmatically
try $order = $this->orderRepository->get($orderId); return $order->getCouponCode(); catch (\Exception $e) return null; ?php namespace YourNamespace\YourModule\Model
try $order = $this->orderRepository->get($orderId); return $order->getCouponCode(); catch (NoSuchEntityException $e) return null; isLoggedIn()) $quote = $this->
class GetCouponFromQuote