Skip to content

Commit 16d903c

Browse files
committed
MAGETWO-90729: Imported products are incorrectly in stock if 'allow_backorders' enabled
1 parent 1ed3c22 commit 16d903c

File tree

1 file changed

+12
-4
lines changed
  • app/code/Magento/CatalogImportExport/Model/Import

1 file changed

+12
-4
lines changed

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Magento\Framework\App\ObjectManager;
1616
use Magento\Framework\Exception\LocalizedException;
1717
use Magento\Framework\Filesystem;
18+
use Magento\Framework\Intl\DateTimeFactory;
1819
use Magento\Framework\Model\ResourceModel\Db\ObjectRelationProcessor;
1920
use Magento\Framework\Model\ResourceModel\Db\TransactionManagerInterface;
2021
use Magento\Framework\Stdlib\DateTime;
@@ -724,6 +725,11 @@ class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
724725
*/
725726
private $mediaProcessor;
726727

728+
/**
729+
* @var DateTimeFactory
730+
*/
731+
private $dateTimeFactory;
732+
727733
/**
728734
* @param \Magento\Framework\Json\Helper\Data $jsonHelper
729735
* @param \Magento\ImportExport\Helper\Data $importExportData
@@ -767,7 +773,7 @@ class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
767773
* @param ImageTypeProcessor $imageTypeProcessor
768774
* @param MediaGalleryProcessor $mediaProcessor
769775
* @param StockItemImporterInterface|null $stockItemImporter
770-
*
776+
* @param DateTimeFactory $dateTimeFactory
771777
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
772778
*/
773779
public function __construct(
@@ -812,7 +818,8 @@ public function __construct(
812818
CatalogConfig $catalogConfig = null,
813819
ImageTypeProcessor $imageTypeProcessor = null,
814820
MediaGalleryProcessor $mediaProcessor = null,
815-
StockItemImporterInterface $stockItemImporter = null
821+
StockItemImporterInterface $stockItemImporter = null,
822+
DateTimeFactory $dateTimeFactory = null
816823
) {
817824
$this->_eventManager = $eventManager;
818825
$this->stockRegistry = $stockRegistry;
@@ -868,6 +875,7 @@ public function __construct(
868875
->_initSkus()
869876
->initImagesArrayKeys();
870877
$this->validator->init($this);
878+
$this->dateTimeFactory = $dateTimeFactory ?? ObjectManager::getInstance()->get(DateTimeFactory::class);
871879
}
872880

873881
/**
@@ -2873,8 +2881,8 @@ private function formatStockDataForRow(array $rowData): array
28732881
? $row['is_in_stock']
28742882
: $this->stockStateProvider->verifyStock($stockItemDo);
28752883
if ($this->stockStateProvider->verifyNotification($stockItemDo)) {
2876-
$row['low_stock_date'] =
2877-
gmdate(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT, (new \DateTime())->getTimestamp());
2884+
$date = $this->dateTimeFactory->create('now', new \DateTimeZone('UTC'));
2885+
$row['low_stock_date'] = $date->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT);
28782886
}
28792887
$row['stock_status_changed_auto'] = (int)!$this->stockStateProvider->verifyStock($stockItemDo);
28802888
} else {

0 commit comments

Comments
 (0)