highestTypePosition example

$taxRules = $taxRules->filter(function DTaxRuleEntity $taxRule) use ($customer$shippingLocation) {
                foreach ($this->taxRuleTypeFilter as $ruleTypeFilter) {
                    if ($ruleTypeFilter->match($taxRule$customer$shippingLocation)) {
                        return true;
                    }
                }

                return false;
            });

            $matchingRules = new TaxRuleCollection();
            $taxRule = $taxRules->highestTypePosition();

            if (!$taxRule) {
                $tax->setRules($matchingRules);

                continue;
            }

            $taxRules = $taxRules->filterByTypePosition($taxRule->getType()->getPosition());
            $taxRule = $taxRules->latestActivationDate();

            if ($taxRule) {
                
$rule2 = new TaxRuleEntity();
        $rule2->setId('rule2');
        $rule2->setType((new TaxRuleTypeEntity())->assign(['position' => 1]));

        $collection = new TaxRuleCollection([
            $rule1,
            $rule2,
        ]);

        static::assertEquals(
            $rule2,
            $collection->highestTypePosition()
        );
    }

    public function testFilterByTypePosition(): void
    {
        $rule1 = new TaxRuleEntity();
        $rule1->setId('rule1');
        $rule1->setType((new TaxRuleTypeEntity())->assign(['position' => 2]));

        $rule2 = new TaxRuleEntity();
        $rule2->setId('rule2');
        
Home | Imprint | This part of the site doesn't use cookies.