Skip to content

Commit 80e2309

Browse files
committed
AC-15054: Fix Performance Acceptance Tests
1 parent cccc7f5 commit 80e2309

File tree

2 files changed

+27
-18
lines changed

2 files changed

+27
-18
lines changed

app/code/Magento/Quote/Plugin/UpdateCartId.php

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
namespace Magento\Quote\Plugin;
1010

11-
use Magento\Catalog\Api\ProductRepositoryInterface;
1211
use Magento\Framework\Exception\LocalizedException;
1312
use Magento\Framework\Exception\NoSuchEntityException;
1413
use Magento\Framework\Webapi\Rest\Request as RestRequest;
@@ -27,14 +26,14 @@ class UpdateCartId
2726
{
2827
/**
2928
* @param RestRequest $request
30-
* @param ProductRepositoryInterface $productRepository
3129
* @param StoreManagerInterface $storeManager
3230
* @param QuoteIdMaskFactory $quoteIdMaskFactory
3331
* @param CartRepositoryInterface $cartRepository
32+
* @param ProductResource $productResource
33+
* @param ProductWebsiteLink $productWebsiteLink
3434
*/
3535
public function __construct(
3636
private readonly RestRequest $request,
37-
private readonly ProductRepositoryInterface $productRepository,
3837
private readonly StoreManagerInterface $storeManager,
3938
private readonly QuoteIdMaskFactory $quoteIdMaskFactory,
4039
private readonly CartRepositoryInterface $cartRepository,
@@ -78,22 +77,33 @@ private function validateProductWebsiteAssignment(CartItemInterface $cartItem):
7877
return;
7978
}
8079

81-
$maskedQuoteId = $cartItem->getQuoteId();
82-
$quoteIdMask = $this->quoteIdMaskFactory->create()->load($maskedQuoteId, 'masked_id');
83-
$quoteId = $quoteIdMask->getQuoteId();
80+
$storeId = (int)($cartItem->getStoreId() ?? 0);
8481

85-
if (!$quoteId) {
86-
return;
82+
if (!$storeId) {
83+
try {
84+
$storeId = (int)$this->storeManager->getStore()->getId();
85+
} catch (\Throwable $e) {
86+
// ignore; fallback to masked quote resolution below
87+
}
8788
}
8889

89-
try {
90-
$quote = $this->cartRepository->get($quoteId);
91-
$storeId = $quote->getStoreId();
92-
// Product not in quote yet
93-
$this->validateWebsiteAssignmentBySku($sku, $storeId);
90+
if (!$storeId) {
91+
try {
92+
$maskedQuoteId = $cartItem->getQuoteId();
93+
if ($maskedQuoteId) {
94+
$quoteIdMask = $this->quoteIdMaskFactory->create()->load($maskedQuoteId, 'masked_id');
95+
$quoteId = (int)$quoteIdMask->getQuoteId();
96+
if ($quoteId) {
97+
$storeId = (int)$this->cartRepository->get($quoteId)->getStoreId();
98+
}
99+
}
100+
} catch (NoSuchEntityException) {
101+
throw new LocalizedException(__('Product that you are trying to add is not available.'));
102+
}
103+
}
94104

95-
} catch (NoSuchEntityException) {
96-
throw new LocalizedException(__('Product that you are trying to add is not available.'));
105+
if ($storeId) {
106+
$this->validateWebsiteAssignmentBySku($sku, $storeId);
97107
}
98108
}
99109

app/code/Magento/Quote/Plugin/Webapi/ValidateProductWebsiteAssignment.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
namespace Magento\Quote\Plugin\Webapi;
99

10-
use Magento\Catalog\Api\ProductRepositoryInterface;
1110
use Magento\Framework\Exception\LocalizedException;
1211
use Magento\Framework\Exception\NoSuchEntityException;
1312
use Magento\Quote\Api\CartItemRepositoryInterface;
@@ -23,12 +22,12 @@
2322
class ValidateProductWebsiteAssignment
2423
{
2524
/**
26-
* @param ProductRepositoryInterface $productRepository
2725
* @param StoreManagerInterface $storeManager
2826
* @param CartRepositoryInterface $cartRepository
27+
* @param ProductResource $productResource
28+
* @param ProductWebsiteLink $productWebsiteLink
2929
*/
3030
public function __construct(
31-
private readonly ProductRepositoryInterface $productRepository,
3231
private readonly StoreManagerInterface $storeManager,
3332
private readonly CartRepositoryInterface $cartRepository,
3433
private readonly ProductResource $productResource,

0 commit comments

Comments
 (0)