|
1 | 1 | <?php
|
2 | 2 | /**
|
3 |
| - * Copyright © Magento, Inc. All rights reserved. |
4 |
| - * See COPYING.txt for license details. |
| 3 | + * Copyright 2019 Adobe |
| 4 | + * All Rights Reserved. |
5 | 5 | */
|
6 | 6 | declare(strict_types=1);
|
7 | 7 |
|
|
12 | 12 | use Magento\Bundle\Test\Fixture\Option as BundleOptionFixture;
|
13 | 13 | use Magento\Bundle\Test\Fixture\Product as BundleProductFixture;
|
14 | 14 | use Magento\Catalog\Test\Fixture\Product as ProductFixture;
|
| 15 | +use Magento\Catalog\Test\Fixture\ProductStock as ProductStockFixture; |
15 | 16 | use Magento\Customer\Test\Fixture\Customer;
|
| 17 | +use Magento\Indexer\Test\Fixture\Indexer as IndexerFixture; |
16 | 18 | use Magento\Quote\Model\QuoteFactory;
|
17 | 19 | use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
|
18 | 20 | use Magento\Quote\Model\ResourceModel\Quote as QuoteResource;
|
| 21 | +use Magento\Quote\Test\Fixture\AddProductToCart; |
19 | 22 | use Magento\Quote\Test\Fixture\CustomerCart;
|
20 | 23 | use Magento\Quote\Test\Fixture\GuestCart as GuestCartFixture;
|
| 24 | +use Magento\TestFramework\Fixture\Config as ConfigFixture; |
21 | 25 | use Magento\TestFramework\Fixture\DataFixture;
|
22 | 26 | use Magento\TestFramework\Fixture\DataFixtureStorage;
|
23 | 27 | use Magento\TestFramework\Fixture\DataFixtureStorageManager;
|
24 |
| -use Magento\TestFramework\Fixture\DbIsolation; |
25 | 28 | use Magento\TestFramework\Helper\Bootstrap;
|
26 | 29 | use Magento\TestFramework\TestCase\GraphQlAbstract;
|
27 | 30 | use Magento\Integration\Api\CustomerTokenServiceInterface;
|
@@ -200,6 +203,101 @@ public function testMergeGuestWithCustomerCartBundleProduct()
|
200 | 203 | self::assertEquals(3, $item1['quantity']);
|
201 | 204 | }
|
202 | 205 |
|
| 206 | + #[ |
| 207 | + ConfigFixture('cataloginventory/options/backorders', 1), // 1 = BACKORDERS_YES_NOTIFY |
| 208 | + ConfigFixture('cataloginventory/item_options/use_config_backorders', 0), |
| 209 | + DataFixture(ProductFixture::class, [ |
| 210 | + 'extension_attributes' => [ |
| 211 | + 'stock_item' => [ |
| 212 | + 'use_config_backorders' => false, |
| 213 | + 'backorders' => 1, |
| 214 | + 'is_in_stock' => 1 |
| 215 | + ] |
| 216 | + ] |
| 217 | + ], as: 'product'), |
| 218 | + DataFixture( |
| 219 | + ProductStockFixture::class, |
| 220 | + [ |
| 221 | + 'prod_id' => '$product.id$', |
| 222 | + 'prod_qty' => 0 |
| 223 | + ] |
| 224 | + ), |
| 225 | + DataFixture(IndexerFixture::class), |
| 226 | + DataFixture(GuestCartFixture::class, as: 'guestCart'), |
| 227 | + DataFixture( |
| 228 | + AddProductToCart::class, |
| 229 | + [ |
| 230 | + 'cart_id' => '$guestCart.id$', |
| 231 | + 'product_id' => '$product.id$', |
| 232 | + 'qty' => 3 |
| 233 | + ] |
| 234 | + ), |
| 235 | + DataFixture(Customer::class, as: 'customer'), |
| 236 | + DataFixture(CustomerCart::class, ['customer_id' => '$customer.id$'], 'customerCart'), |
| 237 | + DataFixture( |
| 238 | + AddProductToCart::class, |
| 239 | + [ |
| 240 | + 'cart_id' => '$customerCart.id$', |
| 241 | + 'product_id' => '$product.id$', |
| 242 | + 'qty' => 2 |
| 243 | + ] |
| 244 | + ), |
| 245 | + ] |
| 246 | + public function testMergeGuestWithCustomerCartBackorderProduct() |
| 247 | + { |
| 248 | + $updatedQuantity = 5; //including 3 from guest cart and 2 from customer cart |
| 249 | + $guestCartId = (int)$this->fixtures->get('guestCart')->getId(); |
| 250 | + $customerCartId = (int)$this->fixtures->get('customerCart')->getId(); |
| 251 | + $customerEmail = $this->fixtures->get('customer')->getEmail(); |
| 252 | + $productSku = $this->fixtures->get('product')->getSku(); |
| 253 | + |
| 254 | + $guestQuoteMaskedId = $this->quoteIdToMaskedId->execute($guestCartId); |
| 255 | + $customerQuoteMaskedId = $this->quoteIdToMaskedId->execute($customerCartId); |
| 256 | + if (!$customerQuoteMaskedId) { |
| 257 | + $quoteIdMask = $this->quoteIdMaskedFactory->create()->setQuoteId($customerCartId); |
| 258 | + $this->quoteIdMaskedResource->save($quoteIdMask); |
| 259 | + $customerQuoteMaskedId = $this->quoteIdToMaskedId->execute($customerCartId); |
| 260 | + } |
| 261 | + |
| 262 | + $queryHeader = $this->getHeaderMap($customerEmail); |
| 263 | + $cartMergeQuery = $this->getCartMergeMutation($guestQuoteMaskedId, $customerQuoteMaskedId); |
| 264 | + |
| 265 | + $mergeResponse = $this->graphQlMutation($cartMergeQuery, [], '', $queryHeader); |
| 266 | + $this->assertEquals( |
| 267 | + [ |
| 268 | + "mergeCarts" => [ |
| 269 | + "items" => [ |
| 270 | + 0 => [ |
| 271 | + "quantity" => $updatedQuantity, |
| 272 | + "product" => [ |
| 273 | + "sku" => $productSku, |
| 274 | + ] |
| 275 | + ] |
| 276 | + ] |
| 277 | + ] |
| 278 | + ], |
| 279 | + $mergeResponse |
| 280 | + ); |
| 281 | + |
| 282 | + $cartQuery = $this->getCartQuery($customerQuoteMaskedId); |
| 283 | + $cartResponse = $this->graphQlMutation($cartQuery, [], '', $queryHeader); |
| 284 | + $this->assertEquals( |
| 285 | + [ |
| 286 | + "cart" => [ |
| 287 | + "items" => [ |
| 288 | + 0 => [ |
| 289 | + "quantity" => $updatedQuantity, |
| 290 | + "product" => [ |
| 291 | + "sku" => $productSku, |
| 292 | + ] |
| 293 | + ] |
| 294 | + ] |
| 295 | + ] |
| 296 | + ], |
| 297 | + $cartResponse |
| 298 | + ); |
| 299 | + } |
| 300 | + |
203 | 301 | /**
|
204 | 302 | * @magentoApiDataFixture Magento/Checkout/_files/quote_with_virtual_product_saved.php
|
205 | 303 | * @magentoApiDataFixture Magento/Customer/_files/customer.php
|
|
0 commit comments