9
9
use Magento \CatalogInventory \Api \StockStateInterface ;
10
10
use Magento \CatalogInventory \Model \Spi \StockRegistryProviderInterface ;
11
11
use Magento \CatalogInventory \Model \Spi \StockStateProviderInterface ;
12
+ use Magento \Framework \DataObject ;
12
13
13
14
/**
15
+ * Provides functionality for stock state information
16
+ *
14
17
* Interface StockState
15
18
*/
16
19
class StockState implements StockStateInterface
@@ -31,6 +34,8 @@ class StockState implements StockStateInterface
31
34
protected $ stockConfiguration ;
32
35
33
36
/**
37
+ * StockState constructor
38
+ *
34
39
* @param StockStateProviderInterface $stockStateProvider
35
40
* @param StockRegistryProviderInterface $stockRegistryProvider
36
41
* @param StockConfigurationInterface $stockConfiguration
@@ -46,30 +51,32 @@ public function __construct(
46
51
}
47
52
48
53
/**
54
+ * Verify stock by product id
55
+ *
49
56
* @param int $productId
50
57
* @param int $scopeId
51
58
* @return bool
52
59
*/
53
60
public function verifyStock ($ productId , $ scopeId = null )
54
61
{
55
- // if ($scopeId === null) {
56
- $ scopeId = $ this ->stockConfiguration ->getDefaultScopeId ();
57
- // }
62
+ $ scopeId = $ this ->stockConfiguration ->getDefaultScopeId ();
58
63
$ stockItem = $ this ->stockRegistryProvider ->getStockItem ($ productId , $ scopeId );
64
+
59
65
return $ this ->stockStateProvider ->verifyStock ($ stockItem );
60
66
}
61
67
62
68
/**
69
+ * Verify notification by product id
70
+ *
63
71
* @param int $productId
64
72
* @param int $scopeId
65
73
* @return bool
66
74
*/
67
75
public function verifyNotification ($ productId , $ scopeId = null )
68
76
{
69
- // if ($scopeId === null) {
70
- $ scopeId = $ this ->stockConfiguration ->getDefaultScopeId ();
71
- // }
77
+ $ scopeId = $ this ->stockConfiguration ->getDefaultScopeId ();
72
78
$ stockItem = $ this ->stockRegistryProvider ->getStockItem ($ productId , $ scopeId );
79
+
73
80
return $ this ->stockStateProvider ->verifyNotification ($ stockItem );
74
81
}
75
82
@@ -84,16 +91,14 @@ public function verifyNotification($productId, $scopeId = null)
84
91
*/
85
92
public function checkQty ($ productId , $ qty , $ scopeId = null )
86
93
{
87
- // if ($scopeId === null) {
88
- $ scopeId = $ this ->stockConfiguration ->getDefaultScopeId ();
89
- // }
94
+ $ scopeId = $ this ->stockConfiguration ->getDefaultScopeId ();
90
95
$ stockItem = $ this ->stockRegistryProvider ->getStockItem ($ productId , $ scopeId );
96
+
91
97
return $ this ->stockStateProvider ->checkQty ($ stockItem , $ qty );
92
98
}
93
99
94
100
/**
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
97
102
*
98
103
* @param int $productId
99
104
* @param float $qty
@@ -102,10 +107,9 @@ public function checkQty($productId, $qty, $scopeId = null)
102
107
*/
103
108
public function suggestQty ($ productId , $ qty , $ scopeId = null )
104
109
{
105
- // if ($scopeId === null) {
106
- $ scopeId = $ this ->stockConfiguration ->getDefaultScopeId ();
107
- // }
110
+ $ scopeId = $ this ->stockConfiguration ->getDefaultScopeId ();
108
111
$ stockItem = $ this ->stockRegistryProvider ->getStockItem ($ productId , $ scopeId );
112
+
109
113
return $ this ->stockStateProvider ->suggestQty ($ stockItem , $ qty );
110
114
}
111
115
@@ -118,29 +122,31 @@ public function suggestQty($productId, $qty, $scopeId = null)
118
122
*/
119
123
public function getStockQty ($ productId , $ scopeId = null )
120
124
{
121
- // if ($scopeId === null) {
122
- $ scopeId = $ this ->stockConfiguration ->getDefaultScopeId ();
123
- // }
125
+ $ scopeId = $ this ->stockConfiguration ->getDefaultScopeId ();
124
126
$ stockItem = $ this ->stockRegistryProvider ->getStockItem ($ productId , $ scopeId );
127
+
125
128
return $ this ->stockStateProvider ->getStockQty ($ stockItem );
126
129
}
127
130
128
131
/**
132
+ * Check qty increments by product id
133
+ *
129
134
* @param int $productId
130
135
* @param float $qty
131
136
* @param int $websiteId
132
- * @return \Magento\Framework\ DataObject
137
+ * @return DataObject
133
138
*/
134
139
public function checkQtyIncrements ($ productId , $ qty , $ websiteId = null )
135
140
{
136
- // if ($websiteId === null) {
137
- $ websiteId = $ this ->stockConfiguration ->getDefaultScopeId ();
138
- // }
141
+ $ websiteId = $ this ->stockConfiguration ->getDefaultScopeId ();
139
142
$ stockItem = $ this ->stockRegistryProvider ->getStockItem ($ productId , $ websiteId );
143
+
140
144
return $ this ->stockStateProvider ->checkQtyIncrements ($ stockItem , $ qty );
141
145
}
142
146
143
147
/**
148
+ * Check quote item qty
149
+ *
144
150
* @param int $productId
145
151
* @param float $itemQty
146
152
* @param float $qtyToCheck
@@ -150,10 +156,9 @@ public function checkQtyIncrements($productId, $qty, $websiteId = null)
150
156
*/
151
157
public function checkQuoteItemQty ($ productId , $ itemQty , $ qtyToCheck , $ origQty , $ scopeId = null )
152
158
{
153
- // if ($scopeId === null) {
154
- $ scopeId = $ this ->stockConfiguration ->getDefaultScopeId ();
155
- // }
159
+ $ scopeId = $ this ->stockConfiguration ->getDefaultScopeId ();
156
160
$ stockItem = $ this ->stockRegistryProvider ->getStockItem ($ productId , $ scopeId );
161
+
157
162
return $ this ->stockStateProvider ->checkQuoteItemQty ($ stockItem , $ itemQty , $ qtyToCheck , $ origQty );
158
163
}
159
164
}
0 commit comments