Magento 2 Get Coupon Code Programmatically -
$quote = $quoteFactory->create()->load($quoteId); return $quote->getCouponCode();
use Magento\Quote\Model\QuoteFactory; public function getCouponCodeFromQuote(QuoteFactory $quoteFactory, $quoteId)
use Magento\Sales\Model\ResourceModel\Order\CollectionFactory; public function getCouponCodesFromOrders(CollectionFactory $orderCollectionFactory, array $orderIds) magento 2 get coupon code programmatically
private CartRepositoryInterface $quoteRepository; private OrderRepositoryInterface $orderRepository;
private CollectionFactory $couponCollectionFactory; $quote = $quoteFactory->
$this->orderRepository = $orderRepository;
class GetCouponCodeService
class GetCoupon implements HttpGetActionInterface
private OrderRepositoryInterface $orderRepository; private OrderRepositoryInterface $orderRepository
return $result; Useful for generating a dropdown of all existing coupon codes in admin or API.