Skip to content

Commit 1a0e59d

Browse files
author
Valeriy Nayda
committed
MSI-451: disabled sources tab content on manage_stock update
1 parent bfa15ba commit 1a0e59d

File tree

2 files changed

+18
-24
lines changed

2 files changed

+18
-24
lines changed
Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@
55
*/
66
declare(strict_types=1);
77

8-
namespace Magento\InventoryCatalog\Ui\DataProvider\Product\Form\Modifier\SourceItems;
8+
namespace Magento\InventoryCatalog\Model;
99

1010
use Magento\CatalogInventory\Model\Configuration;
1111
use Magento\Framework\App\Config\ScopeConfigInterface;
1212
use Magento\InventoryCatalog\Api\DefaultStockProviderInterface;
1313
use Magento\InventoryConfigurationApi\Api\GetStockItemConfigurationInterface;
1414

1515
/**
16-
* Check stock should be managed for given product sku.
16+
* Check source items should be managed for given product sku
1717
*/
18-
class ManageStock
18+
class CanManageSourceItemsBySku
1919
{
2020
/**
2121
* Provides manage stock global config value.
@@ -39,8 +39,6 @@ class ManageStock
3939
private $getStockItemConfiguration;
4040

4141
/**
42-
* ManageStock constructor.
43-
*
4442
* @param ScopeConfigInterface $config
4543
* @param GetStockItemConfigurationInterface $getStockItemConfiguration
4644
* @param DefaultStockProviderInterface $defaultStockProvider
@@ -56,24 +54,21 @@ public function __construct(
5654
}
5755

5856
/**
59-
* Check, if stock should be managed for give product.
60-
*
61-
* @param string $sku
57+
* @param string $sku Sku can be null if product is new
6258
* @return bool
63-
* @throws \Magento\Framework\Exception\LocalizedException
6459
*/
6560
public function execute(string $sku = null): bool
6661
{
67-
$stockId = $this->defaultStockProvider->getId();
68-
if ($sku) {
62+
if (null !== $sku) {
63+
$stockId = $this->defaultStockProvider->getId();
6964
$itemConfiguration = $this->getStockItemConfiguration->execute($sku, $stockId);
70-
if ($itemConfiguration) {
65+
66+
if (null !== $itemConfiguration) {
7167
return $itemConfiguration->isUseConfigManageStock()
7268
? (bool)$this->config->getValue(Configuration::XML_PATH_MANAGE_STOCK)
7369
: $itemConfiguration->isManageStock();
7470
}
7571
}
76-
7772
return (bool)$this->config->getValue(Configuration::XML_PATH_MANAGE_STOCK);
7873
}
7974
}

app/code/Magento/InventoryCatalog/Ui/DataProvider/Product/Form/Modifier/SourceItems.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
use Magento\Inventory\Model\ResourceModel\SourceItem\CollectionFactory;
1616
use Magento\InventoryApi\Api\Data\SourceInterface;
1717
use Magento\InventoryApi\Api\Data\SourceItemInterface;
18+
use Magento\InventoryCatalog\Model\CanManageSourceItemsBySku;
1819
use Magento\InventoryCatalog\Model\IsSingleSourceModeInterface;
19-
use Magento\InventoryCatalog\Ui\DataProvider\Product\Form\Modifier\SourceItems\ManageStock;
2020
use Magento\InventoryConfiguration\Model\IsSourceItemsAllowedForProductTypeInterface;
2121

2222
/**
@@ -50,34 +50,32 @@ class SourceItems extends AbstractModifier
5050
private $resourceConnection;
5151

5252
/**
53-
* Check, if stock should be managed for given product.
54-
*
55-
* @var ManageStock
53+
* @var CanManageSourceItemsBySku
5654
*/
57-
private $manageStock;
55+
private $canManageSourceItemsBySku;
5856

5957
/**
6058
* @param IsSourceItemsAllowedForProductTypeInterface $isSourceItemsAllowedForProductType
6159
* @param IsSingleSourceModeInterface $isSingleSourceMode
6260
* @param LocatorInterface $locator
6361
* @param CollectionFactory $sourceItemCollectionFactory
6462
* @param ResourceConnection $resourceConnection
65-
* @param ManageStock $manageStock
63+
* @param CanManageSourceItemsBySku $canManageSourceItemsBySku
6664
*/
6765
public function __construct(
6866
IsSourceItemsAllowedForProductTypeInterface $isSourceItemsAllowedForProductType,
6967
IsSingleSourceModeInterface $isSingleSourceMode,
7068
LocatorInterface $locator,
7169
CollectionFactory $sourceItemCollectionFactory,
7270
ResourceConnection $resourceConnection,
73-
ManageStock $manageStock
71+
CanManageSourceItemsBySku $canManageSourceItemsBySku
7472
) {
7573
$this->isSourceItemsAllowedForProductType = $isSourceItemsAllowedForProductType;
7674
$this->isSingleSourceMode = $isSingleSourceMode;
7775
$this->locator = $locator;
7876
$this->sourceItemCollectionFactory = $sourceItemCollectionFactory;
7977
$this->resourceConnection = $resourceConnection;
80-
$this->manageStock = $manageStock;
78+
$this->canManageSourceItemsBySku = $canManageSourceItemsBySku;
8179
}
8280

8381
/**
@@ -138,7 +136,8 @@ public function modifyMeta(array $meta)
138136
|| $this->isSourceItemsAllowedForProductType->execute($product->getTypeId()) === false) {
139137
return $meta;
140138
}
141-
$isMangeStock = $this->manageStock->execute($product->getSku());
139+
140+
$canMangeSourceItems = $this->canManageSourceItemsBySku->execute($product->getSku());
142141
$meta['sources'] = [
143142
'arguments' => [
144143
'data' => [
@@ -154,7 +153,7 @@ public function modifyMeta(array $meta)
154153
'arguments' => [
155154
'data' => [
156155
'config' => [
157-
'visible' => $isMangeStock,
156+
'visible' => $canMangeSourceItems,
158157
],
159158
],
160159
],
@@ -165,7 +164,7 @@ public function modifyMeta(array $meta)
165164
'arguments' => [
166165
'data' => [
167166
'config' => [
168-
'visible' => $isMangeStock,
167+
'visible' => $canMangeSourceItems,
169168
],
170169
],
171170
],

0 commit comments

Comments
 (0)