1
1
<?php
2
+ /**
3
+ * Copyright 2025 Adobe
4
+ * All Rights Reserved.
5
+ */
6
+
2
7
declare (strict_types=1 );
3
8
4
9
namespace Magento \Sales \Service \V1 ;
@@ -27,6 +32,11 @@ class OrderApiConfigurableVariationsPriceTest extends WebapiAbstract
27
32
{
28
33
private const RESOURCE_PATH = '/V1/orders ' ;
29
34
35
+ /**
36
+ * Fixture storage manager for resolving test data.
37
+ *
38
+ * @var DataFixtureStorage
39
+ */
30
40
private DataFixtureStorage $ fixtures ;
31
41
32
42
/**
@@ -40,18 +50,23 @@ protected function setUp(): void
40
50
}
41
51
42
52
#[
43
- DataFixture(AttributeFixture::class, [
44
- 'frontend_input ' => 'select ' ,
45
- 'options ' => ['40 ' , '42 ' ],
46
- 'is_configurable ' => true ,
47
- 'is_global ' => true
48
- ], as: 'attribute ' ),
49
- DataFixture(ProductFixture::class,
53
+ DataFixture(
54
+ AttributeFixture::class,
55
+ [
56
+ 'frontend_input ' => 'select ' ,
57
+ 'options ' => ['40 ' , '42 ' ],
58
+ 'is_configurable ' => true ,
59
+ 'is_global ' => true ,
60
+ ],
61
+ as: 'attribute '
62
+ ),
63
+ DataFixture(
64
+ ProductFixture::class,
50
65
[
51
66
'price ' => 100 ,
52
67
'custom_attributes ' => [
53
- ['attribute_code ' => '$attribute.attribute_code$ ' , 'value ' => '40 ' ]
54
- ]
68
+ ['attribute_code ' => '$attribute.attribute_code$ ' , 'value ' => '40 ' ],
69
+ ],
55
70
],
56
71
as: 'product1 '
57
72
),
@@ -60,31 +75,34 @@ protected function setUp(): void
60
75
[
61
76
'price ' => 100 ,
62
77
'custom_attributes ' => [
63
- ['attribute_code ' => '$attribute.attribute_code$ ' , 'value ' => '42 ' ]
64
- ]
78
+ ['attribute_code ' => '$attribute.attribute_code$ ' , 'value ' => '42 ' ],
79
+ ],
65
80
],
66
81
as: 'product2 '
67
82
),
68
83
DataFixture(
69
84
ConfigurableProductFixture::class,
70
85
[
71
- '_options ' => ['$attribute$ ' ],
72
- '_links ' => ['$product1$ ' , '$product2$ ' ],
73
- 'custom_attributes ' => [
74
- ['attribute_code ' => '$attribute.attribute_code$ ' , 'value ' => '40 ' ]
75
- ]
86
+ '_options ' => ['$attribute$ ' ],
87
+ '_links ' => ['$product1$ ' , '$product2$ ' ],
88
+ 'custom_attributes ' => [
89
+ ['attribute_code ' => '$attribute.attribute_code$ ' , 'value ' => '40 ' ],
90
+ ],
76
91
],
77
92
'configurable_product '
78
93
),
79
94
DataFixture(GuestCart::class, as: 'cart ' ),
80
95
DataFixture(Customer::class, as: 'customer ' ),
81
96
DataFixture(CustomerCart::class, ['customer_id ' => '$customer.id$ ' ], as: 'quote ' ),
82
- DataFixture(AddProductToCart::class, [
83
- 'cart_id ' => '$cart.id$ ' ,
84
- 'product_id ' => '$configurable_product.id$ ' ,
85
- 'child_product_id ' => '$product1.id$ ' ,
86
- 'qty ' => 1
87
- ]),
97
+ DataFixture(
98
+ AddProductToCart::class,
99
+ [
100
+ 'cart_id ' => '$cart.id$ ' ,
101
+ 'product_id ' => '$configurable_product.id$ ' ,
102
+ 'child_product_id ' => '$product1.id$ ' ,
103
+ 'qty ' => 1 ,
104
+ ]
105
+ ),
88
106
DataFixture(SetBillingAddress::class, ['cart_id ' => '$cart.id$ ' ]),
89
107
DataFixture(SetShippingAddress::class, ['cart_id ' => '$cart.id$ ' ]),
90
108
DataFixture(SetGuestEmail::class, ['cart_id ' => '$cart.id$ ' ]),
@@ -95,12 +113,12 @@ protected function setUp(): void
95
113
/**
96
114
* Validates that simple products linked to a configurable parent in an order:
97
115
* - Exist in the response
98
- * - Are linked correctly via parent_item_id
99
- * - Carry expected pricing logic (either 0.0 or actual price depending on Magento behavior)
116
+ * - Are linked via parent_item_id
117
+ * - Carry expected pricing logic
100
118
*/
101
119
public function testSimpleItemsAssignedToConfigurableHaveValidPrice (): void
102
120
{
103
- $ orderData = $ this ->callOrderApi ((string )$ this ->fixtures ->get ('order ' )->getEntityId ());
121
+ $ orderData = $ this ->callOrderApi ((string ) $ this ->fixtures ->get ('order ' )->getEntityId ());
104
122
105
123
$ this ->assertArrayHasKey ('items ' , $ orderData );
106
124
$ this ->assertIsArray ($ orderData ['items ' ]);
@@ -129,27 +147,26 @@ public function testSimpleItemsAssignedToConfigurableHaveValidPrice(): void
129
147
130
148
foreach ($ simpleItemsWithParent as $ item ) {
131
149
$ this ->assertNotEmpty ($ item ['sku ' ], 'Simple item must have SKU. ' );
150
+ $ price = (float ) $ item ['price ' ];
132
151
133
- $ price = (float )$ item ['price ' ];
134
- $ this ->assertTrue (true , sprintf (
135
- 'Simple item "%s" has price %s (valid if parent holds pricing). ' ,
136
- $ item ['sku ' ],
137
- $ price
138
- ));
152
+ $ this ->assertTrue (
153
+ true ,
154
+ sprintf ('Simple item "%s" has price %s. ' , $ item ['sku ' ], $ price )
155
+ );
139
156
140
157
if ($ price > 0.0 ) {
141
158
$ this ->assertGreaterThan (
142
159
0.0 ,
143
160
$ price ,
144
- sprintf ('Simple item "%s" should have valid price if used independently . ' , $ item ['sku ' ])
161
+ sprintf ('Simple item "%s" should have price > 0 . ' , $ item ['sku ' ])
145
162
);
146
163
}
147
164
}
148
165
149
166
foreach ($ unlinkedSimples as $ item ) {
150
167
$ this ->assertEquals (
151
168
0.0 ,
152
- (float )$ item ['price ' ],
169
+ (float ) $ item ['price ' ],
153
170
'Unlinked simple item should have zero price. '
154
171
);
155
172
}
@@ -158,7 +175,7 @@ public function testSimpleItemsAssignedToConfigurableHaveValidPrice(): void
158
175
}
159
176
160
177
/**
161
- * Calls the REST API to retrieve order data by order ID.
178
+ * Calls the REST and SOAP APIs to retrieve order data by order ID.
162
179
*
163
180
* @param string $orderId
164
181
* @return array
@@ -181,7 +198,7 @@ private function callOrderApi(string $orderId): array
181
198
}
182
199
183
200
/**
184
- * Validates that each simple product has a valid parent link to a configurable item .
201
+ * Validates that simple items link correctly to one of the configurable parent items .
185
202
*
186
203
* @param array $configurableItems
187
204
* @param array $simpleItems
@@ -195,10 +212,7 @@ private function assertSimpleItemsHaveValidParent(array $configurableItems, arra
195
212
$ this ->assertContains (
196
213
$ item ['parent_item_id ' ],
197
214
$ configurableItemIds ,
198
- sprintf (
199
- 'Simple item "%s" must link to a configurable parent. ' ,
200
- $ item ['item_id ' ] ?? 'N/A '
201
- )
215
+ sprintf ('Simple item "%s" must link to a configurable parent. ' , $ item ['item_id ' ] ?? 'N/A ' )
202
216
);
203
217
}
204
218
}
0 commit comments