|
7 | 7 |
|
8 | 8 | namespace Magento\GraphQl\Bundle;
|
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\Quote\Model\QuoteIdToMaskedQuoteIdInterface; |
| 16 | +use Magento\Quote\Test\Fixture\GuestCart as GuestCartFixture; |
| 17 | +use Magento\TestFramework\Fixture\DataFixture; |
| 18 | +use Magento\TestFramework\Fixture\DataFixtureStorage; |
| 19 | +use Magento\TestFramework\Fixture\DataFixtureStorageManager; |
| 20 | +use Magento\TestFramework\Helper\Bootstrap; |
10 | 21 | use Magento\TestFramework\TestCase\GraphQlAbstract;
|
11 | 22 |
|
12 | 23 | class BundleProductMainPriceTest extends GraphQlAbstract
|
13 | 24 | {
|
| 25 | + /** |
| 26 | + * @var QuoteIdToMaskedQuoteIdInterface |
| 27 | + */ |
| 28 | + private $quoteIdToMaskedId; |
| 29 | + |
| 30 | + /** |
| 31 | + * @var DataFixtureStorage |
| 32 | + */ |
| 33 | + private $fixtures; |
| 34 | + |
| 35 | + protected function setUp(): void |
| 36 | + { |
| 37 | + $objectManager = Bootstrap::getObjectManager(); |
| 38 | + $this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class); |
| 39 | + $this->fixtures = DataFixtureStorageManager::getStorage(); |
| 40 | + } |
| 41 | + |
14 | 42 | public function getQuery()
|
15 | 43 | {
|
16 | 44 | $productSku = 'fixed_bundle_product_with_special_price';
|
@@ -129,4 +157,71 @@ public function testBundleProductPriceDetails(): void
|
129 | 157 | $this->assertEquals(40.0, $priceDetails['main_final_price']);
|
130 | 158 | $this->assertEquals(20, $priceDetails['discount_percentage']);
|
131 | 159 | }
|
| 160 | + |
| 161 | + #[ |
| 162 | + DataFixture(ProductFixture::class, ['sku' => 'simple1', 'price' => 10], as:'p1'), |
| 163 | + DataFixture(ProductFixture::class, ['sku' => 'simple2', 'price' => 20], as:'p2'), |
| 164 | + DataFixture(BundleSelectionFixture::class, ['sku' => '$p1.sku$'], as:'link1'), |
| 165 | + DataFixture(BundleSelectionFixture::class, ['sku' => '$p2.sku$'], as:'link2'), |
| 166 | + DataFixture(BundleOptionFixture::class, ['title' => 'Checkbox Options', 'type' => 'checkbox', |
| 167 | + 'required' => 1,'product_links' => ['$link1$', '$link2$']], 'opt1'), |
| 168 | + DataFixture(BundleOptionFixture::class, ['title' => 'Checkbox Options', 'type' => 'checkbox', |
| 169 | + 'required' => 1,'product_links' => ['$link1$', '$link2$']], 'opt2'), |
| 170 | + DataFixture( |
| 171 | + BundleProductFixture::class, |
| 172 | + ['sku' => 'bundle-product-multiselect-checkbox-options', '_options' => ['$opt1$', '$opt2$']], |
| 173 | + as:'bp1' |
| 174 | + ), |
| 175 | + DataFixture(GuestCartFixture::class, as: 'guestCart'), |
| 176 | + DataFixture( |
| 177 | + AddBundleProductToCart::class, |
| 178 | + [ |
| 179 | + 'cart_id' => '$guestCart.id$', |
| 180 | + 'product_id' => '$bp1.id$', |
| 181 | + 'selections' => [['$p1.id$'], ['$p2.id$']], |
| 182 | + 'qty' => 2 |
| 183 | + ] |
| 184 | + ) |
| 185 | + ] |
| 186 | + public function testCartBundleProductPriceDetails() |
| 187 | + { |
| 188 | + $guestCart = $this->fixtures->get('guestCart'); |
| 189 | + $guestQuoteMaskedId = $this->quoteIdToMaskedId->execute((int)$guestCart->getId()); |
| 190 | + |
| 191 | + $cartQuery = $this->getGuestCartQuery($guestQuoteMaskedId); |
| 192 | + $cartResponse = $this->graphQlMutation($cartQuery); |
| 193 | + $productPriceDetails = $cartResponse['cart']['itemsV2']['items'][0]['product']['price_details']; |
| 194 | + self::assertArrayHasKey('main_price', $productPriceDetails); |
| 195 | + self::assertArrayHasKey('main_final_price', $productPriceDetails); |
| 196 | + self::assertArrayHasKey('discount_percentage', $productPriceDetails); |
| 197 | + self::assertEquals(0, $productPriceDetails['main_price']); |
| 198 | + self::assertEquals(30, $productPriceDetails['main_final_price']); |
| 199 | + self::assertEquals(0, $productPriceDetails['discount_percentage']); |
| 200 | + } |
| 201 | + |
| 202 | + private function getGuestCartQuery(string $maskedId): string |
| 203 | + { |
| 204 | + return <<<QUERY |
| 205 | +{ |
| 206 | + cart(cart_id: "{$maskedId}") { |
| 207 | + itemsV2 { |
| 208 | + items { |
| 209 | + product { |
| 210 | + sku |
| 211 | + ... on BundleProduct { |
| 212 | + dynamic_price |
| 213 | + price_view |
| 214 | + price_details { |
| 215 | + main_price |
| 216 | + main_final_price |
| 217 | + discount_percentage |
| 218 | + } |
| 219 | + } |
| 220 | + } |
| 221 | + } |
| 222 | + } |
| 223 | + } |
| 224 | +} |
| 225 | +QUERY; |
| 226 | + } |
132 | 227 | }
|
0 commit comments