Skip to content

Commit 7034fda

Browse files
committed
Error getting order item discounts applied_to for customer order via GraphQl customer request
1 parent 7da46f5 commit 7034fda

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

app/code/Magento/SalesGraphQl/Model/OrderItem/DataProvider.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010
use Magento\Catalog\Api\Data\ProductInterface;
1111
use Magento\Catalog\Api\ProductRepositoryInterface;
1212
use Magento\Framework\Api\SearchCriteriaBuilder;
13+
use Magento\Framework\App\ObjectManager;
1314
use Magento\Sales\Api\Data\OrderInterface;
1415
use Magento\Sales\Api\Data\OrderItemInterface;
1516
use Magento\Sales\Api\OrderItemRepositoryInterface;
1617
use Magento\Sales\Api\OrderRepositoryInterface;
17-
use Magento\Framework\App\ObjectManager;
18+
use Magento\SalesRule\Api\Data\DiscountAppliedToInterface as DiscountAppliedTo;
19+
1820
use Magento\Tax\Helper\Data as TaxHelper;
1921

2022
/**
@@ -240,6 +242,7 @@ private function getDiscountDetails(OrderInterface $associatedOrder, OrderItemIn
240242
} else {
241243
$discounts [] = [
242244
'label' => $associatedOrder->getDiscountDescription() ?? __('Discount'),
245+
'applied_to' => $this->getAppliedTo($associatedOrder),
243246
'amount' => [
244247
'value' => abs((float) $orderItem->getDiscountAmount()),
245248
'currency' => $associatedOrder->getOrderCurrencyCode()
@@ -248,4 +251,18 @@ private function getDiscountDetails(OrderInterface $associatedOrder, OrderItemIn
248251
}
249252
return $discounts;
250253
}
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+
}
251268
}

0 commit comments

Comments
 (0)