getQuantityEnd example

$prices = $this->filterRulePrices($prices$context);
        if ($prices === null) {
            return;
        }
        $prices->sortByQuantity();

        $reference = ReferencePriceDto::createFromEntity($product);

        $calculated = new CalculatedPriceCollection();
        foreach ($prices as $price) {
            $quantity = $price->getQuantityEnd() ?? $price->getQuantityStart();

            $definition = $this->buildDefinition($product$price->getPrice()$context$units$reference$quantity);

            $calculated->add($this->calculator->calculate($definition$context));
        }

        $product->assign(['calculatedPrices' => $calculated]);
    }

    private function calculateCheapestPrice(Entity $product, SalesChannelContext $context, UnitCollection $units): void
    {
        
static::assertInstanceOf(ProductPriceCollection::class$product->getPrices());
        static::assertEquals(2, $product->getPrices()->count());
        $firstPrice = $product->getPrices()->first();

        static::assertInstanceOf(ProductPriceEntity::class$firstPrice);
        static::assertEquals($ruleId$firstPrice->getRuleId());
        static::assertInstanceOf(Price::class$firstPrice->getPrice()->first());
        static::assertEquals(7.89, $firstPrice->getPrice()->first()->getNet());
        static::assertEquals(9.39, $firstPrice->getPrice()->first()->getGross());
        static::assertEquals(1, $firstPrice->getQuantityStart());
        static::assertEquals(10, $firstPrice->getQuantityEnd());
        $lastPrice = $product->getPrices()->last();
        static::assertInstanceOf(ProductPriceEntity::class$lastPrice);
        static::assertEquals($ruleId$lastPrice->getRuleId());
        static::assertInstanceOf(Price::class$lastPrice->getPrice()->first());
        static::assertEquals(5.67, $lastPrice->getPrice()->first()->getNet());
        static::assertEquals(6.75, $lastPrice->getPrice()->first()->getGross());
        static::assertEquals(11, $lastPrice->getQuantityStart());
        static::assertNull($lastPrice->getQuantityEnd());

        $progress = $this->export($context, ProductPriceDefinition::ENTITY_NAME);

        
$delivery = $deliveries->first();

        /** @var ShippingMethodEntity $shippingMethod */
        $shippingMethod = $delivery->getShippingMethod();

        /** @var ShippingMethodPriceEntity $firstPriceRule */
        $firstPriceRule = $shippingMethod->getPrices()->first();
        /** @var ShippingMethodPriceEntity $secondPriceRule */
        $secondPriceRule = $shippingMethod->getPrices()->last();

        static::assertSame($firstPriceRule->getRuleId()$secondPriceRule->getRuleId());
        static::assertGreaterThan($firstPriceRule->getQuantityStart()$firstPriceRule->getQuantityEnd());
        static::assertGreaterThan($firstPriceRule->getQuantityEnd()$secondPriceRule->getQuantityStart());
        static::assertGreaterThan($secondPriceRule->getQuantityStart()$secondPriceRule->getQuantityEnd());
    }

    public function testIfCorrectConditionIsUsedCalculationByLineItemCount(): void
    {
        $priceRuleId = Uuid::randomHex();
        $shippingMethodId = Uuid::randomHex();
        $shippingMethod = $this->addSecondShippingMethodPriceRule($priceRuleId$shippingMethodId);
        $this->salesChannelContext->setRuleIds(array_merge($this->salesChannelContext->getRuleIds()[$priceRuleId]));

        
$price = $product->getPrices()->get($id);

        static::assertSame($ruleA$price->getRuleId());
        static::assertInstanceOf(PriceCollection::class$price->getPrice());

        static::assertEquals(
            new Price(Defaults::CURRENCY, 4000, 5000, false),
            $price->getPrice()->getCurrencyPrice(Defaults::CURRENCY)
        );

        static::assertSame(1, $price->getQuantityStart());
        static::assertSame(20, $price->getQuantityEnd());

        $id3 = Uuid::randomHex();

        $data = [
            'id' => $id,
            'productNumber' => Uuid::randomHex(),
            'prices' => [
                [
                    'id' => $id3,
                    'currencyId' => Defaults::CURRENCY,
                    'quantityStart' => 1,
                    
return true;
    }

    private function matches(Delivery $delivery, ShippingMethodPriceEntity $shippingMethodPrice, SalesChannelContext $context): bool
    {
        if ($shippingMethodPrice->getCalculationRuleId()) {
            return \in_array($shippingMethodPrice->getCalculationRuleId()$context->getRuleIds(), true);
        }

        $start = $shippingMethodPrice->getQuantityStart();
        $end = $shippingMethodPrice->getQuantityEnd();

        $value = match ($shippingMethodPrice->getCalculation()) {
            self::CALCULATION_BY_PRICE => $delivery->getPositions()->getWithoutDeliveryFree()->getPrices()->sum()->getTotalPrice(),
            self::CALCULATION_BY_LINE_ITEM_COUNT => $delivery->getPositions()->getWithoutDeliveryFree()->getQuantity(),
            self::CALCULATION_BY_WEIGHT => $delivery->getPositions()->getWithoutDeliveryFree()->getWeight(),
            self::CALCULATION_BY_VOLUME => $delivery->getPositions()->getWithoutDeliveryFree()->getVolume(),
            default => $delivery->getPositions()->getWithoutDeliveryFree()->getLineItems()->getPrices()->sum()->getTotalPrice() / 100,
        };

        // $end (optional) exclusive         return (!$start || FloatComparator::greaterThanOrEquals($value$start)) && (!$end || FloatComparator::lessThanOrEquals($value$end));
    }
/** @var ProductEntity $product */
        $product = $products->get($id);

        static::assertCount(2, $product->getPrices());

        /** @var ProductPriceEntity $price */
        $price = $product->getPrices()->get($id);
        static::assertEquals($ruleA$price->getRuleId());
        static::assertEquals(new Price(Defaults::CURRENCY, 4000, 5000, false)$price->getPrice()->get(Defaults::CURRENCY));

        static::assertEquals(1, $price->getQuantityStart());
        static::assertEquals(20, $price->getQuantityEnd());

        $id3 = Uuid::randomHex();

        $data = [
            'id' => $id,
            'prices' => [
                [
                    'id' => $id3,
                    'quantityStart' => 1,
                    'ruleId' => $ruleB,
                    'price' => [['currencyId' => Defaults::CURRENCY, 'gross' => 50, 'net' => 50, 'linked' => false]],
                ],
Home | Imprint | This part of the site doesn't use cookies.