Skip to content

Commit 43e3fd7

Browse files
author
Onischenko, Yaroslav(yonischenko)
committed
Merge pull request #334 from magento-nord/MAGETWO-48153
[NORD] MAGETWO-48153 fix
2 parents 32b8b85 + dd18ea2 commit 43e3fd7

20 files changed

+289
-529
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1963,7 +1963,7 @@ protected function _saveStockItem()
19631963
$productIdsToReindex[] = $row['product_id'];
19641964

19651965
$row['website_id'] = $this->stockConfiguration->getDefaultScopeId();
1966-
$row['stock_id'] = $this->stockRegistry->getStock()->getStockId();
1966+
$row['stock_id'] = $this->stockRegistry->getStock($row['website_id'])->getStockId();
19671967

19681968
$stockItemDo = $this->stockRegistry->getStockItem($row['product_id'], $row['website_id']);
19691969
$existStockData = $stockItemDo->getData();

app/code/Magento/CatalogInventory/Api/StockRegistryInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
interface StockRegistryInterface
1313
{
1414
/**
15-
* @param int|null $stockId
15+
* @param int $scopeId
1616
* @return \Magento\CatalogInventory\Api\Data\StockInterface
1717
*/
18-
public function getStock($stockId = null);
18+
public function getStock($scopeId = null);
1919

2020
/**
2121
* @param int $productId

app/code/Magento/CatalogInventory/Api/StockStatusCriteriaInterface.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,31 @@ interface StockStatusCriteriaInterface extends \Magento\Framework\Api\CriteriaIn
1515
* Add Criteria object
1616
*
1717
* @param \Magento\CatalogInventory\Api\StockStatusCriteriaInterface $criteria
18-
* @return void
18+
* @return bool
1919
*/
2020
public function addCriteria(\Magento\CatalogInventory\Api\StockStatusCriteriaInterface $criteria);
2121

2222
/**
2323
* Filter by scope(s)
2424
*
2525
* @param int $scope
26-
* @return void
26+
* @return bool
2727
*/
2828
public function setScopeFilter($scope);
2929

3030
/**
3131
* Add product(s) filter
3232
*
3333
* @param int $products
34-
* @return void
34+
* @return bool
3535
*/
3636
public function setProductsFilter($products);
3737

3838
/**
3939
* Add filter by quantity
4040
*
4141
* @param float $qty
42-
* @return void
42+
* @return bool
4343
*/
4444
public function setQtyFilter($qty);
4545
}

app/code/Magento/CatalogInventory/Helper/Stock.php

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
namespace Magento\CatalogInventory\Helper;
77

88
use Magento\CatalogInventory\Model\Spi\StockRegistryProviderInterface;
9-
use Magento\CatalogInventory\Model\Spi\StockResolverInterface;
109
use Magento\Store\Model\StoreManagerInterface;
1110
use Magento\Framework\App\Config\ScopeConfigInterface;
1211
use Magento\CatalogInventory\Model\ResourceModel\Stock\StatusFactory;
@@ -48,30 +47,22 @@ class Stock
4847
*/
4948
private $stockRegistryProvider;
5049

51-
/**
52-
* @var StockResolverInterface
53-
*/
54-
protected $stockResolver;
55-
5650
/**
5751
* @param StoreManagerInterface $storeManager
5852
* @param ScopeConfigInterface $scopeConfig
5953
* @param StatusFactory $stockStatusFactory
6054
* @param StockRegistryProviderInterface $stockRegistryProvider
61-
* @param StockResolverInterface $stockResolver
6255
*/
6356
public function __construct(
6457
StoreManagerInterface $storeManager,
6558
ScopeConfigInterface $scopeConfig,
6659
StatusFactory $stockStatusFactory,
67-
StockRegistryProviderInterface $stockRegistryProvider,
68-
StockResolverInterface $stockResolver
60+
StockRegistryProviderInterface $stockRegistryProvider
6961
) {
7062
$this->storeManager = $storeManager;
7163
$this->scopeConfig = $scopeConfig;
7264
$this->stockStatusFactory = $stockStatusFactory;
7365
$this->stockRegistryProvider = $stockRegistryProvider;
74-
$this->stockResolver = $stockResolver;
7566
}
7667

7768
/**
@@ -84,9 +75,8 @@ public function __construct(
8475
public function assignStatusToProduct(Product $product, $stockStatus = null)
8576
{
8677
if ($stockStatus === null) {
87-
$productId = $product->getId();
88-
$stockId = $this->stockResolver->getStockId($productId, $product->getStore()->getWebsiteId());
89-
$stockStatus = $this->stockRegistryProvider->getStockStatus($productId, $stockId);
78+
$websiteId = $product->getStore()->getWebsiteId();
79+
$stockStatus = $this->stockRegistryProvider->getStockStatus($product->getId(), $websiteId);
9080
$status = $stockStatus->getStockStatus();
9181
}
9282
$product->setIsSalable($status);
@@ -103,8 +93,7 @@ public function addStockStatusToProducts(AbstractCollection $productCollection)
10393
$websiteId = $this->storeManager->getStore($productCollection->getStoreId())->getWebsiteId();
10494
foreach ($productCollection as $product) {
10595
$productId = $product->getId();
106-
$stockId = $this->stockResolver->getStockId($productId, $websiteId);
107-
$stockStatus = $this->stockRegistryProvider->getStockStatus($productId, $stockId);
96+
$stockStatus = $this->stockRegistryProvider->getStockStatus($productId, $websiteId);
10897
$status = $stockStatus->getStockStatus();
10998
$product->setIsSalable($status);
11099
}

app/code/Magento/CatalogInventory/Model/Spi/StockRegistryProviderInterface.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,22 @@
1111
interface StockRegistryProviderInterface
1212
{
1313
/**
14-
* @param int|null $stockId
14+
* @param int $scopeId
1515
* @return \Magento\CatalogInventory\Api\Data\StockInterface
1616
*/
17-
public function getStock($stockId);
17+
public function getStock($scopeId);
1818

1919
/**
2020
* @param int $productId
21-
* @param int $stockId
21+
* @param int $scopeId
2222
* @return \Magento\CatalogInventory\Api\Data\StockItemInterface
2323
*/
24-
public function getStockItem($productId, $stockId);
24+
public function getStockItem($productId, $scopeId);
2525

2626
/**
2727
* @param int $productId
28-
* @param int $stockId
28+
* @param int $scopeId
2929
* @return \Magento\CatalogInventory\Api\Data\StockStatusInterface
3030
*/
31-
public function getStockStatus($productId, $stockId);
31+
public function getStockStatus($productId, $scopeId);
3232
}

app/code/Magento/CatalogInventory/Model/Spi/StockResolverInterface.php

Lines changed: 0 additions & 19 deletions
This file was deleted.

app/code/Magento/CatalogInventory/Model/Stock/Item.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public function getStockId()
177177
{
178178
$stockId = $this->getData(static::STOCK_ID);
179179
if ($stockId === null) {
180-
$stockId = $this->stockRegistry->getStock()->getStockId();
180+
$stockId = $this->stockRegistry->getStock($this->getWebsiteId())->getStockId();
181181
}
182182
return (int) $stockId;
183183
}

app/code/Magento/CatalogInventory/Model/StockIndex.php

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use Magento\Catalog\Model\ProductFactory;
1414
use Magento\CatalogInventory\Api\StockIndexInterface;
1515
use Magento\CatalogInventory\Model\Spi\StockRegistryProviderInterface;
16-
use Magento\CatalogInventory\Model\Spi\StockResolverInterface;
1716
use Magento\Catalog\Api\ProductRepositoryInterface;
1817

1918
/**
@@ -56,31 +55,22 @@ class StockIndex implements StockIndexInterface
5655
*/
5756
protected $productTypes = [];
5857

59-
60-
/**
61-
* @var StockResolverInterface
62-
*/
63-
protected $stockResolver;
64-
6558
/**
6659
* @param StockRegistryProviderInterface $stockRegistryProvider
6760
* @param ProductRepositoryInterface $productRepository
6861
* @param ProductWebsite $productWebsite
6962
* @param ProductType $productType
70-
* @param StockResolverInterface $stockResolver
7163
*/
7264
public function __construct(
7365
StockRegistryProviderInterface $stockRegistryProvider,
7466
ProductRepositoryInterface $productRepository,
7567
ProductWebsite $productWebsite,
76-
ProductType $productType,
77-
StockResolverInterface $stockResolver
68+
ProductType $productType
7869
) {
7970
$this->stockRegistryProvider = $stockRegistryProvider;
8071
$this->productRepository = $productRepository;
8172
$this->productWebsite = $productWebsite;
8273
$this->productType = $productType;
83-
$this->stockResolver = $stockResolver;
8474
}
8575

8676
/**
@@ -122,8 +112,7 @@ public function rebuild($productId = null, $scopeId = null)
122112
*/
123113
public function updateProductStockStatus($productId, $websiteId)
124114
{
125-
$stockId = $this->stockResolver->getStockId($productId, $websiteId);
126-
$item = $this->stockRegistryProvider->getStockItem($productId, $stockId);
115+
$item = $this->stockRegistryProvider->getStockItem($productId, $websiteId);
127116

128117
$status = \Magento\CatalogInventory\Model\Stock\Status::STATUS_IN_STOCK;
129118
$qty = 0;
@@ -242,8 +231,7 @@ protected function processParents($productId, $websiteId)
242231
}
243232

244233
foreach ($parentIds as $parentId) {
245-
$stockId = $this->stockResolver->getStockId($productId, $websiteId);
246-
$item = $this->stockRegistryProvider->getStockItem($parentId, $stockId);
234+
$item = $this->stockRegistryProvider->getStockItem($parentId, $websiteId);
247235
$status = \Magento\CatalogInventory\Model\Stock\Status::STATUS_IN_STOCK;
248236
$qty = 0;
249237
if ($item->getItemId()) {

app/code/Magento/CatalogInventory/Model/StockManagement.php

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use Magento\CatalogInventory\Api\StockManagementInterface;
1111
use Magento\CatalogInventory\Model\ResourceModel\QtyCounterInterface;
1212
use Magento\CatalogInventory\Model\Spi\StockRegistryProviderInterface;
13-
use Magento\CatalogInventory\Model\Spi\StockResolverInterface;
1413
use Magento\Catalog\Api\ProductRepositoryInterface;
1514
use Magento\CatalogInventory\Model\ResourceModel\Stock as ResourceStock;
1615

@@ -49,36 +48,28 @@ class StockManagement implements StockManagementInterface
4948
*/
5049
private $qtyCounter;
5150

52-
/**
53-
* @var StockResolverInterface
54-
*/
55-
protected $stockResolver;
56-
5751
/**
5852
* @param ResourceStock $stockResource
5953
* @param StockRegistryProviderInterface $stockRegistryProvider
6054
* @param StockState $stockState
6155
* @param StockConfigurationInterface $stockConfiguration
6256
* @param ProductRepositoryInterface $productRepository
6357
* @param QtyCounterInterface $qtyCounter
64-
* @param StockResolverInterface $stockResolver
6558
*/
6659
public function __construct(
6760
ResourceStock $stockResource,
6861
StockRegistryProviderInterface $stockRegistryProvider,
6962
StockState $stockState,
7063
StockConfigurationInterface $stockConfiguration,
7164
ProductRepositoryInterface $productRepository,
72-
QtyCounterInterface $qtyCounter,
73-
StockResolverInterface $stockResolver
65+
QtyCounterInterface $qtyCounter
7466
) {
7567
$this->stockRegistryProvider = $stockRegistryProvider;
7668
$this->stockState = $stockState;
7769
$this->stockConfiguration = $stockConfiguration;
7870
$this->productRepository = $productRepository;
7971
$this->qtyCounter = $qtyCounter;
8072
$this->resource = $stockResource;
81-
$this->stockResolver = $stockResolver;
8273
}
8374

8475
/**
@@ -93,18 +84,17 @@ public function __construct(
9384
*/
9485
public function registerProductsSale($items, $websiteId = null)
9586
{
96-
if (!$websiteId) {
97-
$websiteId = $this->stockConfiguration->getDefaultScopeId();
98-
}
87+
//if (!$websiteId) {
88+
$websiteId = $this->stockConfiguration->getDefaultScopeId();
89+
//}
9990
$this->getResource()->beginTransaction();
10091
$lockedItems = $this->getResource()->lockProductsStock(array_keys($items), $websiteId);
10192
$fullSaveItems = $registeredItems = [];
10293
foreach ($lockedItems as $lockedItemRecord) {
10394
$productId = $lockedItemRecord['product_id'];
10495
/** @var StockItemInterface $stockItem */
10596
$orderedQty = $items[$productId];
106-
$stockId = $this->stockResolver->getStockId($productId, $websiteId);
107-
$stockItem = $this->stockRegistryProvider->getStockItem($productId, $stockId);
97+
$stockItem = $this->stockRegistryProvider->getStockItem($productId, $websiteId);
10898
$canSubtractQty = $stockItem->getItemId() && $this->canSubtractQty($stockItem);
10999
if (!$canSubtractQty || !$this->stockConfiguration->isQty($lockedItemRecord['type_id'])) {
110100
continue;
@@ -142,9 +132,9 @@ public function registerProductsSale($items, $websiteId = null)
142132
*/
143133
public function revertProductsSale($items, $websiteId = null)
144134
{
145-
if (!$websiteId) {
146-
$websiteId = $this->stockConfiguration->getDefaultScopeId();
147-
}
135+
//if (!$websiteId) {
136+
$websiteId = $this->stockConfiguration->getDefaultScopeId();
137+
//}
148138
$this->qtyCounter->correctItemsQty($items, $websiteId, '+');
149139
return true;
150140
}
@@ -159,11 +149,10 @@ public function revertProductsSale($items, $websiteId = null)
159149
*/
160150
public function backItemQty($productId, $qty, $scopeId = null)
161151
{
162-
if (!$scopeId) {
163-
$scopeId = $this->stockConfiguration->getDefaultScopeId();
164-
}
165-
$stockId = $this->stockResolver->getStockId($productId, $scopeId);
166-
$stockItem = $this->stockRegistryProvider->getStockItem($productId, $stockId);
152+
//if (!$scopeId) {
153+
$scopeId = $this->stockConfiguration->getDefaultScopeId();
154+
//}
155+
$stockItem = $this->stockRegistryProvider->getStockItem($productId, $scopeId);
167156
if ($stockItem->getItemId() && $this->stockConfiguration->isQty($this->getProductType($productId))) {
168157
if ($this->canSubtractQty($stockItem)) {
169158
$stockItem->setQty($stockItem->getQty() + $qty);

0 commit comments

Comments
 (0)