Skip to content

Commit 7d58b3c

Browse files
committed
Merge remote-tracking branch 'origin/AC-7917-V1' into spartans_pr_11022025
2 parents 5bc8203 + 689d591 commit 7d58b3c

File tree

6 files changed

+198
-10
lines changed

6 files changed

+198
-10
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# Copyright © Magento, Inc. All rights reserved.
2-
# See COPYING.txt for license details.
1+
# Copyright 2018 Adobe.
2+
# All Rights Reserved.
33

44
type Mutation {
55
addBundleProductsToCart(input: AddBundleProductsToCartInput @doc(description: "An input object that defines which bundle products to add to the cart.")): AddBundleProductsToCartOutput @resolver(class: "Magento\\QuoteGraphQl\\Model\\Resolver\\AddSimpleProductsToCart") @doc(description: "Add one or more bundle products to the specified cart. We recommend using `addProductsToCart` instead.")
@@ -103,6 +103,7 @@ enum ShipBundleItemsEnum @doc(description: "Defines whether bundle items must be
103103

104104
type BundleOrderItem implements OrderItemInterface @doc(description: "Defines bundle product options for `OrderItemInterface`.") {
105105
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")
106+
parent_sku: String @doc(description: "The SKU of parent product.")
106107
}
107108

108109
type BundleInvoiceItem implements InvoiceItemInterface @doc(description: "Defines bundle product options for `InvoiceItemInterface`.") {

app/code/Magento/ConfigurableProductGraphQl/etc/graphql/di.xml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0"?>
22
<!--
33
/**
4-
* Copyright © Magento, Inc. All rights reserved.
5-
* See COPYING.txt for license details.
4+
* Copyright 2017 Adobe.
5+
* All Rights Reserved.
66
*/
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
@@ -85,4 +85,11 @@
8585
<type name="Magento\Quote\Model\Quote">
8686
<plugin name="update_customized_options" type="Magento\ConfigurableProductGraphQl\Plugin\Quote\UpdateCustomizedOptions"/>
8787
</type>
88+
<type name="Magento\SalesGraphQl\Model\TypeResolver\OrderItem">
89+
<arguments>
90+
<argument name="productTypeMap" xsi:type="array">
91+
<item name="configurable" xsi:type="string">ConfigurableOrderItem</item>
92+
</argument>
93+
</arguments>
94+
</type>
8895
</config>

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# Copyright © Magento, Inc. All rights reserved.
2-
# See COPYING.txt for license details.
1+
# Copyright 2018 Adobe.
2+
# All Rights Reserved.
33
type Mutation {
44
addConfigurableProductsToCart(input: AddConfigurableProductsToCartInput @doc(description: "An input object that defines which configurable products to add to the cart.")): AddConfigurableProductsToCartOutput @resolver(class: "Magento\\ConfigurableProductGraphQl\\Model\\Resolver\\AddConfigurableProductsToCart") @doc(description: "Add one or more configurable products to the specified cart. We recommend using `addProductsToCart` instead.")
55
}
@@ -111,3 +111,7 @@ type ConfigurableProductOptionValue @doc(description: "Defines a value for a con
111111
type StoreConfig {
112112
configurable_thumbnail_source : String @doc(description: "Indicates whether the `parent` or child (`itself`) thumbnail should be used in the cart for configurable products.")
113113
}
114+
115+
type ConfigurableOrderItem implements OrderItemInterface {
116+
parent_sku: String @doc(description: "The SKU of parent product.")
117+
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2020 Adobe.
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -147,6 +147,8 @@ private function fetch()
147147
'product_sku' => $orderItem->getSku(),
148148
'product_url_key' => $associatedProduct ? $associatedProduct->getUrlKey() : null,
149149
'product_type' => $orderItem->getProductType(),
150+
'parent_sku' => ($orderItem->getChildrenItems() && $associatedProduct) ?
151+
$associatedProduct->getSku() : null,
150152
'status' => $orderItem->getStatus(),
151153
'discounts' => $this->getDiscountDetails($associatedOrder, $orderItem),
152154
'product_sale_price' => [

dev/tests/api-functional/testsuite/Magento/GraphQl/Sales/RetrieveOrdersWithBundleProductByOrderNumberTest.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2020 Adobe.
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -77,6 +77,10 @@ public function testGetCustomerOrderBundleProduct()
7777
'bundle-product-two-dropdown-options-simple1-simple2',
7878
$bundledItemInTheOrder['product_sku']
7979
);
80+
$this->assertEquals(
81+
'bundle-product-two-dropdown-options',
82+
$bundledItemInTheOrder['parent_sku']
83+
);
8084
$priceOfBundledItemInOrder = $bundledItemInTheOrder['product_sale_price']['value'];
8185
$this->assertEquals(15, $priceOfBundledItemInOrder);
8286
$this->assertArrayHasKey('bundle_options', $bundledItemInTheOrder);
@@ -266,6 +270,7 @@ private function getCustomerOrderQueryBundleProduct($orderNumber)
266270
quantity_ordered
267271
discounts{amount{value} label}
268272
... on BundleOrderItem{
273+
parent_sku
269274
bundle_options{
270275
__typename
271276
label
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe.
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\GraphQl\Sales;
9+
10+
use Magento\Catalog\Test\Fixture\Product as ProductFixture;
11+
use Magento\ConfigurableProduct\Test\Fixture\AddProductToCart as AddConfigurableProductToCartFixture;
12+
use Magento\Quote\Test\Fixture\QuoteIdMask;
13+
use Magento\Checkout\Test\Fixture\PlaceOrder as PlaceOrderFixture;
14+
use Magento\Checkout\Test\Fixture\SetBillingAddress as SetBillingAddressFixture;
15+
use Magento\Checkout\Test\Fixture\SetDeliveryMethod as SetDeliveryMethodFixture;
16+
use Magento\Checkout\Test\Fixture\SetPaymentMethod as SetPaymentMethodFixture;
17+
use Magento\Checkout\Test\Fixture\SetShippingAddress as SetShippingAddressFixture;
18+
use Magento\ConfigurableProduct\Test\Fixture\Attribute as AttributeFixture;
19+
use Magento\ConfigurableProduct\Test\Fixture\Product as ConfigurableProductFixture;
20+
use Magento\Customer\Test\Fixture\Customer;
21+
use Magento\Framework\Exception\AuthenticationException;
22+
use Magento\GraphQl\GetCustomerAuthenticationHeader;
23+
use Magento\Quote\Test\Fixture\CustomerCart;
24+
use Magento\TestFramework\Fixture\DataFixture;
25+
use Magento\TestFramework\Fixture\DataFixtureStorageManager;
26+
use Magento\TestFramework\Helper\Bootstrap;
27+
use Magento\TestFramework\TestCase\GraphQlAbstract;
28+
29+
/**
30+
* Test for orders with configurable product
31+
*/
32+
class RetrieveOrdersWithConfigurableProductByOrderNumberTest extends GraphQlAbstract
33+
{
34+
/**
35+
* @var GetCustomerAuthenticationHeader
36+
*/
37+
private $customerAuthenticationHeader;
38+
39+
protected function setUp(): void
40+
{
41+
parent::setUp();
42+
$objectManager = Bootstrap::getObjectManager();
43+
$this->customerAuthenticationHeader = $objectManager->get(GetCustomerAuthenticationHeader::class);
44+
}
45+
46+
#[
47+
DataFixture(Customer::class, ['email' => 'customer@example.com'], as: 'customer'),
48+
DataFixture(ProductFixture::class, as: 'product'),
49+
DataFixture(AttributeFixture::class, as: 'attribute'),
50+
DataFixture(
51+
ConfigurableProductFixture::class,
52+
['_options' => ['$attribute$'], '_links' => ['$product$']],
53+
'configurable_product'
54+
),
55+
DataFixture(
56+
CustomerCart::class,
57+
[
58+
'customer_id' => '$customer.id$'
59+
],
60+
'quote'
61+
),
62+
DataFixture(QuoteIdMask::class, ['cart_id' => '$quote.id$'], 'quoteIdMask'),
63+
DataFixture(
64+
AddConfigurableProductToCartFixture::class,
65+
[
66+
'cart_id' => '$quote.id$',
67+
'product_id' => '$configurable_product.id$',
68+
'child_product_id' => '$product.id$',
69+
'qty' => 1
70+
],
71+
),
72+
DataFixture(SetBillingAddressFixture::class, ['cart_id' => '$quote.id$']),
73+
DataFixture(SetShippingAddressFixture::class, ['cart_id' => '$quote.id$']),
74+
DataFixture(SetDeliveryMethodFixture::class, ['cart_id' => '$quote.id$']),
75+
DataFixture(SetPaymentMethodFixture::class, ['cart_id' => '$quote.id$']),
76+
DataFixture(PlaceOrderFixture::class, ['cart_id' => '$quote.id$'], 'order'),
77+
]
78+
public function testGetCustomerOrderConfigurableProduct(): void
79+
{
80+
$order = DataFixtureStorageManager::getStorage()->get('order');
81+
$orderNumber = $order->getIncrementId();
82+
$product = DataFixtureStorageManager::getStorage()->get('product');
83+
$configurableProduct = DataFixtureStorageManager::getStorage()->get('configurable_product');
84+
$customerOrderResponse = $this->getCustomerOrderQueryConfigurableProduct($orderNumber);
85+
$customerOrderItems = $customerOrderResponse[0];
86+
$configurableItemInTheOrder = $customerOrderItems['items'][0];
87+
$this->assertEquals(
88+
$product->getSku(),
89+
$configurableItemInTheOrder['product_sku']
90+
);
91+
92+
$expectedConfigurableOptions = [
93+
'__typename' => 'ConfigurableOrderItem',
94+
'product_sku' => $product->getSku(),
95+
'product_name' => $configurableProduct->getName(),
96+
'parent_sku' => $configurableProduct->getSku(),
97+
'product_url_key' => $configurableProduct->getUrlKey(),
98+
'quantity_ordered' => 1
99+
];
100+
$this->assertEquals($expectedConfigurableOptions, $configurableItemInTheOrder);
101+
}
102+
103+
/**
104+
* Get customer order query for configurable order items
105+
*
106+
* @param $orderNumber
107+
* @return array
108+
* @throws AuthenticationException
109+
*/
110+
private function getCustomerOrderQueryConfigurableProduct($orderNumber): array
111+
{
112+
$query =
113+
<<<QUERY
114+
{
115+
customer {
116+
orders(filter:{number:{eq:"{$orderNumber}"}}) {
117+
total_count
118+
items {
119+
id
120+
number
121+
order_date
122+
status
123+
items {
124+
__typename
125+
product_sku
126+
product_name
127+
product_url_key
128+
quantity_ordered
129+
... on ConfigurableOrderItem {
130+
parent_sku
131+
}
132+
}
133+
total {
134+
base_grand_total{value currency}
135+
grand_total{value currency}
136+
subtotal {value currency }
137+
total_tax{value currency}
138+
taxes {amount{value currency} title rate}
139+
total_shipping{value currency}
140+
shipping_handling
141+
{
142+
amount_including_tax{value}
143+
amount_excluding_tax{value}
144+
total_amount{value}
145+
discounts{amount{value}}
146+
taxes {amount{value} title rate}
147+
}
148+
discounts {amount{value currency} label}
149+
}
150+
}
151+
}
152+
}
153+
}
154+
QUERY;
155+
$currentEmail = 'customer@example.com';
156+
$currentPassword = 'password';
157+
$response = $this->graphQlQuery(
158+
$query,
159+
[],
160+
'',
161+
$this->customerAuthenticationHeader->execute($currentEmail, $currentPassword)
162+
);
163+
164+
$this->assertArrayHasKey('orders', $response['customer']);
165+
$this->assertArrayHasKey('items', $response['customer']['orders']);
166+
$customerOrderItemsInResponse = $response['customer']['orders']['items'];
167+
return $customerOrderItemsInResponse;
168+
}
169+
}

0 commit comments

Comments
 (0)