Skip to content

Commit d46177a

Browse files
committed
AC-15054: Fix Unit test case
1 parent 276b244 commit d46177a

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,18 @@ private function validateProductWebsiteAssignment(CartItemInterface $cartItem):
7777
return;
7878
}
7979

80+
// Skip validation on update; website was already validated on add
81+
if ($cartItem->getItemId()) {
82+
return;
83+
}
84+
8085
$storeId = (int)($cartItem->getStoreId() ?? 0);
8186

8287
if (!$storeId) {
8388
try {
8489
$storeId = (int)$this->storeManager->getStore()->getId();
8590
} catch (\Throwable $e) {
86-
// ignore; fallback to masked quote resolution below
91+
$storeId = 0;
8792
}
8893
}
8994

@@ -122,6 +127,9 @@ private function validateWebsiteAssignmentBySku(string $sku, int $storeId): void
122127
throw new LocalizedException(__('Product that you are trying to add is not available.'));
123128
}
124129
$websiteIds = $this->productWebsiteLink->getWebsiteIdsByProductId($productId);
130+
if (empty($websiteIds)) {
131+
return;
132+
}
125133
$this->checkProductInWebsite($websiteIds, $storeId);
126134
}
127135

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ public function beforeSave(
5454
return;
5555
}
5656

57+
// Skip validation on update; website was already validated on add
58+
if ($cartItem->getItemId()) {
59+
return;
60+
}
61+
5762
try {
5863
$quote = $this->cartRepository->getActive($cartItem->getQuoteId());
5964
$this->checkProductWebsiteAssignmentBySku($sku, $quote->getStoreId());
@@ -77,6 +82,9 @@ private function checkProductWebsiteAssignmentBySku(string $sku, int $storeId):
7782
throw new LocalizedException(__('Product that you are trying to add is not available.'));
7883
}
7984
$websiteIds = $this->productWebsiteLink->getWebsiteIdsByProductId($productId);
85+
if (empty($websiteIds)) {
86+
return;
87+
}
8088
$this->validateWebsiteAssignment($websiteIds, $storeId);
8189
}
8290

0 commit comments

Comments
 (0)