Skip to content

Commit f7e4b2a

Browse files
ENGCOM-7979: refactored code #27758
- Merge Pull Request #27758 from ProkopovVitaliy/magento2:fix-26702 - Merged commits: 1. e527114 2. 677ddce 3. 7199dfe 4. 6d024bb 5. 707297a 6. e035f6a
2 parents c415874 + e035f6a commit f7e4b2a

File tree

1 file changed

+29
-24
lines changed

1 file changed

+29
-24
lines changed

app/code/Magento/CatalogInventory/Model/StockState.php

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@
99
use Magento\CatalogInventory\Api\StockStateInterface;
1010
use Magento\CatalogInventory\Model\Spi\StockRegistryProviderInterface;
1111
use Magento\CatalogInventory\Model\Spi\StockStateProviderInterface;
12+
use Magento\Framework\DataObject;
1213

1314
/**
15+
* Provides functionality for stock state information
16+
*
1417
* Interface StockState
1518
*/
1619
class StockState implements StockStateInterface
@@ -31,6 +34,8 @@ class StockState implements StockStateInterface
3134
protected $stockConfiguration;
3235

3336
/**
37+
* StockState constructor
38+
*
3439
* @param StockStateProviderInterface $stockStateProvider
3540
* @param StockRegistryProviderInterface $stockRegistryProvider
3641
* @param StockConfigurationInterface $stockConfiguration
@@ -46,30 +51,32 @@ public function __construct(
4651
}
4752

4853
/**
54+
* Verify stock by product id
55+
*
4956
* @param int $productId
5057
* @param int $scopeId
5158
* @return bool
5259
*/
5360
public function verifyStock($productId, $scopeId = null)
5461
{
55-
// if ($scopeId === null) {
56-
$scopeId = $this->stockConfiguration->getDefaultScopeId();
57-
// }
62+
$scopeId = $this->stockConfiguration->getDefaultScopeId();
5863
$stockItem = $this->stockRegistryProvider->getStockItem($productId, $scopeId);
64+
5965
return $this->stockStateProvider->verifyStock($stockItem);
6066
}
6167

6268
/**
69+
* Verify notification by product id
70+
*
6371
* @param int $productId
6472
* @param int $scopeId
6573
* @return bool
6674
*/
6775
public function verifyNotification($productId, $scopeId = null)
6876
{
69-
// if ($scopeId === null) {
70-
$scopeId = $this->stockConfiguration->getDefaultScopeId();
71-
// }
77+
$scopeId = $this->stockConfiguration->getDefaultScopeId();
7278
$stockItem = $this->stockRegistryProvider->getStockItem($productId, $scopeId);
79+
7380
return $this->stockStateProvider->verifyNotification($stockItem);
7481
}
7582

@@ -84,16 +91,14 @@ public function verifyNotification($productId, $scopeId = null)
8491
*/
8592
public function checkQty($productId, $qty, $scopeId = null)
8693
{
87-
// if ($scopeId === null) {
88-
$scopeId = $this->stockConfiguration->getDefaultScopeId();
89-
// }
94+
$scopeId = $this->stockConfiguration->getDefaultScopeId();
9095
$stockItem = $this->stockRegistryProvider->getStockItem($productId, $scopeId);
96+
9197
return $this->stockStateProvider->checkQty($stockItem, $qty);
9298
}
9399

94100
/**
95-
* Returns suggested qty that satisfies qty increments and minQty/maxQty/minSaleQty/maxSaleQty conditions
96-
* or original qty if such value does not exist
101+
* Returns suggested qty that satisfies qty increments/minQty/maxQty/minSaleQty/maxSaleQty else returns original qty
97102
*
98103
* @param int $productId
99104
* @param float $qty
@@ -102,10 +107,9 @@ public function checkQty($productId, $qty, $scopeId = null)
102107
*/
103108
public function suggestQty($productId, $qty, $scopeId = null)
104109
{
105-
// if ($scopeId === null) {
106-
$scopeId = $this->stockConfiguration->getDefaultScopeId();
107-
// }
110+
$scopeId = $this->stockConfiguration->getDefaultScopeId();
108111
$stockItem = $this->stockRegistryProvider->getStockItem($productId, $scopeId);
112+
109113
return $this->stockStateProvider->suggestQty($stockItem, $qty);
110114
}
111115

@@ -118,29 +122,31 @@ public function suggestQty($productId, $qty, $scopeId = null)
118122
*/
119123
public function getStockQty($productId, $scopeId = null)
120124
{
121-
// if ($scopeId === null) {
122-
$scopeId = $this->stockConfiguration->getDefaultScopeId();
123-
// }
125+
$scopeId = $this->stockConfiguration->getDefaultScopeId();
124126
$stockItem = $this->stockRegistryProvider->getStockItem($productId, $scopeId);
127+
125128
return $this->stockStateProvider->getStockQty($stockItem);
126129
}
127130

128131
/**
132+
* Check qty increments by product id
133+
*
129134
* @param int $productId
130135
* @param float $qty
131136
* @param int $websiteId
132-
* @return \Magento\Framework\DataObject
137+
* @return DataObject
133138
*/
134139
public function checkQtyIncrements($productId, $qty, $websiteId = null)
135140
{
136-
// if ($websiteId === null) {
137-
$websiteId = $this->stockConfiguration->getDefaultScopeId();
138-
// }
141+
$websiteId = $this->stockConfiguration->getDefaultScopeId();
139142
$stockItem = $this->stockRegistryProvider->getStockItem($productId, $websiteId);
143+
140144
return $this->stockStateProvider->checkQtyIncrements($stockItem, $qty);
141145
}
142146

143147
/**
148+
* Check quote item qty
149+
*
144150
* @param int $productId
145151
* @param float $itemQty
146152
* @param float $qtyToCheck
@@ -150,10 +156,9 @@ public function checkQtyIncrements($productId, $qty, $websiteId = null)
150156
*/
151157
public function checkQuoteItemQty($productId, $itemQty, $qtyToCheck, $origQty, $scopeId = null)
152158
{
153-
// if ($scopeId === null) {
154-
$scopeId = $this->stockConfiguration->getDefaultScopeId();
155-
// }
159+
$scopeId = $this->stockConfiguration->getDefaultScopeId();
156160
$stockItem = $this->stockRegistryProvider->getStockItem($productId, $scopeId);
161+
157162
return $this->stockStateProvider->checkQuoteItemQty($stockItem, $itemQty, $qtyToCheck, $origQty);
158163
}
159164
}

0 commit comments

Comments
 (0)