splitQuantities example

$itemsInGroup = $groupResult[$i]->getItems();

                $itemsInSet = array_merge($itemsInSet$itemsInGroup);
            }

            $units[] = new DiscountPackage(new LineItemQuantityCollection($itemsInSet));
        }

        $splitUnits = [];

        foreach ($units as $group) {
            $singleItems = $this->splitQuantities($group->getMetaData()->getElements());

            $splitUnits[] = new DiscountPackage(new LineItemQuantityCollection($singleItems));
        }

        return new DiscountPackageCollection($splitUnits);
    }

    /** * Gets a list of in-memory grupo definitions * from the list of group settings from the payload * * @param array<string, mixed> $groups * * @return LineItemGroupDefinition[] */

    public function findGroupPackages(array $groupDefinitions, Cart $cart, SalesChannelContext $context): LineItemGroupBuilderResult
    {
        $result = new LineItemGroupBuilderResult();

        // filter out all promotion items         $cartProducts = $this->lineItemProvider->getProducts($cart);

        // split quantities into separate line items         // so we have a real list of products like we would have         // them when holding it in our actual hands.         $restOfCart = $this->splitQuantities($cartProducts$context);

        foreach ($groupDefinitions as $groupDefinition) {
            $sorter = $this->registry->getSorter($groupDefinition->getSorterKey());
            $packager = $this->registry->getPackager($groupDefinition->getPackagerKey());

            // we have to sort our items first             // otherwise it would be a "random" order when             // adjusting the rest of our cart...             $restOfCart = $sorter->sort($restOfCart);

            // try as long as groups can be
/** @var string $groupId */
        $groupId = $discount->getPayloadValue('groupId');

        $definition = $this->getGroupDefinition($groupId$groups);

        $result = $this->groupBuilder->findGroupPackages([$definition]$cart$context);

        $units = [];

        $addedGroupCount = 0;
        foreach ($result->getGroupResult($definition) as $group) {
            $singleItems = $this->splitQuantities($group->getItems());

            $units[] = new DiscountPackage(new LineItemQuantityCollection($singleItems));

            ++$addedGroupCount;

            if ($addedGroupCount === $maximumSetCount) {
                break;
            }
        }

        return new DiscountPackageCollection($units);
    }
Home | Imprint | This part of the site doesn't use cookies.