Skip to content

Commit 62448b8

Browse files
committed
AC-15054: Fix Performance Acceptance Tests
1 parent 3cf05c6 commit 62448b8

File tree

2 files changed

+24
-78
lines changed

2 files changed

+24
-78
lines changed

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

Lines changed: 15 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -74,31 +74,23 @@ private function validateProductWebsiteAssignment(CartItemInterface $cartItem):
7474
return;
7575
}
7676

77-
$maskedQuoteId = $cartItem->getQuoteId();
78-
$quoteIdMask = $this->quoteIdMaskFactory->create()->load($maskedQuoteId, 'masked_id');
79-
$quoteId = $quoteIdMask->getQuoteId();
80-
81-
if (!$quoteId) {
82-
return;
83-
}
84-
85-
try {
86-
$quote = $this->cartRepository->get($quoteId);
87-
$storeId = $quote->getStoreId();
88-
89-
foreach ($quote->getAllItems() as $item) {
90-
if ($sku === $item->getSku()) {
91-
$this->validateWebsiteAssignment($item->getProductId(), $storeId);
92-
return;
93-
}
77+
$storeId = (int)($cartItem->getStoreId() ?? 0);
78+
if (!$storeId) {
79+
$maskedQuoteId = $cartItem->getQuoteId();
80+
$quoteIdMask = $this->quoteIdMaskFactory->create()->load($maskedQuoteId, 'masked_id');
81+
$quoteId = (int)$quoteIdMask->getQuoteId();
82+
if (!$quoteId) {
83+
return;
84+
}
85+
try {
86+
$quote = $this->cartRepository->get($quoteId);
87+
$storeId = (int)$quote->getStoreId();
88+
} catch (NoSuchEntityException) {
89+
throw new LocalizedException(__('Product that you are trying to add is not available.'));
9490
}
95-
96-
// Product not in quote yet
97-
$this->validateWebsiteAssignmentBySku($sku, $storeId);
98-
99-
} catch (NoSuchEntityException) {
100-
throw new LocalizedException(__('Product that you are trying to add is not available.'));
10191
}
92+
93+
$this->validateWebsiteAssignmentBySku($sku, $storeId);
10294
}
10395

10496
/**
@@ -119,27 +111,6 @@ private function validateWebsiteAssignmentBySku(string $sku, int $storeId): void
119111
}
120112
}
121113

122-
/**
123-
* Validate by product ID for existing items
124-
*
125-
* @param int $productId
126-
* @param int $storeId
127-
* @return void
128-
* @throws LocalizedException
129-
*/
130-
private function validateWebsiteAssignment(int $productId, int $storeId): void
131-
{
132-
try {
133-
$product = $this->productRepository->getById($productId, false, $storeId);
134-
if (empty($product->getWebsiteIds())) {
135-
return;
136-
}
137-
$this->checkProductInWebsite($product->getWebsiteIds(), $storeId);
138-
} catch (NoSuchEntityException) {
139-
throw new LocalizedException(__('Product that you are trying to add is not available.'));
140-
}
141-
}
142-
143114
/**
144115
* Validate by product ID for existing items
145116
*

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

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,17 @@ public function beforeSave(
5151
return;
5252
}
5353

54-
try {
55-
$quote = $this->cartRepository->getActive($cartItem->getQuoteId());
56-
57-
foreach ($quote->getAllItems() as $item) {
58-
if ($sku === $item->getSku()) {
59-
$this->checkProductWebsiteAssignment($item->getProductId(), $item->getStoreId());
60-
return;
61-
}
54+
$storeId = (int)($cartItem->getStoreId() ?? 0);
55+
if (!$storeId) {
56+
try {
57+
$quote = $this->cartRepository->getActive($cartItem->getQuoteId());
58+
$storeId = (int)$quote->getStoreId();
59+
} catch (NoSuchEntityException $e) {
60+
throw new LocalizedException(__('Product that you are trying to add is not available.'));
6261
}
63-
64-
// Fallback: product not in quote items yet
65-
$this->checkProductWebsiteAssignmentBySku($sku, $quote->getStoreId());
66-
67-
} catch (NoSuchEntityException $e) {
68-
throw new LocalizedException(__('Product that you are trying to add is not available.'));
6962
}
63+
64+
$this->checkProductWebsiteAssignmentBySku($sku, $storeId);
7065
}
7166

7267
/**
@@ -86,26 +81,6 @@ private function checkProductWebsiteAssignmentBySku(string $sku, int $storeId):
8681
}
8782
}
8883

89-
/**
90-
* Check product website assignment by product ID
91-
*
92-
* @param int $productId
93-
* @param int|null $storeId
94-
* @throws LocalizedException
95-
*/
96-
private function checkProductWebsiteAssignment($productId, $storeId): void
97-
{
98-
try {
99-
$product = $this->productRepository->getById($productId, false, $storeId);
100-
if (empty($product->getWebsiteIds())) {
101-
return;
102-
}
103-
$this->validateWebsiteAssignment($product->getWebsiteIds(), $storeId);
104-
} catch (NoSuchEntityException $e) {
105-
throw new LocalizedException(__('Product that you are trying to add is not available.'));
106-
}
107-
}
108-
10984
/**
11085
* Validate product website assignment
11186
*

0 commit comments

Comments
 (0)