Skip to content

Commit

Permalink
Merge pull request magento#1242 from magento-engcom/MSI-1209
Browse files Browse the repository at this point in the history
MSI-1209: Cannot place order with configurable product on single stock mode
  • Loading branch information
Valeriy Nayda authored May 24, 2018
2 parents 6cb3243 + 0b256fd commit aa89995
Showing 1 changed file with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

namespace Magento\InventorySales\Plugin\Sales\OrderManagement;

use Magento\InventoryCatalogApi\Model\GetProductTypesBySkusInterface;
use Magento\InventoryConfigurationApi\Model\IsSourceItemManagementAllowedForProductTypeInterface;
use Magento\Sales\Api\Data\OrderInterface;
use Magento\Sales\Api\OrderManagementInterface;
use Magento\InventorySalesApi\Api\PlaceReservationsForSalesEventInterface;
Expand Down Expand Up @@ -62,6 +64,16 @@ class AppendReservationsAfterOrderPlacementPlugin
*/
private $stockByWebsiteIdResolver;

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

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

/**
* @param PlaceReservationsForSalesEventInterface $placeReservationsForSalesEvent
* @param GetSkusByProductIdsInterface $getSkusByProductIds
Expand All @@ -71,6 +83,8 @@ class AppendReservationsAfterOrderPlacementPlugin
* @param ItemToSellInterfaceFactory $itemsToSellFactory
* @param CheckItemsQuantity $checkItemsQuantity
* @param StockByWebsiteIdResolverInterface $stockByWebsiteIdResolver
* @param GetProductTypesBySkusInterface $getProductTypesBySkus
* @param IsSourceItemManagementAllowedForProductTypeInterface $isSourceItemManagementAllowedForProductType
*/
public function __construct(
PlaceReservationsForSalesEventInterface $placeReservationsForSalesEvent,
Expand All @@ -80,7 +94,9 @@ public function __construct(
SalesEventInterfaceFactory $salesEventFactory,
ItemToSellInterfaceFactory $itemsToSellFactory,
CheckItemsQuantity $checkItemsQuantity,
StockByWebsiteIdResolverInterface $stockByWebsiteIdResolver
StockByWebsiteIdResolverInterface $stockByWebsiteIdResolver,
GetProductTypesBySkusInterface $getProductTypesBySkus,
IsSourceItemManagementAllowedForProductTypeInterface $isSourceItemManagementAllowedForProductType
) {
$this->placeReservationsForSalesEvent = $placeReservationsForSalesEvent;
$this->getSkusByProductIds = $getSkusByProductIds;
Expand All @@ -90,6 +106,8 @@ public function __construct(
$this->itemsToSellFactory = $itemsToSellFactory;
$this->checkItemsQuantity = $checkItemsQuantity;
$this->stockByWebsiteIdResolver = $stockByWebsiteIdResolver;
$this->getProductTypesBySkus = $getProductTypesBySkus;
$this->isSourceItemManagementAllowedForProductType = $isSourceItemManagementAllowedForProductType;
}

/**
Expand All @@ -108,7 +126,13 @@ public function afterPlace(OrderManagementInterface $subject, OrderInterface $or
$itemsById[$item->getProductId()] += $item->getQtyOrdered();
}
$productSkus = $this->getSkusByProductIds->execute(array_keys($itemsById));
$productTypes = $this->getProductTypesBySkus->execute($productSkus);

foreach ($productSkus as $productId => $sku) {
if (false === $this->isSourceItemManagementAllowedForProductType->execute($productTypes[$sku])) {
continue;
}

$itemsBySku[$sku] = (float)$itemsById[$productId];
$itemsToSell[] = $this->itemsToSellFactory->create([
'sku' => $sku,
Expand Down

0 comments on commit aa89995

Please sign in to comment.