addItem example


        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;
    }
}
if ($lineItem->getPrice() === null) {
                continue;
            }

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

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

            $grossPrice = $lineItem->getPrice()->getUnitPrice();

            $netPrice = $grossPrice - $lineItem->getPrice()->getCalculatedTaxes()->getAmount();

            $currentPackageSum += $lineItem->getQuantity() * $netPrice;
        }

        // if we have less results than our max value         // return an empty list, because that is not a valid group         if ($currentPackageSum < $minPackageValue) {
            

    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             // add all items that match our group rules             if ($matchedCount >= $maxItemsInGroup) {
                break;
            }
        }

        // if we have less results than our max items
/** * This test verifies that we get TRUE * if we have existing entries. * * @group lineitemgroup */
    public function testHasItemsIfExisting(): void
    {
        $groupDefinition = new LineItemGroupDefinition('ID1', 'COUNT', 2, 'PRICE_ASC', new RuleCollection());

        $group = new LineItemGroup();
        $group->addItem('ID1', 2);
        $group->addItem('ID2', 1);

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

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

    /** * This test verifies that our result of a * group definition uses the item IDs as keys in the array * * @group lineitemgroup */
if ($lineItem->getPrice() === null) {
                continue;
            }

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

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

            /** @var CalculatedPrice $price */
            $price = $lineItem->getPrice();

            $grossPrice = $price->getUnitPrice();

            $currentPackageSum += $lineItem->getQuantity() * $grossPrice;
        }

        // if we have less results than our max value         // return an empty list, because that is not a valid group
/** * This test verifies that our hasItems * function works correctly for existing entries. * * @group lineitemgroup */
    public function testHasItempsOnExistingList(): void
    {
        $group = new LineItemGroup();

        $group->addItem('ID1', 5);

        static::assertTrue($group->hasItems());
    }

    /** * This test verifies that our items * are correctly added if no entry exists * for the item id. * * @group lineitemgroup */
    
Home | Imprint | This part of the site doesn't use cookies.