diff --git a/src/Sylius/Component/Core/Promotion/Checker/Rule/HasTaxonRuleChecker.php b/src/Sylius/Component/Core/Promotion/Checker/Rule/HasTaxonRuleChecker.php index 12fbf165cf5..abe89a0aa0b 100644 --- a/src/Sylius/Component/Core/Promotion/Checker/Rule/HasTaxonRuleChecker.php +++ b/src/Sylius/Component/Core/Promotion/Checker/Rule/HasTaxonRuleChecker.php @@ -13,6 +13,7 @@ use Sylius\Component\Core\Model\OrderInterface; use Sylius\Component\Core\Model\OrderItemInterface; +use Sylius\Component\Core\Model\ProductInterface; use Sylius\Component\Promotion\Checker\Rule\RuleCheckerInterface; use Sylius\Component\Promotion\Exception\UnsupportedTypeException; use Sylius\Component\Promotion\Model\PromotionSubjectInterface; @@ -39,10 +40,25 @@ public function isEligible(PromotionSubjectInterface $subject, array $configurat /* @var $item OrderItemInterface */ foreach ($subject->getItems() as $item) { - foreach ($item->getProduct()->getProductTaxons() as $productTaxon) { - if (in_array($productTaxon->getTaxon()->getCode(), $configuration['taxons'], true)) { + if ($this->hasProductValidTaxon($item->getProduct(), $configuration)) { + return true; + } + } + + return false; + } + + /** + * @param ProductInterface $product + * @param array $configuration + * + * @return bool + */ + private function hasProductValidTaxon(ProductInterface $product, array $configuration) + { + foreach ($product->getTaxons() as $taxon) { + if (in_array($taxon->getCode(), $configuration['taxons'], true)) { return true; - } } } diff --git a/src/Sylius/Component/Core/Promotion/Filter/TaxonFilter.php b/src/Sylius/Component/Core/Promotion/Filter/TaxonFilter.php index e1eddce519e..782e926dbab 100644 --- a/src/Sylius/Component/Core/Promotion/Filter/TaxonFilter.php +++ b/src/Sylius/Component/Core/Promotion/Filter/TaxonFilter.php @@ -45,8 +45,8 @@ public function filter(array $items, array $configuration) */ private function hasProductValidTaxon(ProductInterface $product, array $taxons) { - foreach ($product->getProductTaxons() as $productTaxon) { - if (in_array($productTaxon->getTaxon()->getCode(), $taxons)) { + foreach ($product->getTaxons() as $taxon) { + if (in_array($taxon->getCode(), $taxons, true)) { return true; } } diff --git a/src/Sylius/Component/Core/spec/Promotion/Checker/Rule/HasTaxonRuleCheckerSpec.php b/src/Sylius/Component/Core/spec/Promotion/Checker/Rule/HasTaxonRuleCheckerSpec.php index cddfff06b08..862c7083cac 100644 --- a/src/Sylius/Component/Core/spec/Promotion/Checker/Rule/HasTaxonRuleCheckerSpec.php +++ b/src/Sylius/Component/Core/spec/Promotion/Checker/Rule/HasTaxonRuleCheckerSpec.php @@ -43,14 +43,12 @@ function it_recognizes_a_subject_as_eligible_if_product_taxon_is_matched( OrderInterface $subject, OrderItemInterface $item, ProductInterface $bastardSword, - ProductTaxonInterface $bastardSwordProductTaxon, TaxonInterface $swords ) { $configuration = ['taxons' => ['swords']]; $swords->getCode()->willReturn('swords'); - $bastardSword->getProductTaxons()->willReturn([$bastardSwordProductTaxon]); - $bastardSwordProductTaxon->getTaxon()->willReturn($swords); + $bastardSword->getTaxons()->willReturn([$swords]); $item->getProduct()->willReturn($bastardSword); $subject->getItems()->willReturn([$item]); @@ -67,8 +65,7 @@ function it_recognizes_a_subject_as_eligible_if_a_product_taxon_is_matched_to_on $configuration = ['taxons' => ['swords', 'axes']]; $swords->getCode()->willReturn('swords'); - $bastardSword->getProductTaxons()->willReturn([$bastardSwordProductTaxon]); - $bastardSwordProductTaxon->getTaxon()->willReturn($swords); + $bastardSword->getTaxons()->willReturn([$swords]); $item->getProduct()->willReturn($bastardSword); $subject->getItems()->willReturn([$item]); @@ -85,8 +82,7 @@ function it_recognizes_a_subject_as_not_eligible_if_a_product_taxon_is_not_match $configuration = ['taxons' => ['swords', 'axes']]; $bows->getCode()->willReturn('bows'); - $reflexBow->getProductTaxons()->willReturn([$reflexBowProductTaxon]); - $reflexBowProductTaxon->getTaxon()->willReturn($bows); + $reflexBow->getTaxons()->willReturn([$bows]); $item->getProduct()->willReturn($reflexBow); $subject->getItems()->willReturn([$item]); diff --git a/src/Sylius/Component/Core/spec/Promotion/Filter/TaxonFilterSpec.php b/src/Sylius/Component/Core/spec/Promotion/Filter/TaxonFilterSpec.php index 7de6e5dbf2a..0cdfb492838 100644 --- a/src/Sylius/Component/Core/spec/Promotion/Filter/TaxonFilterSpec.php +++ b/src/Sylius/Component/Core/spec/Promotion/Filter/TaxonFilterSpec.php @@ -40,18 +40,14 @@ function it_filters_passed_order_items_with_given_configuration( ProductInterface $product1, ProductInterface $product2, TaxonInterface $taxon1, - TaxonInterface $taxon2, - ProductTaxonInterface $productTaxon1, - ProductTaxonInterface $productTaxon2 + TaxonInterface $taxon2 ) { $item1->getProduct()->willReturn($product1); - $product1->getProductTaxons()->willReturn([$productTaxon1]); - $productTaxon1->getTaxon()->willReturn($taxon1); + $product1->getTaxons()->willReturn([$taxon1]); $taxon1->getCode()->willReturn('taxon1'); $item2->getProduct()->willReturn($product2); - $product2->getProductTaxons()->willReturn([$productTaxon2]); - $productTaxon2->getTaxon()->willReturn($taxon2); + $product2->getTaxons()->willReturn([$taxon2]); $taxon2->getCode()->willReturn('taxon2'); $this->filter([$item1, $item2], ['filters' => ['taxons_filter' => ['taxons' => ['taxon1']]]])->shouldReturn([$item1]);