문제

I created an observer with event checkout_onepage_controller_success_action. I need applied coupon code on checkout onepage success in magento 2. I have to send order coupon code to third party with Curl. Do you know, how we can retrieve coupon code used for the order on order success page?

Here is my observer code:

$orderIds = $observer->getEvent()->getOrderIds();
$lastorderId = $orderIds[0];
$order = $this->orderFactory->load($lastorderId);
// echo $order->getQuoteId(); // show quote ID
// echo $order->getDiscountAmount(); // show discount amount

/* Here I need applied Coupon Code */
도움이 되었습니까?

해결책

For getting the coupon code of an order, you should use

$order->getCouponCode();

다른 팁

You can use function:

$order->getCouponCode

In sales_order table, there is field coupon_code for applied coupon code.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 magento.stackexchange
scroll top