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 ;
19
+
18
20
use Magento \Tax \Helper \Data as TaxHelper ;
19
21
20
22
/**
@@ -240,6 +242,7 @@ private function getDiscountDetails(OrderInterface $associatedOrder, OrderItemIn
240
242
} else {
241
243
$ discounts [] = [
242
244
'label ' => $ associatedOrder ->getDiscountDescription () ?? __ ('Discount ' ),
245
+ 'applied_to ' => $ this ->getAppliedTo ($ associatedOrder ),
243
246
'amount ' => [
244
247
'value ' => abs ((float ) $ orderItem ->getDiscountAmount ()),
245
248
'currency ' => $ associatedOrder ->getOrderCurrencyCode ()
@@ -248,4 +251,18 @@ private function getDiscountDetails(OrderInterface $associatedOrder, OrderItemIn
248
251
}
249
252
return $ discounts ;
250
253
}
254
+
255
+ /**
256
+ * Get entity type the discount is applied to
257
+ *
258
+ * @param OrderInterface $order
259
+ * @return string
260
+ */
261
+ public function getAppliedTo ($ order )
262
+ {
263
+ if ((float ) $ order ->getShippingDiscountAmount () > 0 ) {
264
+ return DiscountAppliedTo::APPLIED_TO_SHIPPING ;
265
+ }
266
+ return DiscountAppliedTo::APPLIED_TO_ITEM ;
267
+ }
251
268
}
0 commit comments