$result = []; foreach ($collection as $order) $result[$order->getId()] = $order->getCouponCode();
try $order = $this->orderRepository->get($orderId); return $order->getCouponCode(); catch (\Exception $e) return null;
$this->orderRepository = $orderRepository; magento 2 get coupon code programmatically
$this->couponCollectionFactory = $couponCollectionFactory;
<?php namespace YourNamespace\YourModule\Model; use Magento\Sales\Api\OrderRepositoryInterface; $result = []
public function getAllCoupons(): array
public function getAppliedCouponForItem($itemId) foreach ($collection as $order) $result[$order->
public function fromQuote(int $quoteId): ?string