@@ -23,8 +23,9 @@ class ProductRepositoryInterfaceTest extends WebapiAbstract
23
23
const KEY_PRODUCT_ID = StockStatusInterface::PRODUCT_ID ;
24
24
const KEY_CUSTOM_ATTRIBUTES = 'custom_attributes ' ;
25
25
const KEY_ATTRIBUTE_CODE = \Magento \Eav \Api \Data \AttributeInterface::ATTRIBUTE_CODE ;
26
- const CODE_QUANTITY_AND_STOCK_STATUS = 'quantity_and_stock_status ' ;
26
+ const KEY_IS_IN_STOCK = 'is_in_stock ' ;
27
27
28
+ const CODE_QUANTITY_AND_STOCK_STATUS = 'quantity_and_stock_status ' ;
28
29
const PRODUCT_SKU = 'sku-test-catalog-inventory ' ;
29
30
30
31
/**
@@ -159,6 +160,36 @@ public function testSimpleProductCreationWithoutSpecifyingCatalogInventory()
159
160
$ this ->assertTrue ($ response );
160
161
}
161
162
163
+ /**
164
+ * Tests updating product stock item data when previously product was created without specified stock_item
165
+ */
166
+ public function testUpdatingQuantity ()
167
+ {
168
+ // create a simple product with catalog inventory
169
+ $ qty = null ;
170
+ $ productData = $ this ->getSimpleProductData ($ qty );
171
+ $ response = $ this ->saveProduct ($ productData );
172
+ $ stockItemData = $ response [self ::KEY_EXTENSION_ATTRIBUTES ][self ::KEY_STOCK_ITEM ];
173
+
174
+ $ this ->assertEquals ($ qty , $ stockItemData [self ::KEY_QTY ]);
175
+ $ this ->assertEquals (false , $ stockItemData [self ::KEY_IS_IN_STOCK ]);
176
+
177
+ // update a created product with catalog inventory
178
+ $ qty = 1 ;
179
+ $ inStock = true ;
180
+ $ response [self ::KEY_EXTENSION_ATTRIBUTES ][self ::KEY_STOCK_ITEM ][self ::KEY_QTY ] = $ qty ;
181
+ $ response [self ::KEY_EXTENSION_ATTRIBUTES ][self ::KEY_STOCK_ITEM ][self ::KEY_IS_IN_STOCK ] = $ inStock ;
182
+ $ responseUpdated = $ this ->updateProduct ($ response );
183
+ $ stockItemDataUpdated = $ responseUpdated [self ::KEY_EXTENSION_ATTRIBUTES ][self ::KEY_STOCK_ITEM ];
184
+
185
+ $ this ->assertEquals ($ qty , $ stockItemDataUpdated [self ::KEY_QTY ]);
186
+ $ this ->assertEquals ($ inStock , $ stockItemDataUpdated [self ::KEY_IS_IN_STOCK ]);
187
+
188
+ // delete the product; expect that all goes well
189
+ $ response = $ this ->deleteProduct ($ productData [ProductInterface::SKU ]);
190
+ $ this ->assertTrue ($ response );
191
+ }
192
+
162
193
// --- my helpers -----------------------------------------------------------------------------
163
194
164
195
/**
@@ -195,7 +226,7 @@ protected function getSimpleProductData($qty = 1000)
195
226
[self ::KEY_ATTRIBUTE_CODE => 'description ' , 'value ' => 'My Product Description ' ],
196
227
[
197
228
self ::KEY_ATTRIBUTE_CODE => self ::CODE_QUANTITY_AND_STOCK_STATUS ,
198
- 'value ' => [' is_in_stock ' => true , 'qty ' => $ qty ]
229
+ 'value ' => [self :: KEY_IS_IN_STOCK => true , 'qty ' => $ qty ]
199
230
],
200
231
];
201
232
}
@@ -214,7 +245,7 @@ protected function getStockItemData($qty = 1000)
214
245
return [
215
246
self ::KEY_STOCK_ITEM => [
216
247
self ::KEY_QTY => $ qty ,
217
- ' is_in_stock ' => true ,
248
+ self :: KEY_IS_IN_STOCK => true ,
218
249
'is_qty_decimal ' => false ,
219
250
'show_default_notification_message ' => false ,
220
251
'use_config_min_qty ' => true ,
0 commit comments