Skip to content

Error getting order item discounts applied_to for customer order via … #39971

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: 2.4-develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion app/code/Magento/SalesGraphQl/Model/OrderItem/DataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\Framework\App\ObjectManager;
use Magento\Sales\Api\Data\OrderInterface;
use Magento\Sales\Api\Data\OrderItemInterface;
use Magento\Sales\Api\OrderItemRepositoryInterface;
use Magento\Sales\Api\OrderRepositoryInterface;
use Magento\Framework\App\ObjectManager;
use Magento\SalesRule\Api\Data\DiscountAppliedToInterface as DiscountAppliedTo;
use Magento\Tax\Helper\Data as TaxHelper;

/**
Expand Down Expand Up @@ -240,6 +241,7 @@ private function getDiscountDetails(OrderInterface $associatedOrder, OrderItemIn
} else {
$discounts [] = [
'label' => $associatedOrder->getDiscountDescription() ?? __('Discount'),
'applied_to' => $this->getAppliedTo($associatedOrder),
'amount' => [
'value' => abs((float) $orderItem->getDiscountAmount()),
'currency' => $associatedOrder->getOrderCurrencyCode()
Expand All @@ -248,4 +250,18 @@ private function getDiscountDetails(OrderInterface $associatedOrder, OrderItemIn
}
return $discounts;
}

/**
* Get entity type the discount is applied to
*
* @param OrderInterface $order
* @return string
*/
private function getAppliedTo($order)
{
if ((float) $order->getShippingDiscountAmount() > 0) {
return DiscountAppliedTo::APPLIED_TO_SHIPPING;
}
return DiscountAppliedTo::APPLIED_TO_ITEM;
}
}