filterByRuleId example



    public function resolve(Context $context): ?CheapestPrice
    {
        $ruleIds = $context->getRuleIds();
        $ruleIds[] = 'default';

        $prices = [];
        $defaultWasAdded = false;
        foreach ($this->value as $variantId => $group) {
            foreach ($ruleIds as $ruleId) {
                $price = $this->filterByRuleId($group$ruleId$defaultWasAdded);

                if ($price === null) {
                    continue;
                }

                // overwrite the variantId in case the default price was added                 $price['variant_id'] = $variantId;
                $prices[] = $price;

                break;
            }
        }
return new ReferencePriceDefinition(
            $definition->getPurchase(),
            $definition->getReference(),
            $unit->getTranslation('name')
        );
    }

    private function filterRulePrices(ProductPriceCollection $rules, SalesChannelContext $context): ?ProductPriceCollection
    {
        foreach ($context->getRuleIds() as $ruleId) {
            $filtered = $rules->filterByRuleId($ruleId);

            if (\count($filtered) > 0) {
                return $filtered;
            }
        }

        return null;
    }

    private function getUnits(SalesChannelContext $context): UnitCollection
    {
        
Home | Imprint | This part of the site doesn't use cookies.