Skip to content

Commit 3c5a508

Browse files
Set a quantity if none is specified so the item is in stock.
1 parent cc57a70 commit 3c5a508

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

Model/Component/Products.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,11 +319,14 @@ public function isStockSpecified(array $productData)
319319
*
320320
* @return array
321321
*/
322-
private function setStock(array $productData)
322+
public function setStock(array $productData)
323323
{
324324
$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+
}
327330
return $newProductData;
328331
}
329332

Test/Unit/Component/ProductsTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,37 @@ public function testStockIsNotSet()
212212
$this->assertFalse($this->component->isStockSpecified($testData));
213213
}
214214

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+
215246
private function createProduct($productId)
216247
{
217248
$productMock = $this->getMockBuilder('Magento\Catalog\Model\Product')

0 commit comments

Comments
 (0)