Skip to content

Commit b9b23b9

Browse files
committed
ACP2E-2704: Getting Unable to send the cookie. Size of 'mage-messages' while trying to Reorder
1 parent 2a7960b commit b9b23b9

File tree

7 files changed

+34
-53
lines changed

7 files changed

+34
-53
lines changed

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

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\Framework\Api\AttributeValueFactory;
1313
use Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface;
1414
use Magento\Framework\App\ObjectManager;
15+
use Magento\Framework\DataObject;
1516
use Magento\Framework\Exception\NoSuchEntityException;
1617
use Magento\Framework\Model\AbstractExtensibleModel;
1718
use Magento\Quote\Api\Data\PaymentInterface;
@@ -1619,7 +1620,7 @@ public function addItem(\Magento\Quote\Model\Quote\Item $item)
16191620
* Add product. Returns error message if product type instance can't prepare product.
16201621
*
16211622
* @param mixed $product
1622-
* @param null|float|\Magento\Framework\DataObject $request
1623+
* @param null|float|DataObject $request
16231624
* @param null|string $processMode
16241625
* @return \Magento\Quote\Model\Quote\Item|string
16251626
* @throws \Magento\Framework\Exception\LocalizedException
@@ -1637,11 +1638,12 @@ public function addProduct(
16371638
if (is_numeric($request)) {
16381639
$request = $this->objectFactory->create(['qty' => $request]);
16391640
}
1640-
if (!$request instanceof \Magento\Framework\DataObject) {
1641+
if (!$request instanceof DataObject) {
16411642
throw new \Magento\Framework\Exception\LocalizedException(
16421643
__('We found an invalid request for adding product to quote.')
16431644
);
16441645
}
1646+
$invalidProductAddFlag = $this->checkForInvalidProductAdd($request);
16451647

16461648
if (!$product->isSalable()) {
16471649
throw new \Magento\Framework\Exception\LocalizedException(
@@ -1699,7 +1701,7 @@ public function addProduct(
16991701

17001702
// collect errors instead of throwing first one
17011703
if ($item->getHasError()) {
1702-
if (!$request->getForceAddToCart()) {
1704+
if (!$invalidProductAddFlag) {
17031705
$this->deleteItem($item);
17041706
}
17051707
foreach ($item->getMessage(false) as $message) {
@@ -1719,6 +1721,20 @@ public function addProduct(
17191721
return $parentItem;
17201722
}
17211723

1724+
/**
1725+
* Checks if invalid products should be added to quote
1726+
*
1727+
* @param DataObject $request
1728+
* @return bool
1729+
*/
1730+
private function checkForInvalidProductAdd(DataObject $request): bool
1731+
{
1732+
$forceAdd = $request->getAddToCartInvalidProduct();
1733+
$request->unsetData('add_to_cart_invalid_product');
1734+
1735+
return (bool) $forceAdd;
1736+
}
1737+
17221738
/**
17231739
* Adding catalog product object data to quote
17241740
*
@@ -1774,8 +1790,8 @@ protected function _addCatalogProduct(\Magento\Catalog\Model\Product $product, $
17741790
* For more options see \Magento\Catalog\Helper\Product->addParamsToBuyRequest()
17751791
*
17761792
* @param int $itemId
1777-
* @param \Magento\Framework\DataObject $buyRequest
1778-
* @param null|array|\Magento\Framework\DataObject $params
1793+
* @param DataObject $buyRequest
1794+
* @param null|array|DataObject $params
17791795
* @return \Magento\Quote\Model\Quote\Item
17801796
* @throws \Magento\Framework\Exception\LocalizedException
17811797
*
@@ -1797,9 +1813,9 @@ public function updateItem($itemId, $buyRequest, $params = null)
17971813
$product = clone $this->productRepository->getById($productId, false, $this->getStore()->getId());
17981814

17991815
if (!$params) {
1800-
$params = new \Magento\Framework\DataObject();
1816+
$params = new DataObject();
18011817
} elseif (is_array($params)) {
1802-
$params = new \Magento\Framework\DataObject($params);
1818+
$params = new DataObject($params);
18031819
}
18041820
$params->setCurrentConfig($item->getBuyRequest());
18051821
$buyRequest = $this->_catalogProduct->addParamsToBuyRequest($buyRequest, $params);
@@ -2148,7 +2164,7 @@ protected function _clearErrorInfo()
21482164
* @param string|null $origin Usually a name of module, that embeds error
21492165
* @param int|null $code Error code, unique for origin, that sets it
21502166
* @param string|null $message Error message
2151-
* @param \Magento\Framework\DataObject|null $additionalData Any additional data, that caller would like to store
2167+
* @param DataObject|null $additionalData Any additional data, that caller would like to store
21522168
* @return $this
21532169
*/
21542170
public function addErrorInfo(

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class Reorder
107107
/**
108108
* @var bool
109109
*/
110-
private bool $forceAdd;
110+
private bool $addToCartInvalidProduct;
111111

112112
/**
113113
* @param OrderFactory $orderFactory
@@ -118,7 +118,7 @@ class Reorder
118118
* @param LoggerInterface $logger
119119
* @param ProductCollectionFactory $productCollectionFactory
120120
* @param OrderInfoBuyRequestGetter $orderInfoBuyRequestGetter
121-
* @param bool $forceAdd
121+
* @param bool $addToCartInvalidProduct
122122
*/
123123
public function __construct(
124124
OrderFactory $orderFactory,
@@ -129,7 +129,7 @@ public function __construct(
129129
LoggerInterface $logger,
130130
ProductCollectionFactory $productCollectionFactory,
131131
OrderInfoBuyRequestGetter $orderInfoBuyRequestGetter,
132-
bool $forceAdd = false
132+
bool $addToCartInvalidProduct = false
133133
) {
134134
$this->orderFactory = $orderFactory;
135135
$this->cartRepository = $cartRepository;
@@ -139,7 +139,7 @@ public function __construct(
139139
$this->guestCartResolver = $guestCartResolver;
140140
$this->productCollectionFactory = $productCollectionFactory;
141141
$this->orderInfoBuyRequestGetter = $orderInfoBuyRequestGetter;
142-
$this->forceAdd = $forceAdd;
142+
$this->addToCartInvalidProduct = $addToCartInvalidProduct;
143143
}
144144

145145
/**
@@ -272,7 +272,7 @@ private function addItemToCart(OrderItemInterface $orderItem, Quote $cart, Produ
272272

273273
$addProductResult = null;
274274
try {
275-
$infoBuyRequest->setForceAddToCart($this->forceAdd);
275+
$infoBuyRequest->setAddToCartInvalidProduct($this->addToCartInvalidProduct);
276276
$addProductResult = $cart->addProduct($product, $infoBuyRequest);
277277
} catch (\Magento\Framework\Exception\LocalizedException $e) {
278278
$this->addError($this->getCartItemErrorMessage($orderItem, $product, $e->getMessage()));

app/code/Magento/Sales/etc/di.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,9 +1038,4 @@
10381038
</argument>
10391039
</arguments>
10401040
</type>
1041-
<type name="Magento\Sales\Model\Reorder\Reorder">
1042-
<arguments>
1043-
<argument name="forceAdd" xsi:type="boolean">true</argument>
1044-
</arguments>
1045-
</type>
10461041
</config>

app/code/Magento/Sales/etc/frontend/di.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,9 @@
2222
</argument>
2323
</arguments>
2424
</type>
25+
<type name="Magento\Sales\Model\Reorder\Reorder">
26+
<arguments>
27+
<argument name="addToCartInvalidProduct" xsi:type="boolean">true</argument>
28+
</arguments>
29+
</type>
2530
</config>

app/code/Magento/Sales/etc/graphql/di.xml

Lines changed: 0 additions & 25 deletions
This file was deleted.

app/code/Magento/Sales/etc/webapi_rest/di.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,4 @@
2222
<type name="Magento\Sales\Model\Service\InvoiceService">
2323
<plugin name="addTransactionCommentAfterCapture" type="Magento\Sales\Plugin\Model\Service\Invoice\AddTransactionCommentAfterCapture"/>
2424
</type>
25-
<type name="Magento\Sales\Model\Reorder\Reorder">
26-
<arguments>
27-
<argument name="forceAdd" xsi:type="boolean">false</argument>
28-
</arguments>
29-
</type>
3025
</config>

app/code/Magento/Sales/etc/webapi_soap/di.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,4 @@
2222
<type name="Magento\Sales\Model\Service\InvoiceService">
2323
<plugin name="addTransactionCommentAfterCapture" type="Magento\Sales\Plugin\Model\Service\Invoice\AddTransactionCommentAfterCapture"/>
2424
</type>
25-
<type name="Magento\Sales\Model\Reorder\Reorder">
26-
<arguments>
27-
<argument name="forceAdd" xsi:type="boolean">false</argument>
28-
</arguments>
29-
</type>
3025
</config>

0 commit comments

Comments
 (0)