diff --git a/vendor/magento/module-quote/Model/Cart/AddProductsToCart.php b/vendor/magento/module-quote/Model/Cart/AddProductsToCart.php index 2c5c3536d66..8c85bb723dd 100644 --- a/vendor/magento/module-quote/Model/Cart/AddProductsToCart.php +++ b/vendor/magento/module-quote/Model/Cart/AddProductsToCart.php @@ -151,6 +151,15 @@ class AddProductsToCart return; } + if (!in_array($cart->getStoreId(), $product->getStoreIds())) { + $this->addError( + __('Could not find a product with SKU "%sku"', ['sku' => $sku])->render(), + $cartItemPosition + ); + + return; + } + try { $result = $cart->addProduct($product, $this->requestBuilder->build($cartItem)); $this->cartRepository->save($cart); diff --git a/vendor/magento/module-quote-graph-ql/Model/Cart/AddSimpleProductToCart.php b/vendor/magento/module-quote-graph-ql/Model/Cart/AddSimpleProductToCart.php index f2dd6389d2c..00837ffeea4 100644 --- a/vendor/magento/module-quote-graph-ql/Model/Cart/AddSimpleProductToCart.php +++ b/vendor/magento/module-quote-graph-ql/Model/Cart/AddSimpleProductToCart.php @@ -60,6 +60,9 @@ class AddSimpleProductToCart } catch (NoSuchEntityException $e) { throw new GraphQlNoSuchEntityException(__('Could not find a product with SKU "%sku"', ['sku' => $sku])); } + if (!in_array($cart->getStore()->getWebsiteId(), $product->getWebsiteIds())) { + throw new GraphQlNoSuchEntityException(__('Could not find a product with SKU "%sku"', ['sku' => $sku])); + } try { $result = $cart->addProduct($product, $this->buyRequestBuilder->build($cartItemData));