|
7 | 7 |
|
8 | 8 | namespace Magento\SalesRule\Model\Quote;
|
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; |
10 | 14 | use Magento\Catalog\Test\Fixture\Category as CategoryFixture;
|
11 | 15 | use Magento\Catalog\Test\Fixture\Product as ProductFixture;
|
| 16 | +use Magento\ConfigurableProduct\Test\Fixture\AddProductToCart as AddConfigurableProductToCartFixture; |
| 17 | +use Magento\ConfigurableProduct\Test\Fixture\Attribute as AttributeFixture; |
| 18 | +use Magento\ConfigurableProduct\Test\Fixture\Product as ConfigurableProductFixture; |
12 | 19 | use Magento\Framework\Api\SearchCriteriaBuilder;
|
13 | 20 | use Magento\Framework\Exception\NoSuchEntityException;
|
14 | 21 | use Magento\Framework\ObjectManagerInterface;
|
@@ -390,4 +397,92 @@ public function testDiscountOnSimpleProductWithDiscardSubsequentRule(): void
|
390 | 397 | $this->assertEqualsCanonicalizing([$rule2Id], explode(',', $items[$product3Id]->getAppliedRuleIds()));
|
391 | 398 | $this->assertEqualsCanonicalizing([$rule3Id], explode(',', $items[$product4Id]->getAppliedRuleIds()));
|
392 | 399 | }
|
| 400 | + |
| 401 | + #[ |
| 402 | + AppIsolation(true), |
| 403 | + DataFixture(AttributeFixture::class, ['options' => [['label' => 'option1', 'sort_order' => 0]]], as: 'attr'), |
| 404 | + DataFixture(ProductFixture::class, ['price' => 100], as: 'p1'), |
| 405 | + DataFixture(ConfigurableProductFixture::class, ['_options' => ['$attr$'], '_links' => ['$p1$']], 'cp1'), |
| 406 | + DataFixture( |
| 407 | + ProductConditionFixture::class, |
| 408 | + ['attribute' => 'sku', 'value' => '$p1.sku$'], |
| 409 | + 'cond1' |
| 410 | + ), |
| 411 | + DataFixture( |
| 412 | + RuleFixture::class, |
| 413 | + ['simple_action' => Rule::CART_FIXED_ACTION, 'discount_amount' => 50, 'actions' => ['$cond1$']], |
| 414 | + 'rule1' |
| 415 | + ), |
| 416 | + DataFixture(GuestCartFixture::class, as: 'cart'), |
| 417 | + DataFixture( |
| 418 | + AddConfigurableProductToCartFixture::class, |
| 419 | + ['cart_id' => '$cart.id$', 'product_id' => '$cp1.id$', 'child_product_id' => '$p1.id$', 'qty' => 1], |
| 420 | + ) |
| 421 | + ] |
| 422 | + public function testFixedAmountWholeCartDiscountOnConfigurableProduct(): void |
| 423 | + { |
| 424 | + $quote = $this->fixtures->get('cart'); |
| 425 | + $this->assertEquals(50, $quote->getGrandTotal()); |
| 426 | + $this->assertEquals(50, $quote->getSubtotalWithDiscount()); |
| 427 | + $this->assertEquals(100, $quote->getSubtotal()); |
| 428 | + |
| 429 | + $quote->getAllItems(); |
| 430 | + |
| 431 | + //emulate a plugin on afterGetPrice |
| 432 | + foreach ($quote->getAllItems() as $item) { |
| 433 | + /** @var $item \Magento\Quote\Model\Quote\Item */ |
| 434 | + $item->setPrice(200); |
| 435 | + } |
| 436 | + |
| 437 | + $quote->collectTotals(); |
| 438 | + |
| 439 | + $this->assertEquals(50, $quote->getGrandTotal()); |
| 440 | + $this->assertEquals(50, $quote->getSubtotalWithDiscount()); |
| 441 | + $this->assertEquals(100, $quote->getSubtotal()); |
| 442 | + } |
| 443 | + |
| 444 | + #[ |
| 445 | + AppIsolation(true), |
| 446 | + DataFixture(ProductFixture::class, ['sku' => 'simple1', 'price' => 10], as:'p1'), |
| 447 | + DataFixture(ProductFixture::class, ['sku' => 'simple2', 'price' => 20], as:'p2'), |
| 448 | + DataFixture(BundleSelectionFixture::class, ['sku' => '$p1.sku$', 'price' => 10, 'price_type' => 0], as:'link1'), |
| 449 | + DataFixture(BundleSelectionFixture::class, ['sku' => '$p2.sku$', 'price' => 25, 'price_type' => 1], as:'link2'), |
| 450 | + DataFixture(BundleOptionFixture::class, ['title' => 'Checkbox Options', 'type' => 'checkbox', |
| 451 | + 'required' => 1,'product_links' => ['$link1$', '$link2$']], 'opt1'), |
| 452 | + DataFixture(BundleOptionFixture::class, ['title' => 'Multiselect Options', 'type' => 'multi', |
| 453 | + 'required' => 1,'product_links' => ['$link1$', '$link2$']], 'opt2'), |
| 454 | + DataFixture( |
| 455 | + BundleProductFixture::class, |
| 456 | + ['sku' => 'bundle-product-multiselect-checkbox-options','price' => 50,'price_type' => 1, |
| 457 | + '_options' => ['$opt1$', '$opt2$']], |
| 458 | + as:'bp1' |
| 459 | + ), |
| 460 | + DataFixture( |
| 461 | + ProductConditionFixture::class, |
| 462 | + ['attribute' => 'sku', 'value' => 'bundle-product-multiselect-checkbox-options'], |
| 463 | + as:'cond1' |
| 464 | + ), |
| 465 | + DataFixture( |
| 466 | + RuleFixture::class, |
| 467 | + ['simple_action' => Rule::CART_FIXED_ACTION, 'discount_amount' => 50, 'actions' => ['$cond1$']], |
| 468 | + as:'rule1' |
| 469 | + ), |
| 470 | + DataFixture(GuestCartFixture::class, as: 'cart'), |
| 471 | + DataFixture( |
| 472 | + AddBundleProductToCart::class, |
| 473 | + [ |
| 474 | + 'cart_id' => '$cart.id$', |
| 475 | + 'product_id' => '$bp1.id$', |
| 476 | + 'selections' => [['$p1.id$'], ['$p1.id$', '$p2.id$']], |
| 477 | + 'qty' => 1 |
| 478 | + ], |
| 479 | + ) |
| 480 | + ] |
| 481 | + public function testFixedAmountWholeCartDiscountOnBundleProduct(): void |
| 482 | + { |
| 483 | + $quote = $this->fixtures->get('cart'); |
| 484 | + $this->assertEquals(32.5, $quote->getGrandTotal()); |
| 485 | + $this->assertEquals(32.5, $quote->getSubtotalWithDiscount()); |
| 486 | + $this->assertEquals(82.5, $quote->getSubtotal()); |
| 487 | + } |
393 | 488 | }
|
0 commit comments