Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Configuration.php
Go to the documentation of this file.
1 <?php
7 
9 use Magento\CatalogInventory\Helper\Minsaleqty as MinsaleqtyHelper;
13 
18 {
22  const DEFAULT_WEBSITE_ID = 1;
23 
27  const XML_PATH_GLOBAL = 'cataloginventory/options/';
28 
32  const XML_PATH_CAN_SUBTRACT = 'cataloginventory/options/can_subtract';
33 
37  const XML_PATH_CAN_BACK_IN_STOCK = 'cataloginventory/options/can_back_in_stock';
38 
42  const XML_PATH_ITEM = 'cataloginventory/item_options/';
43 
47  const XML_PATH_MIN_QTY = 'cataloginventory/item_options/min_qty';
48 
52  const XML_PATH_MIN_SALE_QTY = 'cataloginventory/item_options/min_sale_qty';
53 
57  const XML_PATH_MAX_SALE_QTY = 'cataloginventory/item_options/max_sale_qty';
58 
62  const XML_PATH_BACKORDERS = 'cataloginventory/item_options/backorders';
63 
67  const XML_PATH_NOTIFY_STOCK_QTY = 'cataloginventory/item_options/notify_stock_qty';
68 
72  const XML_PATH_MANAGE_STOCK = 'cataloginventory/item_options/manage_stock';
73 
77  const XML_PATH_ENABLE_QTY_INCREMENTS = 'cataloginventory/item_options/enable_qty_increments';
78 
82  const XML_PATH_QTY_INCREMENTS = 'cataloginventory/item_options/qty_increments';
83 
87  const XML_PATH_SHOW_OUT_OF_STOCK = 'cataloginventory/options/show_out_of_stock';
88 
92  const XML_PATH_ITEM_AUTO_RETURN = 'cataloginventory/item_options/auto_return';
93 
97  const XML_PATH_DISPLAY_PRODUCT_STOCK_STATUS = 'cataloginventory/options/display_product_stock_status';
98 
102  const XML_PATH_STOCK_THRESHOLD_QTY = 'cataloginventory/options/stock_threshold_qty';
103 
107  protected $config;
108 
114  protected $scopeConfig;
115 
119  protected $minsaleqtyHelper;
120 
126  protected $isQtyTypeIds;
127 
131  protected $storeManager;
132 
139  public function __construct(
142  MinsaleqtyHelper $minsaleqtyHelper,
144  ) {
145  $this->config = $config;
146  $this->scopeConfig = $scopeConfig;
147  $this->minsaleqtyHelper = $minsaleqtyHelper;
148  $this->storeManager = $storeManager;
149  }
150 
154  public function getDefaultScopeId()
155  {
156  // TODO: should be fixed in MAGETWO-46043
157  // "0" is id of admin website, which is used in backend during save entity
158  return 0;
159  }
160 
165  public function getIsQtyTypeIds($filter = null)
166  {
167  if (null === $this->isQtyTypeIds) {
168  $this->isQtyTypeIds = [];
169  foreach ($this->config->getAll() as $typeId => $typeConfig) {
170  $this->isQtyTypeIds[$typeId] = isset($typeConfig['is_qty']) ? $typeConfig['is_qty'] : false;
171  }
172  }
174  if ($filter !== null) {
175  foreach ($result as $key => $value) {
176  if ($value !== $filter) {
177  unset($result[$key]);
178  }
179  }
180  }
181  return $result;
182  }
183 
188  public function isQty($productTypeId)
189  {
190  $result = $this->getIsQtyTypeIds();
191  return isset($result[$productTypeId]) ? $result[$productTypeId] : false;
192  }
193 
200  public function canSubtractQty($store = null)
201  {
202  return $this->scopeConfig->isSetFlag(
203  self::XML_PATH_CAN_SUBTRACT,
204  \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
205  $store
206  );
207  }
208 
213  public function getMinQty($store = null)
214  {
215  return (float)$this->scopeConfig->getValue(
216  self::XML_PATH_MIN_QTY,
217  \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
218  $store
219  );
220  }
221 
227  public function getMinSaleQty($store = null, $customerGroupId = null)
228  {
229  return (float)$this->minsaleqtyHelper->getConfigValue($customerGroupId, $store);
230  }
231 
236  public function getMaxSaleQty($store = null)
237  {
238  return (float)$this->scopeConfig->getValue(
239  self::XML_PATH_MAX_SALE_QTY,
240  \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
241  $store
242  );
243  }
244 
249  public function getNotifyStockQty($store = null)
250  {
251  return (float) $this->scopeConfig->getValue(
252  self::XML_PATH_NOTIFY_STOCK_QTY,
253  \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
254  $store
255  );
256  }
257 
265  public function getEnableQtyIncrements($store = null)
266  {
267  return (bool) $this->scopeConfig->getValue(
268  self::XML_PATH_ENABLE_QTY_INCREMENTS,
269  \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
270  $store
271  );
272  }
273 
278  public function getQtyIncrements($store = null)
279  {
280  return (float)$this->scopeConfig->getValue(
281  self::XML_PATH_QTY_INCREMENTS,
282  \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
283  $store
284  );
285  }
286 
293  public function getBackorders($store = null)
294  {
295  return (int) $this->scopeConfig->getValue(
296  self::XML_PATH_BACKORDERS,
297  \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
298  $store
299  );
300  }
301 
308  public function getManageStock($store = null)
309  {
310  return (int) $this->scopeConfig->isSetFlag(
311  self::XML_PATH_MANAGE_STOCK,
312  \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
313  $store
314  );
315  }
316 
324  public function getCanBackInStock($store = null)
325  {
326  return $this->scopeConfig->isSetFlag(
327  self::XML_PATH_CAN_BACK_IN_STOCK,
328  \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
329  $store
330  );
331  }
332 
339  public function isShowOutOfStock($store = null)
340  {
341  return $this->scopeConfig->isSetFlag(
342  self::XML_PATH_SHOW_OUT_OF_STOCK,
343  \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
344  $store
345  );
346  }
347 
354  public function isAutoReturnEnabled($store = null)
355  {
356  return $this->scopeConfig->isSetFlag(
357  self::XML_PATH_ITEM_AUTO_RETURN,
358  \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
359  $store
360  );
361  }
362 
370  public function isDisplayProductStockStatus($store = null)
371  {
372  return $this->scopeConfig->isSetFlag(
373  self::XML_PATH_DISPLAY_PRODUCT_STOCK_STATUS,
374  \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
375  $store
376  );
377  }
378 
384  public function getDefaultConfigValue($field, $store = null)
385  {
386  return $this->scopeConfig->getValue(
387  self::XML_PATH_ITEM . $field,
388  \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
389  $store
390  );
391  }
392 
397  public function getStockThresholdQty($store = null)
398  {
399  return $this->scopeConfig->getValue(
400  self::XML_PATH_STOCK_THRESHOLD_QTY,
401  \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
402  $store
403  );
404  }
405 
411  public function getConfigItemOptions()
412  {
413  return [
414  'min_qty',
415  'backorders',
416  'min_sale_qty',
417  'max_sale_qty',
418  'notify_stock_qty',
419  'manage_stock',
420  'enable_qty_increments',
421  'qty_increments',
422  'is_decimal_divided'
423  ];
424  }
425 }
getMinSaleQty($store=null, $customerGroupId=null)
$value
Definition: gender.phtml:16
__construct(ConfigInterface $config, ScopeConfigInterface $scopeConfig, MinsaleqtyHelper $minsaleqtyHelper, StoreManagerInterface $storeManager)