10
10
use Magento \Catalog \Api \Data \ProductInterface ;
11
11
use Magento \Catalog \Api \ProductRepositoryInterface ;
12
12
use Magento \Framework \Api \SearchCriteriaBuilder ;
13
+ use Magento \Framework \App \ObjectManager ;
13
14
use Magento \Sales \Api \Data \OrderInterface ;
14
15
use Magento \Sales \Api \Data \OrderItemInterface ;
15
16
use Magento \Sales \Api \OrderItemRepositoryInterface ;
16
17
use Magento \Sales \Api \OrderRepositoryInterface ;
17
- use Magento \Framework \ App \ ObjectManager ;
18
+ use Magento \SalesRule \ Api \ Data \ DiscountAppliedToInterface as DiscountAppliedTo ;
18
19
use Magento \Tax \Helper \Data as TaxHelper ;
19
20
20
21
/**
@@ -240,6 +241,7 @@ private function getDiscountDetails(OrderInterface $associatedOrder, OrderItemIn
240
241
} else {
241
242
$ discounts [] = [
242
243
'label ' => $ associatedOrder ->getDiscountDescription () ?? __ ('Discount ' ),
244
+ 'applied_to ' => $ this ->getAppliedTo ($ associatedOrder ),
243
245
'amount ' => [
244
246
'value ' => abs ((float ) $ orderItem ->getDiscountAmount ()),
245
247
'currency ' => $ associatedOrder ->getOrderCurrencyCode ()
@@ -248,4 +250,18 @@ private function getDiscountDetails(OrderInterface $associatedOrder, OrderItemIn
248
250
}
249
251
return $ discounts ;
250
252
}
253
+
254
+ /**
255
+ * Get entity type the discount is applied to
256
+ *
257
+ * @param OrderInterface $order
258
+ * @return string
259
+ */
260
+ private function getAppliedTo ($ order )
261
+ {
262
+ if ((float ) $ order ->getShippingDiscountAmount () > 0 ) {
263
+ return DiscountAppliedTo::APPLIED_TO_SHIPPING ;
264
+ }
265
+ return DiscountAppliedTo::APPLIED_TO_ITEM ;
266
+ }
251
267
}
0 commit comments