Skip to content

Commit 4904ea6

Browse files
committed
Always apply rules to related products too
1 parent a28c56a commit 4904ea6

File tree

4 files changed

+21
-37
lines changed

4 files changed

+21
-37
lines changed

src/MShop/Rule/Manager/Base.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ public function apply( $items, string $type = 'catalog' )
4949
{
5050
foreach( $this->rules[$type] as $rule )
5151
{
52+
// Selection products are handled by rule providers
53+
$articleIds = $item->getType() === 'select' ? $item->getRefItems( 'product', null, 'default' )->keys() : [];
54+
$this->apply( $item->getRefItems( 'product' )->except( $articleIds ), $type );
55+
5256
if( $rule->apply( $item ) ) {
5357
break;
5458
}

src/MShop/Rule/Provider/Catalog/Percent.php

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,16 @@ public function getConfigBE() : array
6767
*/
6868
public function apply( \Aimeos\MShop\Product\Item\Iface $product ) : bool
6969
{
70-
$this->update( $product, (float) $this->getConfigValue( 'percent' ) );
70+
$percent = (float) $this->getConfigValue( 'percent', 0 );
71+
72+
if( $product->getType() === 'select' )
73+
{
74+
foreach( $product->getRefItems( 'product', null, 'default' ) as $subproduct ) {
75+
$this->update( $subproduct, $percent );
76+
}
77+
}
78+
79+
$this->update( $product, $percent );
7180
return $this->isLast();
7281
}
7382

@@ -86,21 +95,5 @@ protected function update( \Aimeos\MShop\Product\Item\Iface $product, float $per
8695
$diff = $value * $percent / 100;
8796
$price->setValue( $value + $diff )->setRebate( $diff < 0 ? abs( $diff ) : 0 );
8897
}
89-
90-
$varticles = map();
91-
$subproducts = $product->getRefItems( 'product' );
92-
93-
if( $product->getType() === 'select' )
94-
{
95-
$varticles = $product->getRefItems( 'product', null, 'default' );
96-
97-
foreach( $varticles as $subproduct ) {
98-
$this->update( $subproduct, $percent );
99-
}
100-
}
101-
102-
foreach( $subproducts->except( $varticles->keys() ) as $subproduct ) {
103-
$this->object()->apply( $subproduct );
104-
}
10598
}
10699
}

src/MShop/Rule/Provider/Catalog/Taxrate.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,13 @@ public function getConfigBE() : array
6767
*/
6868
public function apply( \Aimeos\MShop\Product\Item\Iface $product ) : bool
6969
{
70-
$product->getRefItems( 'price' )->setTaxrate( $this->getConfigValue( 'taxrate' ) );
70+
$taxrate = $this->getConfigValue( 'taxrate' );
71+
72+
foreach( $product->getRefItems( 'product', null, 'default' ) as $subproduct ) {
73+
$subproduct->getRefItems( 'price' )->setTaxrate( $taxrate );
74+
}
75+
76+
$product->getRefItems( 'price' )->setTaxrate( $taxrate );
7177
return $this->isLast();
7278
}
7379
}

tests/MShop/Rule/Provider/Catalog/PercentTest.php

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -67,25 +67,6 @@ public function testApply()
6767
}
6868

6969

70-
public function testApplyRebate()
71-
{
72-
$this->item->setConfig( ['percent' => '-10'] );
73-
$product = \Aimeos\MShop::create( $this->context, 'product' )->find( 'CNE', ['price', 'product'] );
74-
$price = $product->getRefItems( 'price' )->first();
75-
76-
$this->assertFalse( $this->object->apply( $product ) );
77-
$this->assertEquals( '16.20', $price?->getValue() );
78-
$this->assertEquals( '1.80', $price?->getRebate() );
79-
80-
foreach( $product->getRefItems( 'product' ) as $subproduct )
81-
{
82-
foreach( $subproduct->getRefItems( 'price' ) as $price ) {
83-
$this->assertGreaterThan( 0, $price->getRebate() );
84-
}
85-
}
86-
}
87-
88-
8970
public function testApplySelection()
9071
{
9172
$this->item->setConfig( ['percent' => '-10'] );

0 commit comments

Comments
 (0)