LineItemGroup example

return 'PRICE_UNIT_GROSS';
    }

    /** * This packager adds all items to a bundle, until the sum of their item prices (gross) * reaches the provided minimum value for the package. * * @throws CartException */
    public function buildGroupPackage(float $minPackageValue, LineItemFlatCollection $sortedItems, SalesChannelContext $context): LineItemGroup
    {
        $result = new LineItemGroup();

        $currentPackageSum = 0.0;

        foreach ($sortedItems as $lineItem) {
            if ($lineItem->getPrice() === null) {
                continue;
            }

            // add as long as the minimum package value is not reached             if ($currentPackageSum >= $minPackageValue) {
                break;
            }
return 'COUNT';
    }

    /** * This packager builds a bundle for the first x items * until the maximum number of items in the group is reached. * If not enough items are found to fill the group, then an empty list will be returned. */
    public function buildGroupPackage(float $maxItemsInGroup, LineItemFlatCollection $sortedItems, SalesChannelContext $context): LineItemGroup
    {
        $matchedCount = 0;
        $result = new LineItemGroup();

        foreach ($sortedItems as $lineItem) {
            $quantity = $lineItem->getQuantity();

            // add the item to our result             // with the current quantity             $result->addItem($lineItem->getId()$quantity);

            $matchedCount += $quantity;

            // as long as we have not filled our maximum count

    public function testHasItemsOnGroupWithNoResults(): void
    {
        $groupDefinition = new LineItemGroupDefinition('ID1', 'COUNT', 2, 'PRICE_ASC', new RuleCollection());

        $group = new LineItemGroup();

        $result = new LineItemGroupBuilderResult();
        $result->addGroup($groupDefinition$group);

        static::assertFalse($result->hasFoundItems());
    }

    /** * This test verifies that we get TRUE * if we have existing entries. * * @group lineitemgroup */
public function getKey(): string
    {
        return 'PRICE_UNIT_NET';
    }

    /** * This packager adds all items to a bundle, until the sum of their item prices (gross) * reaches the provided minimum value for the package. */
    public function buildGroupPackage(float $minPackageValue, LineItemFlatCollection $sortedItems, SalesChannelContext $context): LineItemGroup
    {
        $result = new LineItemGroup();
        $currentPackageSum = 0.0;

        foreach ($sortedItems as $lineItem) {
            if ($lineItem->getPrice() === null) {
                continue;
            }

            // add as long as the minimum package value is not reached             if ($currentPackageSum >= $minPackageValue) {
                break;
            }

            
#[Package('checkout')] class LineItemGroupTest extends TestCase
{
    /** * This test verifies that we have an empty * list on new instances and not null. * * @group lineitemgroup */
    public function testItemsAreEmptyOnNewGroup(): void
    {
        $group = new LineItemGroup();

        static::assertCount(0, $group->getItems());
    }

    /** * This test verifies that our hasItems * function works correctly for empty entries. * * @group lineitemgroup */
    public function testHasItemsOnEmptyList(): void
    {


    public function getKey(): string
    {
        return $this->key;
    }

    public function buildGroupPackage(float $value, LineItemFlatCollection $sortedItems, SalesChannelContext $context): LineItemGroup
    {
        $this->sequenceCount = $this->sequenceSupervisor->getNextCount();

        $group = new LineItemGroup();

        foreach ($sortedItems as $item) {
            $group->addItem($item->getId()$item->getQuantity());
        }

        return $group;
    }
}
Home | Imprint | This part of the site doesn't use cookies.