|
7 | 7 |
|
8 | 8 | namespace Magento\GraphQl\Quote\Customer;
|
9 | 9 |
|
| 10 | +use Magento\Bundle\Test\Fixture\AddProductToCart as AddBundleProductToCart; |
| 11 | +use Magento\Bundle\Test\Fixture\Link as BundleSelectionFixture; |
| 12 | +use Magento\Bundle\Test\Fixture\Option as BundleOptionFixture; |
| 13 | +use Magento\Bundle\Test\Fixture\Product as BundleProductFixture; |
| 14 | +use Magento\Catalog\Test\Fixture\Product as ProductFixture; |
| 15 | +use Magento\Customer\Test\Fixture\Customer; |
10 | 16 | use Magento\Quote\Model\QuoteFactory;
|
11 | 17 | use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
|
12 | 18 | use Magento\Quote\Model\ResourceModel\Quote as QuoteResource;
|
| 19 | +use Magento\Quote\Test\Fixture\CustomerCart; |
| 20 | +use Magento\Quote\Test\Fixture\GuestCart as GuestCartFixture; |
| 21 | +use Magento\TestFramework\Fixture\DataFixture; |
| 22 | +use Magento\TestFramework\Fixture\DataFixtureStorage; |
| 23 | +use Magento\TestFramework\Fixture\DataFixtureStorageManager; |
| 24 | +use Magento\TestFramework\Fixture\DbIsolation; |
13 | 25 | use Magento\TestFramework\Helper\Bootstrap;
|
14 | 26 | use Magento\TestFramework\TestCase\GraphQlAbstract;
|
15 | 27 | use Magento\Integration\Api\CustomerTokenServiceInterface;
|
@@ -39,13 +51,31 @@ class MergeCartsTest extends GraphQlAbstract
|
39 | 51 | */
|
40 | 52 | private $customerTokenService;
|
41 | 53 |
|
| 54 | + /** |
| 55 | + * @var DataFixtureStorage |
| 56 | + */ |
| 57 | + private $fixtures; |
| 58 | + |
| 59 | + /** |
| 60 | + * @var \Magento\Quote\Model\QuoteIdMaskFactory |
| 61 | + */ |
| 62 | + private $quoteIdMaskedFactory; |
| 63 | + |
| 64 | + /** |
| 65 | + * @var \Magento\Quote\Model\ResourceModel\Quote\QuoteIdMask |
| 66 | + */ |
| 67 | + private $quoteIdMaskedResource; |
| 68 | + |
42 | 69 | protected function setUp(): void
|
43 | 70 | {
|
44 | 71 | $objectManager = Bootstrap::getObjectManager();
|
45 | 72 | $this->quoteResource = $objectManager->get(QuoteResource::class);
|
46 | 73 | $this->quoteFactory = $objectManager->get(QuoteFactory::class);
|
47 | 74 | $this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class);
|
48 | 75 | $this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class);
|
| 76 | + $this->fixtures = DataFixtureStorageManager::getStorage(); |
| 77 | + $this->quoteIdMaskedFactory = $objectManager->get(\Magento\Quote\Model\QuoteIdMaskFactory::class); |
| 78 | + $this->quoteIdMaskedResource = $objectManager->get(\Magento\Quote\Model\ResourceModel\Quote\QuoteIdMask::class); |
49 | 79 | }
|
50 | 80 |
|
51 | 81 | protected function tearDown(): void
|
@@ -101,6 +131,75 @@ public function testMergeGuestWithCustomerCart()
|
101 | 131 | self::assertEquals(1, $item2['quantity']);
|
102 | 132 | }
|
103 | 133 |
|
| 134 | + #[ |
| 135 | + DataFixture(ProductFixture::class, ['sku' => 'simple1', 'price' => 10], as:'p1'), |
| 136 | + DataFixture(ProductFixture::class, ['sku' => 'simple2', 'price' => 20], as:'p2'), |
| 137 | + DataFixture(BundleSelectionFixture::class, ['sku' => '$p1.sku$', 'price' => 10, 'price_type' => 0], as:'link1'), |
| 138 | + DataFixture(BundleSelectionFixture::class, ['sku' => '$p2.sku$', 'price' => 25, 'price_type' => 0], as:'link2'), |
| 139 | + DataFixture(BundleOptionFixture::class, ['title' => 'Checkbox Options', 'type' => 'checkbox', |
| 140 | + 'required' => 1,'product_links' => ['$link1$', '$link2$']], 'opt1'), |
| 141 | + DataFixture(BundleOptionFixture::class, ['title' => 'Checkbox Options', 'type' => 'checkbox', |
| 142 | + 'required' => 1,'product_links' => ['$link1$', '$link2$']], 'opt2'), |
| 143 | + DataFixture( |
| 144 | + BundleProductFixture::class, |
| 145 | + ['sku' => 'bundle-product-multiselect-checkbox-options','price' => 50,'price_type' => 1, |
| 146 | + '_options' => ['$opt1$', '$opt2$']], |
| 147 | + as:'bp1' |
| 148 | + ), |
| 149 | + DataFixture(Customer::class, ['email' => 'me@example.com'], as: 'customer'), |
| 150 | + DataFixture(CustomerCart::class, ['customer_id' => '$customer.id$'], as: 'customerCart'), |
| 151 | + DataFixture( |
| 152 | + AddBundleProductToCart::class, |
| 153 | + [ |
| 154 | + 'cart_id' => '$customerCart.id$', |
| 155 | + 'product_id' => '$bp1.id$', |
| 156 | + 'selections' => [['$p1.id$'], ['$p2.id$']], |
| 157 | + 'qty' => 1 |
| 158 | + ] |
| 159 | + ), |
| 160 | + DataFixture(GuestCartFixture::class, as: 'guestCart'), |
| 161 | + DataFixture( |
| 162 | + AddBundleProductToCart::class, |
| 163 | + [ |
| 164 | + 'cart_id' => '$guestCart.id$', |
| 165 | + 'product_id' => '$bp1.id$', |
| 166 | + 'selections' => [['$p1.id$'], ['$p2.id$']], |
| 167 | + 'qty' => 2 |
| 168 | + ] |
| 169 | + ) |
| 170 | + ] |
| 171 | + public function testMergeGuestWithCustomerCartBundleProduct() |
| 172 | + { |
| 173 | + $guestCart = $this->fixtures->get('guestCart'); |
| 174 | + $guestQuoteMaskedId = $this->quoteIdToMaskedId->execute((int)$guestCart->getId()); |
| 175 | + |
| 176 | + $customerCart = $this->fixtures->get('customerCart'); |
| 177 | + $customerCartId = (int)$customerCart->getId(); |
| 178 | + $customerQuoteMaskedId = $this->quoteIdToMaskedId->execute($customerCartId); |
| 179 | + if (!$customerQuoteMaskedId) { |
| 180 | + $quoteIdMask = $this->quoteIdMaskedFactory->create()->setQuoteId($customerCartId); |
| 181 | + $this->quoteIdMaskedResource->save($quoteIdMask); |
| 182 | + $customerQuoteMaskedId = $this->quoteIdToMaskedId->execute($customerCartId); |
| 183 | + } |
| 184 | + |
| 185 | + $queryHeader = $this->getHeaderMap('me@example.com', 'password'); |
| 186 | + $cartMergeQuery = $this->getCartMergeMutation($guestQuoteMaskedId, $customerQuoteMaskedId); |
| 187 | + $mergeResponse = $this->graphQlMutation($cartMergeQuery, [], '', $queryHeader); |
| 188 | + self::assertArrayHasKey('mergeCarts', $mergeResponse); |
| 189 | + |
| 190 | + $cartResponse = $mergeResponse['mergeCarts']; |
| 191 | + self::assertArrayHasKey('items', $cartResponse); |
| 192 | + self::assertCount(1, $cartResponse['items']); |
| 193 | + $cartResponse = $this->graphQlMutation($this->getCartQuery($customerQuoteMaskedId), [], '', $queryHeader); |
| 194 | + |
| 195 | + self::assertArrayHasKey('cart', $cartResponse); |
| 196 | + self::assertArrayHasKey('items', $cartResponse['cart']); |
| 197 | + self::assertCount(1, $cartResponse['cart']['items']); |
| 198 | + $item1 = $cartResponse['cart']['items'][0]; |
| 199 | + self::assertArrayHasKey('quantity', $item1); |
| 200 | + self::assertEquals(3, $item1['quantity']); |
| 201 | + } |
| 202 | + |
104 | 203 | /**
|
105 | 204 | * @magentoApiDataFixture Magento/Checkout/_files/quote_with_virtual_product_saved.php
|
106 | 205 | * @magentoApiDataFixture Magento/Customer/_files/customer.php
|
|
0 commit comments