Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions
BackOrderNotifyCustomerCondition Class Reference
Inheritance diagram for BackOrderNotifyCustomerCondition:
IsProductSalableForRequestedQtyInterface

Public Member Functions

 __construct (GetStockItemConfigurationInterface $getStockItemConfiguration, GetStockItemDataInterface $getStockItemData, ProductSalableResultInterfaceFactory $productSalableResultFactory, ProductSalabilityErrorInterfaceFactory $productSalabilityErrorFactory)
 
 execute (string $sku, int $stockId, float $requestedQty)
 

Detailed Description

Definition at line 21 of file BackOrderNotifyCustomerCondition.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( GetStockItemConfigurationInterface  $getStockItemConfiguration,
GetStockItemDataInterface  $getStockItemData,
ProductSalableResultInterfaceFactory  $productSalableResultFactory,
ProductSalabilityErrorInterfaceFactory  $productSalabilityErrorFactory 
)
Parameters
GetStockItemConfigurationInterface$getStockItemConfiguration
GetStockItemDataInterface$getStockItemData
ProductSalableResultInterfaceFactory$productSalableResultFactory
ProductSalabilityErrorInterfaceFactory$productSalabilityErrorFactory

Definition at line 49 of file BackOrderNotifyCustomerCondition.php.

54  {
55  $this->getStockItemConfiguration = $getStockItemConfiguration;
56  $this->getStockItemData = $getStockItemData;
57  $this->productSalableResultFactory = $productSalableResultFactory;
58  $this->productSalabilityErrorFactory = $productSalabilityErrorFactory;
59  }

Member Function Documentation

◆ execute()

execute ( string  $sku,
int  $stockId,
float  $requestedQty 
)

Get is product salable for given SKU in a given Stock for a certain Qty

Parameters
string$sku
int$stockId
float$requestedQty
Returns
\Magento\InventorySalesApi\Api\Data\ProductSalableResultInterface
Exceptions

Implements IsProductSalableForRequestedQtyInterface.

Definition at line 64 of file BackOrderNotifyCustomerCondition.php.

64  : ProductSalableResultInterface
65  {
66  $stockItemConfiguration = $this->getStockItemConfiguration->execute($sku, $stockId);
67 
68  if ($stockItemConfiguration->getBackorders() === StockItemConfigurationInterface::BACKORDERS_YES_NOTIFY) {
69  $stockItemData = $this->getStockItemData->execute($sku, $stockId);
70  if (null === $stockItemData) {
71  return $this->productSalableResultFactory->create(['errors' => []]);
72  }
73 
74  $backOrderQty = $requestedQty - $stockItemData[GetStockItemDataInterface::QUANTITY];
75  if ($backOrderQty > 0) {
76  $errors = [
77  $this->productSalabilityErrorFactory->create([
78  'code' => 'back_order-not-enough',
79  'message' => __(
80  'We don\'t have as many quantity as you requested, '
81  . 'but we\'ll back order the remaining %1.',
82  $backOrderQty * 1
83  )])
84  ];
85  return $this->productSalableResultFactory->create(['errors' => $errors]);
86  }
87  }
88 
89  return $this->productSalableResultFactory->create(['errors' => []]);
90  }
__()
Definition: __.php:13
$errors
Definition: overview.phtml:9

The documentation for this class was generated from the following file: