Skip to content

Commit

Permalink
Merge pull request magento#995 from magento-engcom/MSI-920-bis
Browse files Browse the repository at this point in the history
Msi 920 bis
  • Loading branch information
maghamed authored Apr 22, 2018
2 parents efe6aa8 + a41b117 commit e82ab95
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 28 deletions.
13 changes: 11 additions & 2 deletions app/code/Magento/InventorySales/Model/CheckItemsQuantity.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace Magento\InventorySales\Model;

use Magento\Framework\Exception\LocalizedException;
use Magento\InventoryCatalog\Model\GetProductTypesBySkusInterface;
use Magento\InventorySalesApi\Api\IsProductSalableForRequestedQtyInterface;
use Magento\InventoryConfiguration\Model\IsSourceItemsAllowedForProductTypeInterface;
use Magento\InventorySalesApi\Api\Data\ProductSalableResultInterface;
Expand All @@ -31,6 +32,11 @@ class CheckItemsQuantity
*/
private $defaultStockProvider;

/**
* @var GetProductTypesBySkusInterface
*/
private $getProductTypesBySkus;

/**
* @param IsSourceItemsAllowedForProductTypeInterface $isSourceItemsAllowedForProductType
* @param IsProductSalableForRequestedQtyInterface $isProductSalableForRequestedQty
Expand All @@ -39,11 +45,13 @@ class CheckItemsQuantity
public function __construct(
IsSourceItemsAllowedForProductTypeInterface $isSourceItemsAllowedForProductType,
IsProductSalableForRequestedQtyInterface $isProductSalableForRequestedQty,
DefaultStockProviderInterface $defaultStockProvider
DefaultStockProviderInterface $defaultStockProvider,
GetProductTypesBySkusInterface $getProductTypesBySkus
) {
$this->isSourceItemsAllowedForProductType = $isSourceItemsAllowedForProductType;
$this->isProductSalableForRequestedQty = $isProductSalableForRequestedQty;
$this->defaultStockProvider = $defaultStockProvider;
$this->getProductTypesBySkus = $getProductTypesBySkus;
}

/**
Expand All @@ -55,8 +63,9 @@ public function __construct(
* @return void
* @throws LocalizedException
*/
public function execute(array $items, array $productTypes, int $stockId) : void
public function execute(array $items, int $stockId) : void
{
$productTypes = $this->getProductTypesBySkus->execute(array_keys($items));
foreach ($items as $sku => $qty) {
if (false === $this->isSourceItemsAllowedForProductType->execute($productTypes[$sku])) {
$defaultStockId = $this->defaultStockProvider->getId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Magento\InventoryCatalog\Model\GetSkusByProductIdsInterface;
use Magento\Store\Api\WebsiteRepositoryInterface;
use Magento\InventorySalesApi\Api\StockResolverInterface;
use Magento\InventoryCatalog\Model\GetProductTypesBySkusInterface;
use Magento\InventorySalesApi\Api\Data\SalesChannelInterface;
use Magento\InventorySales\Model\CheckItemsQuantity;

Expand All @@ -36,11 +35,6 @@ class ProcessRegisterProductsSalePlugin
*/
private $stockResolver;

/*
* @var GetProductTypesBySkusInterface
*/
private $getProductTypesBySkus;

/**
* @var CheckItemsQuantity
*/
Expand All @@ -50,20 +44,17 @@ class ProcessRegisterProductsSalePlugin
* @param GetSkusByProductIdsInterface $getSkusByProductIds
* @param WebsiteRepositoryInterface $websiteRepository
* @param StockResolverInterface $stockResolver
* @param GetProductTypesBySkusInterface $getProductTypesBySkus
* @param CheckItemsQuantity $checkItemsQuantity
*/
public function __construct(
GetSkusByProductIdsInterface $getSkusByProductIds,
WebsiteRepositoryInterface $websiteRepository,
StockResolverInterface $stockResolver,
GetProductTypesBySkusInterface $getProductTypesBySkus,
CheckItemsQuantity $checkItemsQuantity
) {
$this->getSkusByProductIds = $getSkusByProductIds;
$this->websiteRepository = $websiteRepository;
$this->stockResolver = $stockResolver;
$this->getProductTypesBySkus = $getProductTypesBySkus;
$this->checkItemsQuantity = $checkItemsQuantity;
}

Expand Down Expand Up @@ -96,8 +87,7 @@ public function aroundRegisterProductsSale(
}
$websiteCode = $this->websiteRepository->getById($websiteId)->getCode();
$stockId = (int)$this->stockResolver->get(SalesChannelInterface::TYPE_WEBSITE, $websiteCode)->getStockId();
$productTypes = $this->getProductTypesBySkus->execute(array_keys($itemsBySku));
$this->checkItemsQuantity->execute($itemsBySku, $productTypes, $stockId);
$this->checkItemsQuantity->execute($itemsBySku, $stockId);
return [];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Magento\InventorySalesApi\Api\Data\SalesChannelInterfaceFactory;
use Magento\InventorySalesApi\Api\Data\SalesChannelInterface;
use Magento\InventorySalesApi\Api\Data\ItemToSellInterfaceFactory;
use Magento\InventoryCatalog\Model\GetProductTypesBySkusInterface;
use Magento\InventorySales\Model\CheckItemsQuantity;
use Magento\InventorySales\Model\StockByWebsiteIdResolver;

Expand Down Expand Up @@ -53,11 +52,6 @@ class AppendReservationsAfterOrderPlacementPlugin
*/
private $itemsToSellFactory;

/**
* @var GetProductTypesBySkusInterface
*/
private $getProductTypesBySkus;

/**
* @var CheckItemsQuantity
*/
Expand All @@ -75,7 +69,6 @@ class AppendReservationsAfterOrderPlacementPlugin
* @param SalesChannelInterfaceFactory $salesChannelFactory
* @param SalesEventInterfaceFactory $salesEventFactory
* @param ItemToSellInterfaceFactory $itemsToSellFactory
* @param GetProductTypesBySkusInterface $getProductTypesBySkus
* @param CheckItemsQuantity $checkItemsQuantity
* @param StockByWebsiteIdResolver $stockByWebsiteIdResolver
*/
Expand All @@ -86,7 +79,6 @@ public function __construct(
SalesChannelInterfaceFactory $salesChannelFactory,
SalesEventInterfaceFactory $salesEventFactory,
ItemToSellInterfaceFactory $itemsToSellFactory,
GetProductTypesBySkusInterface $getProductTypesBySkus,
CheckItemsQuantity $checkItemsQuantity,
StockByWebsiteIdResolver $stockByWebsiteIdResolver
) {
Expand All @@ -96,7 +88,6 @@ public function __construct(
$this->salesChannelFactory = $salesChannelFactory;
$this->salesEventFactory = $salesEventFactory;
$this->itemsToSellFactory = $itemsToSellFactory;
$this->getProductTypesBySkus = $getProductTypesBySkus;
$this->checkItemsQuantity = $checkItemsQuantity;
$this->stockByWebsiteIdResolver = $stockByWebsiteIdResolver;
}
Expand All @@ -109,12 +100,11 @@ public function __construct(
*/
public function afterPlace(OrderManagementInterface $subject, OrderInterface $order) : OrderInterface
{
$itemsById = $itemsBySku = $productTypes = $itemsToSell = [];
$itemsById = $itemsBySku = $itemsToSell = [];
foreach ($order->getItems() as $item) {
$itemsById[$item->getProductId()] = $item->getQtyOrdered();
}
$productSkus = $this->getSkusByProductIds->execute(array_keys($itemsById));
$productTypes = $this->getProductTypesBySkus->execute($productSkus);
foreach ($productSkus as $productId => $sku) {
$itemsBySku[$sku] = (float)$itemsById[$productId];
$itemsToSell[] = $this->itemsToSellFactory->create([
Expand All @@ -127,7 +117,7 @@ public function afterPlace(OrderManagementInterface $subject, OrderInterface $or
$websiteCode = $this->websiteRepository->getById($websiteId)->getCode();
$stockId = (int)$this->stockByWebsiteIdResolver->get((int)$websiteId)->getStockId();

$this->checkItemsQuantity->execute($itemsBySku, $productTypes, $stockId);
$this->checkItemsQuantity->execute($itemsBySku, $stockId);

/** @var SalesEventInterface $salesEvent */
$salesEvent = $this->salesEventFactory->create([
Expand Down
1 change: 0 additions & 1 deletion app/code/Magento/InventoryShipping/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"magento/module-inventory-catalog": "*",
"magento/module-inventory-source-selection-api": "*",
"magento/module-inventory-source-selection": "*",
"magento/module-inventory-reservations-api": "*",
"magento/module-sales": "*",
"magento/module-shipping": "*",
"magento/module-ui": "*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
/** @var Item $orderItem */
$orderItem2 = $objectManager->create(Item::class);
$orderItem2->setProductId($product->getId())
->setSku('simple2')
->setName('Simple product')
->setSku($product->getSku())
->setName($product->getName())
->setPrice(100)
->setQtyOrdered(2)
->setBasePrice($product->getPrice())
Expand Down

0 comments on commit e82ab95

Please sign in to comment.