Skip to content

Commit 25e38e1

Browse files
committed
ACP2E-3618: [CLOUD] Re-order button functionality
1 parent c731c59 commit 25e38e1

File tree

3 files changed

+23
-15
lines changed

3 files changed

+23
-15
lines changed

app/code/Magento/Quote/Model/Cart/AddProductsToCart.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,17 +168,11 @@ private function addItemToCart(
168168
$stockItemQuantity
169169
);
170170
}
171-
//here $result has errors
171+
172172
if (is_string($result)) {
173173
foreach (array_unique(explode("\n", $result)) as $error) {
174174
$errors[] = $this->error->create(__($error)->render(), $cartItemPosition, $stockItemQuantity);
175175
}
176-
} elseif ($result->getHasError() && $result->getStockStateResult()->getHasError()) {
177-
$errors[] = $this->error->create(
178-
__($result->getStockStateResult()->getMessage())->render(),
179-
$cartItemPosition,
180-
$stockItemQuantity
181-
);
182176
}
183177

184178
return $errors;

app/code/Magento/Quote/Model/Quote.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1668,6 +1668,8 @@ public function addProduct(
16681668
}
16691669

16701670
$parentItem = null;
1671+
$errors = [];
1672+
$item = null;
16711673
$items = [];
16721674
foreach ($cartCandidates as $candidate) {
16731675
// Child items can be sticked together only within their parent
@@ -1697,12 +1699,23 @@ public function addProduct(
16971699

16981700
$this->itemProcessor->prepare($item, $request, $candidate);
16991701

1702+
// collect errors instead of throwing first one
17001703
if ($item->getHasError()) {
17011704
if (!$invalidProductAddFlag) {
17021705
$this->deleteItem($item);
17031706
}
1707+
foreach ($item->getMessage(false) as $message) {
1708+
if (!in_array($message, $errors)) {
1709+
// filter duplicate messages
1710+
$errors[] = $message;
1711+
}
1712+
}
1713+
break;
17041714
}
17051715
}
1716+
if (!empty($errors)) {
1717+
throw new \Magento\Framework\Exception\LocalizedException(__(implode("\n", $errors)));
1718+
}
17061719

17071720
$this->_eventManager->dispatch('sales_quote_product_add_after', ['items' => $items]);
17081721
return $parentItem;

app/code/Magento/Sales/Model/AdminOrder/Create.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -598,11 +598,6 @@ public function initFromOrder(\Magento\Sales\Model\Order $order)
598598
if (is_string($item)) {
599599
throw new \Magento\Framework\Exception\LocalizedException(__($item));
600600
}
601-
if ($item->getStockStateResult() && $item->getStockStateResult()->getHasError()) {
602-
$this->messageManager->addErrorMessage(
603-
__('The product with SKU %sku is out of stock.', ['sku' => $item->getSku()])
604-
);
605-
}
606601
}
607602
}
608603
}
@@ -738,11 +733,17 @@ public function initFromOrderItem(\Magento\Sales\Model\Order\Item $orderItem, $q
738733

739734
$this->formattedOptions($product, $buyRequest, $productOptions);
740735

741-
$item = $this->getQuote()->addProduct($product, $buyRequest);
742-
if (is_string($item)) {
743-
return $item;
736+
try {
737+
$item = $this->getQuote()->addProduct($product, $buyRequest);
738+
if (is_string($item)) {
739+
return $item;
740+
}
741+
} catch (LocalizedException $e) {
742+
$this->messageManager->addErrorMessage(__($e->getMessage()));
743+
return $this;
744744
}
745745

746+
746747
if ($additionalOptions = $orderItem->getProductOptionByCode('additional_options')) {
747748
$item->addOption(
748749
new \Magento\Framework\DataObject(

0 commit comments

Comments
 (0)