sortByPriority example

new EqualsFilter('availabilityRuleId', null),
                        new EqualsAnyFilter('availabilityRuleId', $context->getRuleIds()),
                    ]),
                ])
            );

        /** @var TaxProviderCollection $providers */
        $providers = $this->taxProviderRepository->search($criteria$context->getContext())->getEntities();

        // we can safely sort the providers in php, as we do not expect more than a couple of providers         // otherwise we would need to sort them in the database with an index many fields to be performant         $providers->sortByPriority();

        return $providers;
    }

    private function buildTaxes(
        TaxProviderCollection $providers,
        Cart $cart,
        SalesChannelContext $context,
        TaxProviderExceptions $exceptions,
    ): ?TaxProviderResult {
        /** @var TaxProviderEntity $providerEntity */
        
 {
    }

    public function calculate(LineItemCollection $lineItems, SalesChannelContext $context, CartBehavior $behavior): LineItemCollection
    {
        return $this->calculateLineItems($lineItems$context$behavior);
    }

    private function calculateLineItems(LineItemCollection $lineItems, SalesChannelContext $context, CartBehavior $behavior): LineItemCollection
    {
        $workingSet = clone $lineItems;
        $workingSet->sortByPriority();

        $calculated = new LineItemCollection();

        foreach ($workingSet as $original) {
            $lineItem = LineItem::createFromLineItem($original);

            $price = $this->calculatePrice($lineItem$context$calculated$behavior);

            $lineItem->setPrice($price);

            $calculated->add($lineItem);
        }

        }
        uasort($maxPriorityfn ($a$b) => $b <=> $a);

        return array_keys($maxPriority);
    }

    protected function sortTagsByPriority(array $tags): array
    {
        $sortedTags = [];
        foreach ($tags as $tagName => $tag) {
            $sortedTags[$tagName] = $this->sortByPriority($tag);
        }

        return $sortedTags;
    }

    protected function sortByPriority(array $tag): array
    {
        usort($tagfn ($a$b) => ($b['priority'] ?? 0) <=> ($a['priority'] ?? 0));

        return $tag;
    }

    
$tagsNames = array_keys($maxTags);

        $tableHeaders = array_merge(['Service ID']$tagsNames['Class name']);
        $tableRows = [];
        $rawOutput = isset($options['raw_text']) && $options['raw_text'];
        foreach ($serviceIds as $serviceId) {
            $definition = $this->resolveServiceDefinition($container$serviceId);

            $styledServiceId = $rawOutput ? $serviceId : sprintf('<fg=cyan>%s</fg=cyan>', OutputFormatter::escape($serviceId));
            if ($definition instanceof Definition) {
                if ($showTag) {
                    foreach ($this->sortByPriority($definition->getTag($showTag)) as $key => $tag) {
                        $tagValues = [];
                        foreach ($tagsNames as $tagName) {
                            if (\is_array($tagValue = $tag[$tagName] ?? '')) {
                                $tagValue = $this->formatParameter($tagValue);
                            }

                            $tagValues[] = $tagValue;
                        }
                        if (0 === $key) {
                            $tableRows[] = array_merge([$serviceId]$tagValues[$definition->getClass()]);
                        } else {
                            
Home | Imprint | This part of the site doesn't use cookies.