Skip to content

Commit 410db1c

Browse files
committed
ACP2E-2704: Getting Unable to send the cookie. Size of 'mage-messages' while trying to Reorder
1 parent 9dbe14e commit 410db1c

File tree

3 files changed

+39
-5
lines changed

3 files changed

+39
-5
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1699,7 +1699,9 @@ public function addProduct(
16991699

17001700
// collect errors instead of throwing first one
17011701
if ($item->getHasError()) {
1702-
$this->deleteItem($item);
1702+
if (!$request->getForceAddToCart()) {
1703+
$this->deleteItem($item);
1704+
}
17031705
foreach ($item->getMessage(false) as $message) {
17041706
if (!in_array($message, $errors)) {
17051707
// filter duplicate messages

app/code/Magento/Quote/Test/Unit/Model/QuoteTest.php

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
use Magento\Framework\DataObject\Copy;
3131
use Magento\Framework\DataObject\Factory;
3232
use Magento\Framework\Event\Manager;
33+
use Magento\Framework\Exception\LocalizedException;
3334
use Magento\Framework\Exception\NoSuchEntityException;
3435
use Magento\Framework\Model\Context;
3536
use Magento\Framework\Phrase;
@@ -1072,17 +1073,28 @@ public function testAddProductItemPreparation(): void
10721073
}
10731074

10741075
/**
1076+
* @param $request
1077+
* @param $hasError
10751078
* @return void
1079+
* @throws LocalizedException
1080+
* @dataProvider dataProviderForTestAddProductItem
10761081
*/
1077-
public function testAddProductItemNew(): void
1082+
public function testAddProductItemNew($request, $hasError): void
10781083
{
1079-
$itemMock = $this->createMock(Item::class);
1084+
$itemMock = $this->getMockBuilder(Item::class)
1085+
->disableOriginalConstructor()
1086+
->addMethods(['getHasError'])
1087+
->onlyMethods(['representProduct', 'setProduct', 'setOptions', 'setQuote', 'getProduct'])
1088+
->getMock();
1089+
$itemMock->expects($this->once())->method('getHasError')->willReturn($hasError);
1090+
$product = $this->createMock(Product::class);
1091+
$itemMock->expects($this->any())->method('getProduct')->willReturn($product);
10801092

10811093
$expectedResult = $itemMock;
10821094
$requestMock = $this->createMock(
10831095
DataObject::class
10841096
);
1085-
$this->objectFactoryMock->expects($this->once())
1097+
$this->objectFactoryMock->expects($this->any())
10861098
->method('create')
10871099
->with(['qty' => 1])
10881100
->willReturn($requestMock);
@@ -1145,10 +1157,29 @@ public function testAddProductItemNew(): void
11451157
->method('getTypeInstance')
11461158
->willReturn($typeInstanceMock);
11471159

1148-
$result = $this->quote->addProduct($this->productMock, null);
1160+
$result = $this->quote->addProduct($this->productMock, $request);
11491161
$this->assertEquals($expectedResult, $result);
11501162
}
11511163

1164+
/**
1165+
* @return array[]
1166+
*/
1167+
private function dataProviderForTestAddProductItem(): array
1168+
{
1169+
return [
1170+
'not_force_item' => [null, false],
1171+
'force_item' => [
1172+
new DataObject(
1173+
[
1174+
'force_add_to_cart' => true,
1175+
'qty' => 1
1176+
]
1177+
),
1178+
true
1179+
]
1180+
];
1181+
}
1182+
11521183
/**
11531184
* @return void
11541185
*/

app/code/Magento/Sales/Model/Reorder/Reorder.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ private function addItemToCart(OrderItemInterface $orderItem, Quote $cart, Produ
264264

265265
$addProductResult = null;
266266
try {
267+
$infoBuyRequest->setForceAddToCart(true);
267268
$addProductResult = $cart->addProduct($product, $infoBuyRequest);
268269
} catch (\Magento\Framework\Exception\LocalizedException $e) {
269270
$this->addError($this->getCartItemErrorMessage($orderItem, $product, $e->getMessage()));

0 commit comments

Comments
 (0)