Skip to content

Commit

Permalink
Inventory Configuration modularity
Browse files Browse the repository at this point in the history
  • Loading branch information
seruymt committed May 14, 2018
1 parent 55dde2e commit 3562475
Show file tree
Hide file tree
Showing 32 changed files with 147 additions and 144 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@
*/
declare(strict_types=1);

namespace Magento\InventoryBundle\Plugin\InventoryConfiguration\IsSourceItemsAllowedForProductType;
namespace Magento\InventoryBundle\Plugin\InventoryConfiguration\IsSourceItemManagementAllowedForProductType;

use Magento\Bundle\Model\Product\Type as BundleType;
use Magento\InventoryConfiguration\Model\IsSourceItemsAllowedForProductTypeInterface;
use Magento\InventoryConfigurationApi\Model\IsSourceItemManagementAllowedForProductTypeInterface;

/**
* Disable Source items management for Bundle product type.
*/
class DisableBundleTypePlugin
{
/**
* @param IsSourceItemsAllowedForProductType $subject
* @param IsSourceItemManagementAllowedForProductTypeInterface $subject
* @param callable $proceed
* @param string $productType
* @return bool
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function aroundExecute(
IsSourceItemsAllowedForProductTypeInterface $subject,
IsSourceItemManagementAllowedForProductTypeInterface $subject,
callable $proceed,
string $productType
): bool {
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/InventoryBundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"magento/module-bundle": "*"
},
"suggest": {
"magento/module-inventory-configuration": "*"
"magento/module-inventory-configuration-api": "*"
},
"type": "magento2-module",
"license": [
Expand Down
4 changes: 2 additions & 2 deletions app/code/Magento/InventoryBundle/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\InventoryConfiguration\Model\IsSourceItemsAllowedForProductTypeInterface">
<type name="Magento\InventoryConfigurationApi\Model\IsSourceItemManagementAllowedForProductTypeInterface">
<plugin name="disable_bundle_type"
type="Magento\InventoryBundle\Plugin\InventoryConfiguration\IsSourceItemsAllowedForProductType\DisableBundleTypePlugin"/>
type="Magento\InventoryBundle\Plugin\InventoryConfiguration\IsSourceItemManagementAllowedForProductType\DisableBundleTypePlugin"/>
</type>
</config>
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use Magento\InventoryCatalogApi\Model\GetProductTypesBySkusInterface;
use Magento\InventoryCatalogApi\Model\GetSkusByProductIdsInterface;
use Magento\InventoryCatalog\Model\UpdateSourceItemBasedOnLegacyStockItem;
use Magento\InventoryConfiguration\Model\IsSourceItemsAllowedForProductTypeInterface;
use Magento\InventoryConfigurationApi\Model\IsSourceItemManagementAllowedForProductTypeInterface;

/**
* Class provides around Plugin on \Magento\CatalogInventory\Model\ResourceModel\Stock\Item::save
Expand All @@ -28,9 +28,9 @@ class UpdateSourceItemAtLegacyStockItemSavePlugin
private $resourceConnection;

/**
* @var IsSourceItemsAllowedForProductTypeInterface
* @var IsSourceItemManagementAllowedForProductTypeInterface
*/
private $isSourceItemsAllowedForProductType;
private $isSourceItemManagementAllowedForProductType;

/**
* @var UpdateSourceItemBasedOnLegacyStockItem
Expand All @@ -50,20 +50,20 @@ class UpdateSourceItemAtLegacyStockItemSavePlugin
/**
* @param UpdateSourceItemBasedOnLegacyStockItem $updateSourceItemBasedOnLegacyStockItem
* @param ResourceConnection $resourceConnection
* @param IsSourceItemsAllowedForProductTypeInterface $isSourceItemsAllowedForProductType
* @param IsSourceItemManagementAllowedForProductTypeInterface $isSourceItemManagementAllowedForProductType
* @param GetProductTypesBySkusInterface $getProductTypeBySku
* @param GetSkusByProductIdsInterface $getSkusByProductIds
*/
public function __construct(
UpdateSourceItemBasedOnLegacyStockItem $updateSourceItemBasedOnLegacyStockItem,
ResourceConnection $resourceConnection,
IsSourceItemsAllowedForProductTypeInterface $isSourceItemsAllowedForProductType,
IsSourceItemManagementAllowedForProductTypeInterface $isSourceItemManagementAllowedForProductType,
GetProductTypesBySkusInterface $getProductTypeBySku,
GetSkusByProductIdsInterface $getSkusByProductIds
) {
$this->updateSourceItemBasedOnLegacyStockItem = $updateSourceItemBasedOnLegacyStockItem;
$this->resourceConnection = $resourceConnection;
$this->isSourceItemsAllowedForProductType = $isSourceItemsAllowedForProductType;
$this->isSourceItemManagementAllowedForProductType = $isSourceItemManagementAllowedForProductType;
$this->getProductTypeBySku = $getProductTypeBySku;
$this->getSkusByProductIds = $getSkusByProductIds;
}
Expand All @@ -86,7 +86,7 @@ public function aroundSave(ItemResourceModel $subject, callable $proceed, Abstra
$proceed($legacyStockItem);

$typeId = $this->getTypeId($legacyStockItem);
if ($this->isSourceItemsAllowedForProductType->execute($typeId)) {
if ($this->isSourceItemManagementAllowedForProductType->execute($typeId)) {
$this->updateSourceItemBasedOnLegacyStockItem->execute($legacyStockItem);
}

Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/InventoryCatalog/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"magento/module-inventory-api": "*",
"magento/module-inventory-catalog-api": "*",
"magento/module-store": "*",
"magento/module-inventory-configuration": "*",
"magento/module-inventory-configuration-api": "*",
"magento/module-inventory-indexer": "*",
"magento/module-inventory-sales-api": "*"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use Magento\InventoryApi\Api\SourceItemRepositoryInterface;
use Magento\InventoryCatalogApi\Api\DefaultSourceProviderInterface;
use Magento\InventoryCatalogApi\Model\IsSingleSourceModeInterface;
use Magento\InventoryConfiguration\Model\IsSourceItemsAllowedForProductTypeInterface;
use Magento\InventoryConfigurationApi\Model\IsSourceItemManagementAllowedForProductTypeInterface;

/**
* Save source product relations during product persistence via controller
Expand All @@ -29,9 +29,9 @@
class ProcessSourceItemsObserver implements ObserverInterface
{
/**
* @var IsSourceItemsAllowedForProductTypeInterface
* @var IsSourceItemManagementAllowedForProductTypeInterface
*/
private $isSourceItemsAllowedForProductType;
private $isSourceItemManagementAllowedForProductType;

/**
* @var SourceItemsProcessor
Expand Down Expand Up @@ -59,22 +59,22 @@ class ProcessSourceItemsObserver implements ObserverInterface
private $sourceItemRepository;

/**
* @param IsSourceItemsAllowedForProductTypeInterface $isSourceItemsAllowedForProductType
* @param IsSourceItemManagementAllowedForProductTypeInterface $isSourceItemManagementAllowedForProductType
* @param SourceItemsProcessor $sourceItemsProcessor
* @param IsSingleSourceModeInterface $isSingleSourceMode
* @param DefaultSourceProviderInterface $defaultSourceProvider
* @param SearchCriteriaBuilderFactory $searchCriteriaBuilderFactory
* @param SourceItemRepositoryInterface $sourceItemRepository
*/
public function __construct(
IsSourceItemsAllowedForProductTypeInterface $isSourceItemsAllowedForProductType,
IsSourceItemManagementAllowedForProductTypeInterface $isSourceItemManagementAllowedForProductType,
SourceItemsProcessor $sourceItemsProcessor,
IsSingleSourceModeInterface $isSingleSourceMode,
DefaultSourceProviderInterface $defaultSourceProvider,
SearchCriteriaBuilderFactory $searchCriteriaBuilderFactory,
SourceItemRepositoryInterface $sourceItemRepository
) {
$this->isSourceItemsAllowedForProductType = $isSourceItemsAllowedForProductType;
$this->isSourceItemManagementAllowedForProductType = $isSourceItemManagementAllowedForProductType;
$this->sourceItemsProcessor = $sourceItemsProcessor;
$this->isSingleSourceMode = $isSingleSourceMode;
$this->defaultSourceProvider = $defaultSourceProvider;
Expand All @@ -92,7 +92,7 @@ public function execute(EventObserver $observer)
{
/** @var ProductInterface $product */
$product = $observer->getEvent()->getProduct();
if ($this->isSourceItemsAllowedForProductType->execute($product->getTypeId()) === false) {
if ($this->isSourceItemManagementAllowedForProductType->execute($product->getTypeId()) === false) {
return;
}
/** @var Save $controller */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AbstractModifier;
use Magento\Framework\Stdlib\ArrayManager;
use Magento\InventoryCatalogApi\Model\IsSingleSourceModeInterface;
use Magento\InventoryConfiguration\Model\IsSourceItemsAllowedForProductTypeInterface;
use Magento\InventoryConfigurationApi\Model\IsSourceItemManagementAllowedForProductTypeInterface;

/**
* Quantity modifier on CatalogInventory Product Editing Form
Expand All @@ -34,27 +34,27 @@ class Quantity extends AbstractModifier
private $locator;

/**
* @var IsSourceItemsAllowedForProductTypeInterface
* @var IsSourceItemManagementAllowedForProductTypeInterface
*/
private $isSourceItemsAllowedForProductType;
private $isSourceItemManagementAllowedForProductType;

/**
* CatalogInventory constructor.
* @param ArrayManager $arrayManager
* @param IsSingleSourceModeInterface $isSingleSourceMode
* @param LocatorInterface $locator
* @param IsSourceItemsAllowedForProductTypeInterface $isSourceItemsAllowedForProductType
* @param IsSourceItemManagementAllowedForProductTypeInterface $isSourceItemManagementAllowedForProductType
*/
public function __construct(
ArrayManager $arrayManager,
IsSingleSourceModeInterface $isSingleSourceMode,
LocatorInterface $locator,
IsSourceItemsAllowedForProductTypeInterface $isSourceItemsAllowedForProductType
IsSourceItemManagementAllowedForProductTypeInterface $isSourceItemManagementAllowedForProductType
) {
$this->arrayManager = $arrayManager;
$this->isSingleSourceMode = $isSingleSourceMode;
$this->locator = $locator;
$this->isSourceItemsAllowedForProductType = $isSourceItemsAllowedForProductType;
$this->isSourceItemManagementAllowedForProductType = $isSourceItemManagementAllowedForProductType;
}

/**
Expand All @@ -78,7 +78,7 @@ public function modifyMeta(array $meta)

$product = $this->locator->getProduct();

if ($this->isSourceItemsAllowedForProductType->execute($product->getTypeId()) === false) {
if ($this->isSourceItemManagementAllowedForProductType->execute($product->getTypeId()) === false) {
return $meta;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@
use Magento\InventoryApi\Api\Data\SourceItemInterface;
use Magento\InventoryCatalogAdminUi\Model\CanManageSourceItemsBySku;
use Magento\InventoryCatalogApi\Model\IsSingleSourceModeInterface;
use Magento\InventoryConfiguration\Model\IsSourceItemsAllowedForProductTypeInterface;
use Magento\InventoryConfigurationApi\Model\IsSourceItemManagementAllowedForProductTypeInterface;

/**
* Product form modifier. Add to form source data
*/
class SourceItems extends AbstractModifier
{
/**
* @var IsSourceItemsAllowedForProductTypeInterface
* @var IsSourceItemManagementAllowedForProductTypeInterface
*/
private $isSourceItemsAllowedForProductType;
private $isSourceItemManagementAllowedForProductType;

/**
* @var IsSingleSourceModeInterface
Expand Down Expand Up @@ -55,22 +55,22 @@ class SourceItems extends AbstractModifier
private $canManageSourceItemsBySku;

/**
* @param IsSourceItemsAllowedForProductTypeInterface $isSourceItemsAllowedForProductType
* @param IsSourceItemManagementAllowedForProductTypeInterface $isSourceItemManagementAllowedForProductType
* @param IsSingleSourceModeInterface $isSingleSourceMode
* @param LocatorInterface $locator
* @param CollectionFactory $sourceItemCollectionFactory
* @param ResourceConnection $resourceConnection
* @param CanManageSourceItemsBySku $canManageSourceItemsBySku
*/
public function __construct(
IsSourceItemsAllowedForProductTypeInterface $isSourceItemsAllowedForProductType,
IsSourceItemManagementAllowedForProductTypeInterface $isSourceItemManagementAllowedForProductType,
IsSingleSourceModeInterface $isSingleSourceMode,
LocatorInterface $locator,
CollectionFactory $sourceItemCollectionFactory,
ResourceConnection $resourceConnection,
CanManageSourceItemsBySku $canManageSourceItemsBySku
) {
$this->isSourceItemsAllowedForProductType = $isSourceItemsAllowedForProductType;
$this->isSourceItemManagementAllowedForProductType = $isSourceItemManagementAllowedForProductType;
$this->isSingleSourceMode = $isSingleSourceMode;
$this->locator = $locator;
$this->sourceItemCollectionFactory = $sourceItemCollectionFactory;
Expand All @@ -86,7 +86,7 @@ public function modifyData(array $data)
$product = $this->locator->getProduct();

if ($this->isSingleSourceMode->execute() === true
|| $this->isSourceItemsAllowedForProductType->execute($product->getTypeId()) === false
|| $this->isSourceItemManagementAllowedForProductType->execute($product->getTypeId()) === false
|| null === $product->getId()
) {
return $data;
Expand Down Expand Up @@ -135,7 +135,7 @@ public function modifyMeta(array $meta)
$product = $this->locator->getProduct();

if ($this->isSingleSourceMode->execute() === true
|| $this->isSourceItemsAllowedForProductType->execute($product->getTypeId()) === false) {
|| $this->isSourceItemManagementAllowedForProductType->execute($product->getTypeId()) === false) {
return $meta;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AbstractModifier;
use Magento\Framework\Stdlib\ArrayManager;
use Magento\InventoryCatalogApi\Model\IsSingleSourceModeInterface;
use Magento\InventoryConfiguration\Model\IsSourceItemsAllowedForProductTypeInterface;
use Magento\InventoryConfigurationApi\Model\IsSourceItemManagementAllowedForProductTypeInterface;

/**
* StockStatus modifier on CatalogInventory Product Editing Form
Expand All @@ -34,27 +34,27 @@ class StockStatus extends AbstractModifier
private $locator;

/**
* @var IsSourceItemsAllowedForProductTypeInterface
* @var IsSourceItemManagementAllowedForProductTypeInterface
*/
private $isSourceItemsAllowedForProductType;
private $isSourceItemManagementAllowedForProductType;

/**
* CatalogInventory constructor.
* @param ArrayManager $arrayManager
* @param IsSingleSourceModeInterface $isSingleSourceMode
* @param LocatorInterface $locator
* @param IsSourceItemsAllowedForProductTypeInterface $isSourceItemsAllowedForProductType
* @param IsSourceItemManagementAllowedForProductTypeInterface $isSourceItemManagementAllowedForProductType
*/
public function __construct(
ArrayManager $arrayManager,
IsSingleSourceModeInterface $isSingleSourceMode,
LocatorInterface $locator,
IsSourceItemsAllowedForProductTypeInterface $isSourceItemsAllowedForProductType
IsSourceItemManagementAllowedForProductTypeInterface $isSourceItemManagementAllowedForProductType
) {
$this->arrayManager = $arrayManager;
$this->isSingleSourceMode = $isSingleSourceMode;
$this->locator = $locator;
$this->isSourceItemsAllowedForProductType = $isSourceItemsAllowedForProductType;
$this->isSourceItemManagementAllowedForProductType = $isSourceItemManagementAllowedForProductType;
}

/**
Expand All @@ -78,7 +78,7 @@ public function modifyMeta(array $meta)

$product = $this->locator->getProduct();

if ($this->isSourceItemsAllowedForProductType->execute($product->getTypeId()) === false) {
if ($this->isSourceItemManagementAllowedForProductType->execute($product->getTypeId()) === false) {
return $meta;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use Magento\Inventory\Model\SourceItem\Command\GetSourceItemsBySkuInterface;
use Magento\InventoryApi\Api\SourceRepositoryInterface;
use Magento\InventoryCatalogApi\Model\IsSingleSourceModeInterface;
use Magento\InventoryConfiguration\Model\IsSourceItemsAllowedForProductTypeInterface;
use Magento\InventoryConfigurationApi\Model\IsSourceItemManagementAllowedForProductTypeInterface;
use Magento\Ui\Component\Form\Element\DataType\Text;
use Magento\Ui\Component\Listing\Columns\Column;

Expand All @@ -27,9 +27,9 @@ class QuantityPerSource extends AbstractModifier
private $isSingleSourceMode;

/**
* @var IsSourceItemsAllowedForProductTypeInterface
* @var IsSourceItemManagementAllowedForProductTypeInterface
*/
private $isSourceItemsAllowedForProductType;
private $isSourceItemManagementAllowedForProductType;

/**
* @var SourceRepositoryInterface
Expand All @@ -43,18 +43,18 @@ class QuantityPerSource extends AbstractModifier

/**
* @param IsSingleSourceModeInterface $isSingleSourceMode
* @param IsSourceItemsAllowedForProductTypeInterface $isSourceItemsAllowedForProductType
* @param IsSourceItemManagementAllowedForProductTypeInterface $isSourceItemManagementAllowedForProductType
* @param SourceRepositoryInterface $sourceRepository
* @param GetSourceItemsBySkuInterface $getSourceItemsBySku
*/
public function __construct(
IsSingleSourceModeInterface $isSingleSourceMode,
IsSourceItemsAllowedForProductTypeInterface $isSourceItemsAllowedForProductType,
IsSourceItemManagementAllowedForProductTypeInterface $isSourceItemManagementAllowedForProductType,
SourceRepositoryInterface $sourceRepository,
GetSourceItemsBySkuInterface $getSourceItemsBySku
) {
$this->isSingleSourceMode = $isSingleSourceMode;
$this->isSourceItemsAllowedForProductType = $isSourceItemsAllowedForProductType;
$this->isSourceItemManagementAllowedForProductType = $isSourceItemManagementAllowedForProductType;
$this->sourceRepository = $sourceRepository;
$this->getSourceItemsBySku = $getSourceItemsBySku;
}
Expand All @@ -69,9 +69,9 @@ public function modifyData(array $data)
}

foreach ($data['items'] as &$item) {
$item['quantity_per_source'] = $this->isSourceItemsAllowedForProductType->execute($item['type_id']) === true
? $this->getSourceItemsData($item['sku'])
: [];
$item['quantity_per_source'] = $this->isSourceItemManagementAllowedForProductType->execute(
$item['type_id']
) === true ? $this->getSourceItemsData($item['sku']) : [];
}
unset($item);

Expand Down
Loading

0 comments on commit 3562475

Please sign in to comment.