|
9 | 9 |
|
10 | 10 | use Exception;
|
11 | 11 | use Magento\Catalog\Api\ProductRepositoryInterface;
|
12 |
| -use Magento\Catalog\Model\Product; |
13 |
| -use Magento\Framework\DataObject; |
14 |
| -use Magento\Quote\Model\Quote\Item; |
15 |
| -use Magento\Catalog\Model\Product\Type\AbstractType; |
16 | 12 | use Magento\Framework\Model\Context;
|
17 | 13 | use Magento\Framework\Event\ManagerInterface;
|
18 |
| -use Magento\Framework\Phrase; |
19 |
| -use Magento\Framework\Exception\LocalizedException; |
20 | 14 | use Magento\Framework\Exception\NoSuchEntityException;
|
21 | 15 | use Magento\Framework\GraphQl\Exception\GraphQlInputException;
|
22 | 16 | use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
|
@@ -90,13 +84,6 @@ public function execute(Quote $cart, array $cartItemData): void
|
90 | 84 |
|
91 | 85 | try {
|
92 | 86 | $result = $cart->addProduct($product, $this->buyRequestBuilder->build($cartItemData));
|
93 |
| - /* |
94 |
| - $result = $this->addProductToCartWithConcurrency( |
95 |
| - $cart, |
96 |
| - $product, |
97 |
| - $this->buyRequestBuilder->build($cartItemData) |
98 |
| - ); |
99 |
| - */ |
100 | 87 | } catch (Exception $e) {
|
101 | 88 | throw new GraphQlInputException(
|
102 | 89 | __(
|
@@ -134,89 +121,4 @@ private function extractSku(array $cartItemData): string
|
134 | 121 | }
|
135 | 122 | return (string)$cartItemData['data']['sku'];
|
136 | 123 | }
|
137 |
| - |
138 |
| - /** |
139 |
| - * @param Quote $cart |
140 |
| - * @param Product $product |
141 |
| - * @param DataObject $request |
142 |
| - * @return Item |
143 |
| - * @throws LocalizedException |
144 |
| - */ |
145 |
| - private function addProductToCartWithConcurrency(Quote $cart, Product $product, DataObject $request) : Item |
146 |
| - { |
147 |
| - if (!$product->isSalable()) { |
148 |
| - throw new LocalizedException( |
149 |
| - __('Product that you are trying to add is not available.') |
150 |
| - ); |
151 |
| - } |
152 |
| - $cartCandidates = $product->getTypeInstance()->prepareForCartAdvanced( |
153 |
| - $request, |
154 |
| - $product, |
155 |
| - AbstractType::PROCESS_MODE_FULL |
156 |
| - ); |
157 |
| - if (is_string($cartCandidates) || $cartCandidates instanceof Phrase) { |
158 |
| - throw new LocalizedException((string)$cartCandidates); |
159 |
| - } |
160 |
| - if (!is_array($cartCandidates)) { |
161 |
| - $cartCandidates = [$cartCandidates]; |
162 |
| - } |
163 |
| - $parentItem = null; |
164 |
| - $errors = []; |
165 |
| - $items = []; |
166 |
| - foreach ($cartCandidates as $candidate) { |
167 |
| - $stickWithinParent = $candidate->getParentProductId() ? $parentItem : null; |
168 |
| - $candidate->setStickWithinParent($stickWithinParent); |
169 |
| - $item = null; |
170 |
| - $itemsCollection = $cart->getItemsCollection(false); |
171 |
| - |
172 |
| - foreach ($itemsCollection as $item) { |
173 |
| - if (!$item->isDeleted() && $item->representProduct($product)) { |
174 |
| - break; |
175 |
| - } |
176 |
| - } |
177 |
| - |
178 |
| - if (!$item) { |
179 |
| - $item = $this->itemProcessor->init($candidate, $request); |
180 |
| - $item->setQuote($cart); |
181 |
| - $item->setOptions($candidate->getCustomOptions()); |
182 |
| - $item->setProduct($candidate); |
183 |
| - $cart->addItem($item); |
184 |
| - } |
185 |
| - $items[] = $item; |
186 |
| - |
187 |
| - if (!$parentItem) { |
188 |
| - $parentItem = $item; |
189 |
| - } |
190 |
| - if ($parentItem && $candidate->getParentProductId() && !$item->getParentItem()) { |
191 |
| - $item->setParentItem($parentItem); |
192 |
| - } |
193 |
| - |
194 |
| - $this->itemProcessor->prepare($item, $request, $candidate); |
195 |
| - |
196 |
| - if ($item->getHasError()) { |
197 |
| - $cart->deleteItem($item); |
198 |
| - foreach ($item->getMessage(false) as $message) { |
199 |
| - if (!in_array($message, $errors)) { |
200 |
| - $errors[] = $message; |
201 |
| - } |
202 |
| - } |
203 |
| - break; |
204 |
| - } |
205 |
| - |
206 |
| - $itemsToUpdate = []; |
207 |
| - foreach ($cart->getItems() as $itemToUpdate) { |
208 |
| - if ($itemToUpdate->getItemId() === $item->getItemId()) { |
209 |
| - $itemsToUpdate[] = $item; |
210 |
| - } else { |
211 |
| - $itemsToUpdate[] = $itemToUpdate; |
212 |
| - } |
213 |
| - } |
214 |
| - $cart->setItems($itemsToUpdate); |
215 |
| - } |
216 |
| - if (!empty($errors)) { |
217 |
| - throw new LocalizedException(__(implode("\n", $errors))); |
218 |
| - } |
219 |
| - $this->eventManager->dispatch('sales_quote_product_add_after', ['items' => $items]); |
220 |
| - return $parentItem; |
221 |
| - } |
222 | 124 | }
|
0 commit comments