Skip to content

Commit 9886b75

Browse files
committed
ACP2E-2376: added integration test for configurable and bundle product
1 parent 1f04a2f commit 9886b75

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

dev/tests/integration/testsuite/Magento/SalesRule/Model/Quote/DiscountTest.php

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,15 @@
77

88
namespace Magento\SalesRule\Model\Quote;
99

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;
1014
use Magento\Catalog\Test\Fixture\Category as CategoryFixture;
1115
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;
1219
use Magento\Framework\Api\SearchCriteriaBuilder;
1320
use Magento\Framework\Exception\NoSuchEntityException;
1421
use Magento\Framework\ObjectManagerInterface;
@@ -390,4 +397,90 @@ public function testDiscountOnSimpleProductWithDiscardSubsequentRule(): void
390397
$this->assertEqualsCanonicalizing([$rule2Id], explode(',', $items[$product3Id]->getAppliedRuleIds()));
391398
$this->assertEqualsCanonicalizing([$rule3Id], explode(',', $items[$product4Id]->getAppliedRuleIds()));
392399
}
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() {
423+
$quote = $this->fixtures->get('cart');
424+
$this->assertEquals(50, $quote->getGrandTotal());
425+
$this->assertEquals(50, $quote->getSubtotalWithDiscount());
426+
$this->assertEquals(100, $quote->getSubtotal());
427+
428+
$quote->getAllItems();
429+
430+
//emulate a plugin on afterGetPrice
431+
foreach ($quote->getAllItems() as $item) {
432+
/** @var $item \Magento\Quote\Model\Quote\Item */
433+
$item->setPrice(200);
434+
}
435+
436+
$quote->collectTotals();
437+
438+
$this->assertEquals(50, $quote->getGrandTotal());
439+
$this->assertEquals(50, $quote->getSubtotalWithDiscount());
440+
$this->assertEquals(100, $quote->getSubtotal());
441+
}
442+
443+
#[
444+
AppIsolation(true),
445+
DataFixture(ProductFixture::class, ['sku' => 'simple1', 'price' => 10], as:'p1'),
446+
DataFixture(ProductFixture::class, ['sku' => 'simple2', 'price' => 20], as:'p2'),
447+
DataFixture(BundleSelectionFixture::class, ['sku' => '$p1.sku$', 'price' => 10, 'price_type' => 0], as:'link1'),
448+
DataFixture(BundleSelectionFixture::class, ['sku' => '$p2.sku$', 'price' => 25, 'price_type' => 1], as:'link2'),
449+
DataFixture(BundleOptionFixture::class, ['title' => 'Checkbox Options', 'type' => 'checkbox',
450+
'required' => 1,'product_links' => ['$link1$', '$link2$']], 'opt1'),
451+
DataFixture(BundleOptionFixture::class, ['title' => 'Multiselect Options', 'type' => 'multi',
452+
'required' => 1,'product_links' => ['$link1$', '$link2$']], 'opt2'),
453+
DataFixture(
454+
BundleProductFixture::class,
455+
['sku' => 'bundle-product-multiselect-checkbox-options','price' => 50,'price_type' => 1,
456+
'_options' => ['$opt1$', '$opt2$']],
457+
as:'bp1'
458+
),
459+
DataFixture(
460+
ProductConditionFixture::class,
461+
['attribute' => 'sku', 'value' => 'bundle-product-multiselect-checkbox-options'],
462+
as:'cond1'
463+
),
464+
DataFixture(
465+
RuleFixture::class,
466+
['simple_action' => Rule::CART_FIXED_ACTION, 'discount_amount' => 50, 'actions' => ['$cond1$']],
467+
as:'rule1'
468+
),
469+
DataFixture(GuestCartFixture::class, as: 'cart'),
470+
DataFixture(
471+
AddBundleProductToCart::class,
472+
[
473+
'cart_id' => '$cart.id$',
474+
'product_id' => '$bp1.id$',
475+
'selections' => [['$p1.id$'], ['$p1.id$', '$p2.id$']],
476+
'qty' => 1
477+
],
478+
)
479+
]
480+
public function testFixedAmountWholeCartDiscountOnBundleProduct() {
481+
$quote = $this->fixtures->get('cart');
482+
$this->assertEquals(32.5, $quote->getGrandTotal());
483+
$this->assertEquals(32.5, $quote->getSubtotalWithDiscount());
484+
$this->assertEquals(82.5, $quote->getSubtotal());
485+
}
393486
}

0 commit comments

Comments
 (0)