-
Notifications
You must be signed in to change notification settings - Fork 247
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 #1410 from magento-engcom/MSI-1250-Prevent-Disabli…
…ng-Default-Source-by-Disabling-Is-Enabled-Switcher 1250: added plugin to prevent disabling default source
- Loading branch information
Showing
5 changed files
with
109 additions
and
14 deletions.
There are no files selected for viewing
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
79 changes: 79 additions & 0 deletions
79
...talogAdminUi/Plugin/InventoryAdminUi/DataProvider/PreventDisablingDefaultSourcePlugin.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,79 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\InventoryCatalogAdminUi\Plugin\InventoryAdminUi\DataProvider; | ||
|
||
use Magento\Framework\App\RequestInterface; | ||
use Magento\InventoryApi\Api\Data\SourceItemInterface; | ||
use Magento\InventoryCatalogApi\Api\DefaultSourceProviderInterface; | ||
use Magento\InventoryAdminUi\Ui\DataProvider\SourceDataProvider; | ||
|
||
class PreventDisablingDefaultSourcePlugin | ||
{ | ||
/** | ||
* @var DefaultSourceProviderInterface | ||
*/ | ||
private $defaultSourceProvider; | ||
|
||
/** | ||
* @var RequestInterface | ||
*/ | ||
private $request; | ||
|
||
/** | ||
* @param DefaultSourceProviderInterface $defaultSourceProvider | ||
* @param RequestInterface $request | ||
*/ | ||
public function __construct( | ||
DefaultSourceProviderInterface $defaultSourceProvider, | ||
RequestInterface $request | ||
) { | ||
$this->defaultSourceProvider = $defaultSourceProvider; | ||
$this->request = $request; | ||
} | ||
|
||
/** | ||
* @param SourceDataProvider $subject | ||
* @param $meta | ||
* @return array | ||
*/ | ||
public function afterGetMeta( | ||
SourceDataProvider $subject, | ||
$meta | ||
): array { | ||
$isFormComponent = SourceDataProvider::SOURCE_FORM_NAME === $subject->getName(); | ||
if (!$isFormComponent || !$this->isDefaultSource()) { | ||
return $meta; | ||
} | ||
|
||
$meta['general'] = [ | ||
'children' => [ | ||
'enabled' => [ | ||
'arguments' => [ | ||
'data' => [ | ||
'config' => [ | ||
'disabled' => true, | ||
] | ||
] | ||
] | ||
] | ||
] | ||
]; | ||
|
||
return $meta; | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
private function isDefaultSource(): bool | ||
{ | ||
$defaultSourceCode = $this->defaultSourceProvider->getCode(); | ||
$currentSourceCode = $this->request->getParam(SourceItemInterface::SOURCE_CODE); | ||
return $defaultSourceCode === $currentSourceCode; | ||
} | ||
} |
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
16 changes: 16 additions & 0 deletions
16
...ode/Magento/InventoryCatalogAdminUi/view/adminhtml/ui_component/inventory_source_form.xml
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,16 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
--> | ||
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd"> | ||
<fieldset name="general"> | ||
<field name="enabled"> | ||
<settings> | ||
<notice translate="true">The Default Source must be enabled. A default source is required for single source merchants and product migration.</notice> | ||
</settings> | ||
</field> | ||
</fieldset> | ||
</form> |