Skip to content

Commit ddabec9

Browse files
committed
MC-20639: MyAccount :: Order Details :: Refund (creditMemo) Details by Order Number
1 parent 4adb48e commit ddabec9

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed

app/code/Magento/BundleGraphQl/etc/schema.graphqls

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ type BundleShipmentItem implements ShipmentItemInterface {
100100
bundle_options: [ItemSelectedBundleOption] @doc(description: "A list of bundle options that are assigned to the bundle product") @resolver(class: "Magento\\BundleGraphQl\\Model\\Resolver\\Order\\Item\\BundleOptions")
101101
}
102102

103+
type BundleCreditMemoItem implements CreditMemoItemInterface {
104+
bundle_options: [ItemSelectedBundleOption] @doc(description: "A list of bundle options that are assigned to the bundle product")
105+
}
106+
103107
type ItemSelectedBundleOption @doc(description: "A list of options of the selected bundle product") {
104108
id: ID! @doc(description: "The unique identifier of the option")
105109
label: String! @doc(description: "The label of the option")

app/code/Magento/SalesGraphQl/Model/Resolver/CreditMemo/CreditMemoItems.php

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,36 @@ private function getCreditMemoItemData(OrderInterface $order, CreditmemoItemInte
123123
],
124124
'quantity_refunded' => $creditMemoItem->getQty(),
125125
'model' => $creditMemoItem,
126-
'product_type' => $orderItem['product_type']
126+
'product_type' => $orderItem['product_type'],
127+
'discounts' => $this->formatDiscountDetails($order, $creditMemoItem)
127128
];
128129
}
130+
131+
/**
132+
* Returns formatted information about an applied discount
133+
*
134+
* @param OrderInterface $associatedOrder
135+
* @param CreditmemoItemInterface $creditmemoItem
136+
* @return array
137+
*/
138+
private function formatDiscountDetails(
139+
OrderInterface $associatedOrder,
140+
CreditmemoItemInterface $creditmemoItem
141+
) : array {
142+
if ($associatedOrder->getDiscountDescription() === null
143+
&& $creditmemoItem->getDiscountAmount() == 0
144+
&& $associatedOrder->getDiscountAmount() == 0
145+
) {
146+
$discounts = [];
147+
} else {
148+
$discounts[] = [
149+
'label' => $associatedOrder->getDiscountDescription() ?? _('Discount'),
150+
'amount' => [
151+
'value' => abs($creditmemoItem->getDiscountAmount()) ?? 0,
152+
'currency' => $associatedOrder->getOrderCurrencyCode()
153+
]
154+
];
155+
}
156+
return $discounts;
157+
}
129158
}

app/code/Magento/SalesGraphQl/etc/schema.graphqls

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,16 +217,13 @@ interface CreditMemoItemInterface @doc(description: "Credit memo item details")
217217
product_name: String @doc(description: "The name of the base product")
218218
product_sku: String! @doc(description: "SKU of the base product")
219219
product_sale_price: Money! @doc(description: "The sale price for the base product, including selected options")
220+
discounts: [Discount] @doc(description: "Contains information about the final discount amount for the base product, including discounts on options")
220221
quantity_refunded: Float @doc(description: "The number of refunded items")
221222
}
222223

223224
type CreditMemoItem implements CreditMemoItemInterface {
224225
}
225226

226-
type BundleCreditMemoItem implements CreditMemoItemInterface {
227-
bundle_options: [ItemSelectedBundleOption] @doc(description: "A list of bundle options that are assigned to the bundle product")
228-
}
229-
230227
type CreditMemoTotal @doc(description: "Credit memo price details") {
231228
subtotal: Money! @doc(description: "The subtotal of the invoice, excluding shipping, discounts, and taxes")
232229
discounts: [Discount] @doc(description: "The applied discounts to the credit memo")

0 commit comments

Comments
 (0)