File tree Expand file tree Collapse file tree 2 files changed +37
-3
lines changed Expand file tree Collapse file tree 2 files changed +37
-3
lines changed Original file line number Diff line number Diff line change @@ -319,11 +319,14 @@ public function isStockSpecified(array $productData)
319
319
*
320
320
* @return array
321
321
*/
322
- private function setStock (array $ productData )
322
+ public function setStock (array $ productData )
323
323
{
324
324
$ newProductData = $ productData ;
325
- $ newProductData [self ::QTY_COLUMN_HEADING ] = 1 ;
326
- $ newProductData [self ::IS_IN_STOCK_COLUMN_HEADING ] = 1 ;
325
+ if (isset ($ productData [self ::IS_IN_STOCK_COLUMN_HEADING ]) &&
326
+ $ productData [self ::IS_IN_STOCK_COLUMN_HEADING ] == 1 &&
327
+ isset ($ productData [self ::QTY_COLUMN_HEADING ]) == false ) {
328
+ $ newProductData [self ::QTY_COLUMN_HEADING ] = 1 ;
329
+ }
327
330
return $ newProductData ;
328
331
}
329
332
Original file line number Diff line number Diff line change @@ -212,6 +212,37 @@ public function testStockIsNotSet()
212
212
$ this ->assertFalse ($ this ->component ->isStockSpecified ($ testData ));
213
213
}
214
214
215
+ public function testSetStock ()
216
+ {
217
+ $ testData = [
218
+ 'sku ' => 1 ,
219
+ 'name ' => 'Test ' ,
220
+ 'is_in_stock ' => 1
221
+ ];
222
+ $ expectedData = [
223
+ 'sku ' => 1 ,
224
+ 'name ' => 'Test ' ,
225
+ 'is_in_stock ' => 1 ,
226
+ 'qty ' => 1
227
+ ];
228
+ $ this ->assertEquals ($ expectedData , $ this ->component ->setStock ($ testData ));
229
+ }
230
+
231
+ public function testNotSetStock ()
232
+ {
233
+ $ testData = [
234
+ 'sku ' => 1 ,
235
+ 'name ' => 'Test ' ,
236
+ 'is_in_stock ' => 0
237
+ ];
238
+ $ expectedData = [
239
+ 'sku ' => 1 ,
240
+ 'name ' => 'Test ' ,
241
+ 'is_in_stock ' => 0 ,
242
+ ];
243
+ $ this ->assertEquals ($ expectedData , $ this ->component ->setStock ($ testData ));
244
+ }
245
+
215
246
private function createProduct ($ productId )
216
247
{
217
248
$ productMock = $ this ->getMockBuilder ('Magento\Catalog\Model\Product ' )
You can’t perform that action at this time.
0 commit comments