@@ -99,41 +99,41 @@ public function validate(Observer $observer)
99
99
{
100
100
/* @var $quoteItem \Magento\Quote\Model\Quote\Item */
101
101
$ quoteItem = $ observer ->getEvent ()->getItem ();
102
-
103
102
if (!$ quoteItem ||
104
103
!$ quoteItem ->getProductId () ||
105
104
!$ quoteItem ->getQuote () ||
106
105
$ quoteItem ->getQuote ()->getIsSuperMode ()
107
106
) {
108
107
return ;
109
108
}
110
-
109
+ $ product = $ quoteItem -> getProduct ();
111
110
$ qty = $ quoteItem ->getQty ();
112
111
113
- /** @var \Magento\CatalogInventory\Model\Stock\Item $stockItem */
114
- $ stockItem = $ this ->stockRegistry ->getStockItem (
115
- $ quoteItem ->getProduct ()->getId (),
116
- $ quoteItem ->getProduct ()->getStore ()->getWebsiteId ()
117
- );
112
+ /* @var \Magento\CatalogInventory\Model\Stock\Item $stockItem */
113
+ $ stockItem = $ this ->stockRegistry ->getStockItem ($ product ->getId (), $ product ->getStore ()->getWebsiteId ());
118
114
if (!$ stockItem instanceof StockItemInterface) {
119
115
throw new LocalizedException (__ ('The stock item for Product is not valid. ' ));
120
116
}
121
117
122
- $ parentStockItem = false ;
118
+ /* @var \Magento\CatalogInventory\Api\Data\StockStatusInterface $stockStatus */
119
+ $ stockStatus = $ this ->stockRegistry ->getStockStatus ($ product ->getId (), $ product ->getStore ()->getWebsiteId ());
120
+
121
+ /* @var \Magento\CatalogInventory\Api\Data\StockStatusInterface $parentStockStatus */
122
+ $ parentStockStatus = false ;
123
123
124
124
/**
125
125
* Check if product in stock. For composite products check base (parent) item stock status
126
126
*/
127
127
if ($ quoteItem ->getParentItem ()) {
128
128
$ product = $ quoteItem ->getParentItem ()->getProduct ();
129
- $ parentStockItem = $ this ->stockRegistry ->getStockItem (
129
+ $ parentStockStatus = $ this ->stockRegistry ->getStockStatus (
130
130
$ product ->getId (),
131
131
$ product ->getStore ()->getWebsiteId ()
132
132
);
133
133
}
134
134
135
- if ($ stockItem ) {
136
- if (!$ stockItem -> getIsInStock () || $ parentStockItem && !$ parentStockItem -> getIsInStock ()) {
135
+ if ($ stockStatus ) {
136
+ if (!$ stockStatus -> getStockStatus () || $ parentStockStatus && !$ parentStockStatus -> getStockStatus ()) {
137
137
$ quoteItem ->addErrorInfo (
138
138
'cataloginventory ' ,
139
139
Data::ERROR_QTY ,
@@ -156,13 +156,13 @@ public function validate(Observer $observer)
156
156
* Check item for options
157
157
*/
158
158
if (($ options = $ quoteItem ->getQtyOptions ()) && $ qty > 0 ) {
159
- $ qty = $ quoteItem -> getProduct ()-> getTypeInstance ()->prepareQuoteItemQty ($ qty , $ quoteItem -> getProduct () );
159
+ $ qty = $ product -> getTypeInstance ()->prepareQuoteItemQty ($ qty , $ product );
160
160
$ quoteItem ->setData ('qty ' , $ qty );
161
- if ($ stockItem ) {
161
+ if ($ stockStatus ) {
162
162
$ result = $ this ->stockState ->checkQtyIncrements (
163
- $ quoteItem -> getProduct () ->getId (),
163
+ $ product ->getId (),
164
164
$ qty ,
165
- $ quoteItem -> getProduct () ->getStore ()->getWebsiteId ()
165
+ $ product ->getStore ()->getWebsiteId ()
166
166
);
167
167
if ($ result ->getHasError ()) {
168
168
$ quoteItem ->addErrorInfo (
0 commit comments