Skip to content

Commit 0202a65

Browse files
committed
MAGETWO-61095: When attempting to place a reorder after a product is disabled, product still gets added to the cart
1 parent 84d382b commit 0202a65

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

app/code/Magento/CatalogInventory/Model/Quote/Item/QuantityValidator.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -99,41 +99,41 @@ public function validate(Observer $observer)
9999
{
100100
/* @var $quoteItem \Magento\Quote\Model\Quote\Item */
101101
$quoteItem = $observer->getEvent()->getItem();
102-
103102
if (!$quoteItem ||
104103
!$quoteItem->getProductId() ||
105104
!$quoteItem->getQuote() ||
106105
$quoteItem->getQuote()->getIsSuperMode()
107106
) {
108107
return;
109108
}
110-
109+
$product = $quoteItem->getProduct();
111110
$qty = $quoteItem->getQty();
112111

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());
118114
if (!$stockItem instanceof StockItemInterface) {
119115
throw new LocalizedException(__('The stock item for Product is not valid.'));
120116
}
121117

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;
123123

124124
/**
125125
* Check if product in stock. For composite products check base (parent) item stock status
126126
*/
127127
if ($quoteItem->getParentItem()) {
128128
$product = $quoteItem->getParentItem()->getProduct();
129-
$parentStockItem = $this->stockRegistry->getStockItem(
129+
$parentStockStatus = $this->stockRegistry->getStockStatus(
130130
$product->getId(),
131131
$product->getStore()->getWebsiteId()
132132
);
133133
}
134134

135-
if ($stockItem) {
136-
if (!$stockItem->getIsInStock() || $parentStockItem && !$parentStockItem->getIsInStock()) {
135+
if ($stockStatus) {
136+
if (!$stockStatus->getStockStatus() || $parentStockStatus && !$parentStockStatus->getStockStatus()) {
137137
$quoteItem->addErrorInfo(
138138
'cataloginventory',
139139
Data::ERROR_QTY,
@@ -156,13 +156,13 @@ public function validate(Observer $observer)
156156
* Check item for options
157157
*/
158158
if (($options = $quoteItem->getQtyOptions()) && $qty > 0) {
159-
$qty = $quoteItem->getProduct()->getTypeInstance()->prepareQuoteItemQty($qty, $quoteItem->getProduct());
159+
$qty = $product->getTypeInstance()->prepareQuoteItemQty($qty, $product);
160160
$quoteItem->setData('qty', $qty);
161-
if ($stockItem) {
161+
if ($stockStatus) {
162162
$result = $this->stockState->checkQtyIncrements(
163-
$quoteItem->getProduct()->getId(),
163+
$product->getId(),
164164
$qty,
165-
$quoteItem->getProduct()->getStore()->getWebsiteId()
165+
$product->getStore()->getWebsiteId()
166166
);
167167
if ($result->getHasError()) {
168168
$quoteItem->addErrorInfo(

0 commit comments

Comments
 (0)