Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tangar76/991b4423cd9baaac79381422581951c0 to your computer and use it in GitHub Desktop.
Save tangar76/991b4423cd9baaac79381422581951c0 to your computer and use it in GitHub Desktop.
Fixed stock status to "Out of Stock" after product import even product allowed backorders. .../module-catalog-import-export/Model/Import/Product.php
--- /vendor/magento/module-catalog-import-export/Model/Import/Product.php
+++ /vendor/magento/module-catalog-import-export/Model/Import/Product.php (Unsaved)
@@ -3062,7 +3062,9 @@
$stockItemDo = $this->stockRegistry->getStockItem($row['product_id'], $row['website_id']);
$existStockData = $stockItemDo->getData();
- if (isset($rowData['qty']) && $rowData['qty'] == 0 && !isset($rowData['is_in_stock'])) {
+ if (isset($rowData['qty']) && $rowData['qty'] == 0 && !isset($rowData['is_in_stock'])
+ && empty($existStockData['backorders']) // backorders not set or set to 0
+ ) {
$rowData['is_in_stock'] = 0;
}
@@ -3074,7 +3076,9 @@
);
if ($this->stockConfiguration->isQty($this->skuProcessor->getNewSku($sku)['type_id'])) {
- if (isset($rowData['qty']) && $rowData['qty'] == 0) {
+ if (isset($rowData['qty']) && $rowData['qty'] == 0
+ && empty($existStockData['backorders']) // backorders not set or set to 0
+ ) {
$row['is_in_stock'] = 0;
}
$stockItemDo->setData($row);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment