Skip to content

Commit 8e36536

Browse files
committed
MAGETWO-54740: Imported products are incorrectly in stock if 'allow_backorders' enabled
1 parent 8c3acc5 commit 8e36536

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

app/code/Magento/CatalogImportExport/Model/Import/Product.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2137,7 +2137,9 @@ protected function _saveStockItem()
21372137
)
21382138
) {
21392139
$stockItemDo->setData($row);
2140-
$row['is_in_stock'] = $this->stockStateProvider->verifyStock($stockItemDo);
2140+
$row['is_in_stock'] = $stockItemDo->getBackorders() && isset($row['is_in_stock'])
2141+
? $row['is_in_stock']
2142+
: $this->stockStateProvider->verifyStock($stockItemDo);
21412143
if ($this->stockStateProvider->verifyNotification($stockItemDo)) {
21422144
$row['low_stock_date'] = $this->dateTime->gmDate(
21432145
'Y-m-d H:i:s',

dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import/ProductTest.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2143,4 +2143,48 @@ public function testProductsWithMultipleStoresWhenMediaIsDisabled()
21432143
$this->assertTrue($errors->getErrorsCount() === 0);
21442144
$this->assertTrue($this->_model->importData());
21452145
}
2146+
2147+
/**
2148+
* Test that imported product stock status with backorders functionality enabled can be set to 'out of stock'.
2149+
*
2150+
* @magentoDataIsolation enabled
2151+
* @magentoAppIsolation enabled
2152+
*/
2153+
public function testImportWithBackordersEnabled()
2154+
{
2155+
$this->importFile('products_to_import_with_backorders_enabled_and_0_qty.csv');
2156+
$product = $this->getProductBySku('simple_new');
2157+
$this->assertFalse($product->getDataByKey('quantity_and_stock_status')['is_in_stock']);
2158+
}
2159+
2160+
/**
2161+
* Import file by providing import filename in parameters
2162+
*
2163+
* @param string $fileName
2164+
*/
2165+
private function importFile(string $fileName)
2166+
{
2167+
$filesystem = $this->objectManager->create(\Magento\Framework\Filesystem::class);
2168+
$directory = $filesystem->getDirectoryWrite(DirectoryList::ROOT);
2169+
$source = $this->objectManager->create(
2170+
\Magento\ImportExport\Model\Import\Source\Csv::class,
2171+
[
2172+
'file' => __DIR__ . '/_files/' . $fileName,
2173+
'directory' => $directory
2174+
]
2175+
);
2176+
$errors = $this->_model->setParameters(
2177+
[
2178+
'behavior' => \Magento\ImportExport\Model\Import::BEHAVIOR_APPEND,
2179+
'entity' => 'catalog_product',
2180+
\Magento\ImportExport\Model\Import::FIELDS_ENCLOSURE => 1
2181+
]
2182+
)->setSource(
2183+
$source
2184+
)->validateData();
2185+
2186+
$this->assertTrue($errors->getErrorsCount() == 0);
2187+
2188+
$this->_model->importData();
2189+
}
21462190
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
sku,store_view_code,attribute_set_code,product_type,categories,product_websites,name,description,short_description,weight,product_online,tax_class_name,visibility,price,special_price,special_price_from_date,special_price_to_date,url_key,meta_title,meta_keywords,meta_description,base_image,base_image_label,small_image,small_image_label,thumbnail_image,thumbnail_image_label,created_at,updated_at,new_from_date,new_to_date,display_product_options_in,map_price,msrp_price,map_enabled,gift_message_available,custom_design,custom_design_from,custom_design_to,custom_layout_update,page_layout,product_options_container,msrp_display_actual_price_type,country_of_manufacture,additional_attributes,qty,out_of_stock_qty,use_config_min_qty,is_qty_decimal,allow_backorders,use_config_backorders,min_cart_qty,use_config_min_sale_qty,max_cart_qty,use_config_max_sale_qty,is_in_stock,notify_on_stock_below,use_config_notify_stock_qty,manage_stock,use_config_manage_stock,use_config_qty_increments,qty_increments,use_config_enable_qty_inc,enable_qty_increments,is_decimal_divided,website_id,related_skus,crosssell_skus,upsell_skus,additional_images,additional_image_labels,hide_from_product_page,custom_options,bundle_price_type,bundle_sku_type,bundle_price_view,bundle_weight_type,bundle_values,associated_skus
2+
simple_new,,Default,simple,,base,New Product,,,,1,Taxable Goods,"Catalog, Search",10,,,,new-product,New Product,New Product,New Product ,,,,,,,10/20/2015 7:05,10/20/2015 7:05,,,Block after Info Column,,,,,,,,,,,,,"has_options=1,quantity_and_stock_status=In Stock,required_options=1",0,0,1,0,1,0,1,1,10000,1,0,1,1,1,0,1,1,0,0,0,1,,,,,,,,,,,,,

0 commit comments

Comments
 (0)