|
7 | 7 |
|
8 | 8 | namespace Magento\Quote\Model\Cart; |
9 | 9 |
|
10 | | -use Magento\Catalog\Api\ProductRepositoryInterface; |
11 | 10 | use Magento\Framework\Exception\NoSuchEntityException; |
12 | 11 | use Magento\Quote\Api\CartRepositoryInterface; |
13 | 12 | use Magento\Quote\Model\Cart\BuyRequest\BuyRequestBuilder; |
@@ -47,33 +46,25 @@ class AddProductsToCart |
47 | 46 | */ |
48 | 47 | private $error; |
49 | 48 |
|
50 | | - /** |
51 | | - * @var ProductRepositoryInterface |
52 | | - */ |
53 | | - private $productRepository; |
54 | | - |
55 | 49 | /** |
56 | 50 | * @param CartRepositoryInterface $cartRepository |
57 | 51 | * @param MaskedQuoteIdToQuoteIdInterface $maskedQuoteIdToQuoteId |
58 | 52 | * @param BuyRequestBuilder $requestBuilder |
59 | 53 | * @param ProductReaderInterface $productReader |
60 | 54 | * @param AddProductsToCartError $addProductsToCartError |
61 | | - * @param ProductRepositoryInterface $productRepository |
62 | 55 | */ |
63 | 56 | public function __construct( |
64 | 57 | CartRepositoryInterface $cartRepository, |
65 | 58 | MaskedQuoteIdToQuoteIdInterface $maskedQuoteIdToQuoteId, |
66 | 59 | BuyRequestBuilder $requestBuilder, |
67 | 60 | ProductReaderInterface $productReader, |
68 | | - AddProductsToCartError $addProductsToCartError, |
69 | | - ProductRepositoryInterface $productRepository |
| 61 | + AddProductsToCartError $addProductsToCartError |
70 | 62 | ) { |
71 | 63 | $this->cartRepository = $cartRepository; |
72 | 64 | $this->maskedQuoteIdToQuoteId = $maskedQuoteIdToQuoteId; |
73 | 65 | $this->requestBuilder = $requestBuilder; |
74 | 66 | $this->productReader = $productReader; |
75 | 67 | $this->error = $addProductsToCartError; |
76 | | - $this->productRepository = $productRepository; |
77 | 68 | } |
78 | 69 |
|
79 | 70 | /** |
@@ -143,6 +134,7 @@ function ($item) { |
143 | 134 | }, |
144 | 135 | $cartItems |
145 | 136 | ); |
| 137 | + $this->productReader->loadProducts($skus, $cart->getStoreId()); |
146 | 138 | foreach ($cartItems as $cartItemPosition => $cartItem) { |
147 | 139 | $errors = $this->addItemToCart($cart, $cartItem, $cartItemPosition); |
148 | 140 | if ($errors) { |
@@ -173,11 +165,7 @@ private function addItemToCart(Quote $cart, Data\CartItem $cartItem, int $cartIt |
173 | 165 | $cartItemPosition |
174 | 166 | ); |
175 | 167 | } else { |
176 | | - try { |
177 | | - $product = clone $this->productRepository->get($sku, false, $cart->getStoreId()); |
178 | | - } catch (NoSuchEntityException $e) { |
179 | | - $product = null; |
180 | | - } |
| 168 | + $product = $this->productReader->getProductBySku($sku); |
181 | 169 | if (!$product || !$product->isSaleable() || !$product->isAvailable()) { |
182 | 170 | $errors[] = $this->error->create( |
183 | 171 | __('Could not find a product with SKU "%sku"', ['sku' => $sku])->render(), |
|
0 commit comments