Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
StockState.php
Go to the documentation of this file.
1 <?php
7 
12 
17 {
22 
27 
32 
38  public function __construct(
42  ) {
43  $this->stockStateProvider = $stockStateProvider;
44  $this->stockRegistryProvider = $stockRegistryProvider;
45  $this->stockConfiguration = $stockConfiguration;
46  }
47 
53  public function verifyStock($productId, $scopeId = null)
54  {
55  // if ($scopeId === null) {
56  $scopeId = $this->stockConfiguration->getDefaultScopeId();
57  // }
58  $stockItem = $this->stockRegistryProvider->getStockItem($productId, $scopeId);
59  return $this->stockStateProvider->verifyStock($stockItem);
60  }
61 
67  public function verifyNotification($productId, $scopeId = null)
68  {
69  // if ($scopeId === null) {
70  $scopeId = $this->stockConfiguration->getDefaultScopeId();
71  // }
72  $stockItem = $this->stockRegistryProvider->getStockItem($productId, $scopeId);
73  return $this->stockStateProvider->verifyNotification($stockItem);
74  }
75 
85  public function checkQty($productId, $qty, $scopeId = null)
86  {
87  // if ($scopeId === null) {
88  $scopeId = $this->stockConfiguration->getDefaultScopeId();
89  // }
90  $stockItem = $this->stockRegistryProvider->getStockItem($productId, $scopeId);
91  return $this->stockStateProvider->checkQty($stockItem, $qty);
92  }
93 
103  public function suggestQty($productId, $qty, $scopeId = null)
104  {
105  // if ($scopeId === null) {
106  $scopeId = $this->stockConfiguration->getDefaultScopeId();
107  // }
108  $stockItem = $this->stockRegistryProvider->getStockItem($productId, $scopeId);
109  return $this->stockStateProvider->suggestQty($stockItem, $qty);
110  }
111 
119  public function getStockQty($productId, $scopeId = null)
120  {
121  // if ($scopeId === null) {
122  $scopeId = $this->stockConfiguration->getDefaultScopeId();
123  // }
124  $stockItem = $this->stockRegistryProvider->getStockItem($productId, $scopeId);
125  return $this->stockStateProvider->getStockQty($stockItem);
126  }
127 
134  public function checkQtyIncrements($productId, $qty, $websiteId = null)
135  {
136  // if ($websiteId === null) {
137  $websiteId = $this->stockConfiguration->getDefaultScopeId();
138  // }
139  $stockItem = $this->stockRegistryProvider->getStockItem($productId, $websiteId);
140  return $this->stockStateProvider->checkQtyIncrements($stockItem, $qty);
141  }
142 
151  public function checkQuoteItemQty($productId, $itemQty, $qtyToCheck, $origQty, $scopeId = null)
152  {
153  // if ($scopeId === null) {
154  $scopeId = $this->stockConfiguration->getDefaultScopeId();
155  // }
156  $stockItem = $this->stockRegistryProvider->getStockItem($productId, $scopeId);
157  return $this->stockStateProvider->checkQuoteItemQty($stockItem, $itemQty, $qtyToCheck, $origQty);
158  }
159 }
__construct(StockStateProviderInterface $stockStateProvider, StockRegistryProviderInterface $stockRegistryProvider, StockConfigurationInterface $stockConfiguration)
Definition: StockState.php:38
suggestQty($productId, $qty, $scopeId=null)
Definition: StockState.php:103
verifyNotification($productId, $scopeId=null)
Definition: StockState.php:67
checkQtyIncrements($productId, $qty, $websiteId=null)
Definition: StockState.php:134
verifyStock($productId, $scopeId=null)
Definition: StockState.php:53
checkQuoteItemQty($productId, $itemQty, $qtyToCheck, $origQty, $scopeId=null)
Definition: StockState.php:151
getStockQty($productId, $scopeId=null)
Definition: StockState.php:119
checkQty($productId, $qty, $scopeId=null)
Definition: StockState.php:85