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#1347 from DaniloEmpire/issue-717
Fix for issue magento#717
- Loading branch information
Showing
2 changed files
with
109 additions
and
1 deletion.
There are no files selected for viewing
91 changes: 91 additions & 0 deletions
91
...gento/InventorySales/Model/IsProductSalableCondition/BackOrderNotifyCustomerCondition.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,91 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\InventorySales\Model\IsProductSalableCondition; | ||
|
||
use Magento\InventoryConfigurationApi\Api\Data\StockItemConfigurationInterface; | ||
use Magento\InventoryConfigurationApi\Api\GetStockItemConfigurationInterface; | ||
use Magento\InventorySalesApi\Api\Data\ProductSalabilityErrorInterfaceFactory; | ||
use Magento\InventorySalesApi\Api\Data\ProductSalableResultInterface; | ||
use Magento\InventorySalesApi\Api\Data\ProductSalableResultInterfaceFactory; | ||
use Magento\InventorySalesApi\Api\IsProductSalableForRequestedQtyInterface; | ||
use Magento\InventorySalesApi\Model\GetStockItemDataInterface; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
class BackOrderNotifyCustomerCondition implements IsProductSalableForRequestedQtyInterface | ||
{ | ||
/** | ||
* @var GetStockItemConfigurationInterface | ||
*/ | ||
private $getStockItemConfiguration; | ||
|
||
/** | ||
* @var GetStockItemDataInterface | ||
*/ | ||
private $getStockItemData; | ||
|
||
/** | ||
* @var ProductSalableResultInterfaceFactory | ||
*/ | ||
private $productSalableResultFactory; | ||
|
||
/** | ||
* @var ProductSalabilityErrorInterfaceFactory | ||
*/ | ||
private $productSalabilityErrorFactory; | ||
|
||
/** | ||
* @param GetStockItemConfigurationInterface $getStockItemConfiguration | ||
*/ | ||
public function __construct( | ||
GetStockItemConfigurationInterface $getStockItemConfiguration, | ||
GetStockItemDataInterface $getStockItemData, | ||
ProductSalableResultInterfaceFactory $productSalableResultFactory, | ||
ProductSalabilityErrorInterfaceFactory $productSalabilityErrorFactory | ||
) { | ||
$this->getStockItemConfiguration = $getStockItemConfiguration; | ||
$this->getStockItemData = $getStockItemData; | ||
$this->productSalableResultFactory = $productSalableResultFactory; | ||
$this->productSalabilityErrorFactory = $productSalabilityErrorFactory; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function execute(string $sku, int $stockId, float $requestedQty): ProductSalableResultInterface | ||
{ | ||
$stockItemConfiguration = $this->getStockItemConfiguration->execute($sku, $stockId); | ||
if (null === $stockItemConfiguration) { | ||
$this->productSalableResultFactory->create(['errors' => []]); | ||
} | ||
|
||
if ($stockItemConfiguration->getBackorders() === StockItemConfigurationInterface::BACKORDERS_YES_NOTIFY) { | ||
$stockItemData = $this->getStockItemData->execute($sku, $stockId); | ||
if (null === $stockItemData) { | ||
$this->productSalableResultFactory->create(['errors' => []]); | ||
} | ||
|
||
$backOrderQty = $requestedQty - $stockItemData[GetStockItemDataInterface::QUANTITY]; | ||
if ($backOrderQty > 0) { | ||
$errors = [ | ||
$this->productSalabilityErrorFactory->create([ | ||
'code' => 'back_order-not-enough', | ||
'message' => __( | ||
'We don\'t have as many quantity as you requested, ' | ||
. 'but we\'ll back order the remaining %1.', | ||
$backOrderQty * 1 | ||
)]) | ||
]; | ||
return $this->productSalableResultFactory->create(['errors' => $errors]); | ||
} | ||
} | ||
|
||
return $this->productSalableResultFactory->create(['errors' => []]); | ||
} | ||
} |
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