forked from magento/magento2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request magento#559 from magento-engcom/451_assigned_sourc…
…es_disabled magento#451 disabled sources tab content on manage_stock update
- Loading branch information
Showing
5 changed files
with
147 additions
and
3 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
app/code/Magento/InventoryCatalog/Model/CanManageSourceItemsBySku.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\InventoryCatalog\Model; | ||
|
||
use Magento\CatalogInventory\Model\Configuration; | ||
use Magento\Framework\App\Config\ScopeConfigInterface; | ||
use Magento\InventoryCatalog\Api\DefaultStockProviderInterface; | ||
use Magento\InventoryConfigurationApi\Api\GetStockItemConfigurationInterface; | ||
|
||
/** | ||
* Check source items should be managed for given product sku | ||
*/ | ||
class CanManageSourceItemsBySku | ||
{ | ||
/** | ||
* Provides manage stock global config value. | ||
* | ||
* @var ScopeConfigInterface | ||
*/ | ||
private $config; | ||
|
||
/** | ||
* Provides default stock id for current website in order to get correct stock configuration for product. | ||
* | ||
* @var DefaultStockProviderInterface | ||
*/ | ||
private $defaultStockProvider; | ||
|
||
/** | ||
* Provides stock item configuration for given product sku. | ||
* | ||
* @var GetStockItemConfigurationInterface | ||
*/ | ||
private $getStockItemConfiguration; | ||
|
||
/** | ||
* @param ScopeConfigInterface $config | ||
* @param GetStockItemConfigurationInterface $getStockItemConfiguration | ||
* @param DefaultStockProviderInterface $defaultStockProvider | ||
*/ | ||
public function __construct( | ||
ScopeConfigInterface $config, | ||
GetStockItemConfigurationInterface $getStockItemConfiguration, | ||
DefaultStockProviderInterface $defaultStockProvider | ||
) { | ||
$this->config = $config; | ||
$this->defaultStockProvider = $defaultStockProvider; | ||
$this->getStockItemConfiguration = $getStockItemConfiguration; | ||
} | ||
|
||
/** | ||
* @param string $sku Sku can be null if product is new | ||
* @return bool | ||
*/ | ||
public function execute(string $sku = null): bool | ||
{ | ||
if (null !== $sku) { | ||
$stockId = $this->defaultStockProvider->getId(); | ||
$itemConfiguration = $this->getStockItemConfiguration->execute($sku, $stockId); | ||
|
||
if (null !== $itemConfiguration) { | ||
return $itemConfiguration->isUseConfigManageStock() | ||
? (bool)$this->config->getValue(Configuration::XML_PATH_MANAGE_STOCK) | ||
: $itemConfiguration->isManageStock(); | ||
} | ||
} | ||
return (bool)$this->config->getValue(Configuration::XML_PATH_MANAGE_STOCK); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...de/Magento/InventoryCatalog/view/adminhtml/web/js/product/form/components/source-items.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
define([ | ||
'Magento_Ui/js/form/components/fieldset' | ||
], function (Fieldset) { | ||
'use strict'; | ||
|
||
return Fieldset.extend({ | ||
defaults: { | ||
imports: { | ||
onStockChange: '${ $.provider }:data.product.stock_data.manage_stock' | ||
} | ||
}, | ||
|
||
/** | ||
* Disable all child elements if manage stock is zero | ||
* @param {Integer} canManageStock | ||
*/ | ||
onStockChange: function (canManageStock) { | ||
if (canManageStock === 0) { | ||
this.delegate('disabled', true); | ||
} | ||
} | ||
}); | ||
}); |