getNet example


        $currency = $price->getCurrencyPrice($this->context->getCurrencyId());

        if (!$currency instanceof Price) {
            throw ProductException::invalidPriceDefinition();
        }

        if ($context->getTaxState() === CartPrice::TAX_STATE_GROSS) {
            return $currency->getGross();
        }

        return $currency->getNet();
    }
}


        return $value;
    }

    private function getPriceForTaxState(Price $price, SalesChannelContext $context): float
    {
        if ($context->getTaxState() === CartPrice::TAX_STATE_GROSS) {
            return $price->getGross();
        }

        return $price->getNet();
    }

    private function getListPrice(PriceCollection $prices, SalesChannelContext $context): ?float
    {
        $price = $prices->getCurrencyPrice($context->getCurrency()->getId());
        if ($price === null || $price->getListPrice() === null) {
            return null;
        }

        $value = $this->getPriceForTaxState($price->getListPrice()$context);

        
public function sortByPrice(Context $context): void
    {
        $this->sort(function DProductPriceEntity $a, ProductPriceEntity $b) use ($context) {
            $a = $a->getPrice()->first();
            $b = $b->getPrice()->first();

            if ($context->getTaxState() === CartPrice::TAX_STATE_GROSS) {
                return ($a ? $a->getGross() : 0) <=> ($b ? $b->getGross() : 0);
            }

            return ($a ? $a->getNet() : 0) <=> ($b ? $b->getNet() : 0);
        });
    }

    protected function getExpectedClass(): string
    {
        return ProductPriceEntity::class;
    }
}
/** @var ProductEntity $product */
        $product = $this->productRepository->search((new Criteria([$productId]))->addAssociation('prices')$context)->first();

        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());

        


        return $value;
    }

    private function getPriceForTaxState(Price $price, SalesChannelContext $context): float
    {
        if ($context->getTaxState() === CartPrice::TAX_STATE_GROSS) {
            return $price->getGross();
        }

        return $price->getNet();
    }

    private function getMatchingPriceOfRule(Delivery $delivery, SalesChannelContext $context, ShippingMethodPriceCollection $shippingPrices): ?CalculatedPrice
    {
        $shippingPrices->sort(
            function DShippingMethodPriceEntity $priceEntityA, ShippingMethodPriceEntity $priceEntityB) use ($context) {
                /** @var PriceCollection $priceCollectionA */
                $priceCollectionA = $priceEntityA->getCurrencyPrice();
                $priceA = $this->getCurrencyPrice($priceCollectionA$context);

                /** @var PriceCollection $priceCollectionB */
                
throw CartException::discountTypeNotSupported($key$type);
        }
        if (!$value instanceof PriceCollection) {
            throw CartException::absoluteDiscountMissingPriceCollection($key);
        }
        if (!$value->has(Defaults::CURRENCY)) {
            throw CartException::missingDefaultPriceCollectionForDiscount($key);
        }

        foreach ($value as $price) {
            $price->setGross(\abs($price->getGross()) * -1);
            $price->setNet(\abs($price->getNet()) * -1);

            if (!$price->getListPrice()) {
                continue;
            }
            $price->getListPrice()->setGross(\abs($price->getListPrice()->getGross()) * -1);
            $price->getListPrice()->setNet(\abs($price->getListPrice()->getNet()) * -1);
        }

        return new CurrencyPriceDefinition($value);
    }
}
return $this->linked;
    }

    public function setLinked(bool $linked): void
    {
        $this->linked = $linked;
    }

    public function add(self $price): void
    {
        $this->gross += $price->getGross();
        $this->net += $price->getNet();
    }

    public function getCurrencyId(): string
    {
        return $this->currencyId;
    }

    public function setCurrencyId(string $currencyId): void
    {
        $this->currencyId = $currencyId;
    }

    
 {
    }

    public function calculate(PriceCollection $price, CalculatedPriceCollection $prices, SalesChannelContext $context, int $quantity = 1): CalculatedPrice
    {
        $currency = $price->getCurrencyPrice($context->getCurrencyId());

        if (!$currency) {
            throw CartException::invalidPriceDefinition();
        }

        $value = $context->getTaxState() === CartPrice::TAX_STATE_GROSS ? $currency->getGross() : $currency->getNet();

        if ($currency->getCurrencyId() !== $context->getCurrencyId()) {
            $value *= $context->getCurrency()->getFactor();
        }

        $taxRules = $this->percentageTaxRuleBuilder->buildRules($prices->sum());

        $definition = new QuantityPriceDefinition($value$taxRules$quantity);

        return $this->priceCalculator->calculate($definition$context);
    }
}
$invoiceAmount += $price * $detail->getQuantity();

            $tax = $detail->getTax();

            $taxValue = $detail->getTaxRate();

            // Additional tax checks required for sw-2238, sw-2903 and sw-3164             if ($tax && $tax->getId() !== 0 && $tax->getId() !== null && $tax->getTax() !== null) {
                $taxValue = (float) $tax->getTax();
            }

            if ($order->getNet()) {
                $invoiceAmountNet += $this->rounding->round($price$taxValue$detail->getQuantity());
            } else {
                $invoiceAmountNet += round(($price * $detail->getQuantity()) / (100 + $taxValue) * 100, 2);
            }
        }

        if ($order->getTaxFree()) {
            $order->setInvoiceAmountNet($invoiceAmount + $order->getInvoiceShippingNet());
            $order->setInvoiceAmount($order->getInvoiceAmountNet());
        } elseif ($order->getNet()) {
            $order->setInvoiceAmountNet($invoiceAmount + $order->getInvoiceShippingNet());
            
throw CartException::surchargeTypeNotSupported($key$type);
        }
        if (!$value instanceof PriceCollection) {
            throw CartException::absoluteSurchargeMissingPriceCollection($key);
        }
        if (!$value->has(Defaults::CURRENCY)) {
            throw CartException::missingDefaultPriceCollectionForSurcharge($key);
        }

        foreach ($value as $price) {
            $price->setGross(\abs($price->getGross()));
            $price->setNet(\abs($price->getNet()));

            if (!$price->getListPrice()) {
                continue;
            }
            $price->getListPrice()->setGross(\abs($price->getListPrice()->getGross()));
            $price->getListPrice()->setNet(\abs($price->getListPrice()->getNet()));
        }

        return new CurrencyPriceDefinition($value);
    }
}
CartPrice::TAX_STATE_GROSS,
            99.99
        );

        $stubs = $this->createMock(ScriptPriceStubs::class);
        $price = new PriceCollection([]);

        $stubs->method('build')->willReturn($price);

        $facade = new CartPriceFacade($original$stubs);

        static::assertEquals(100, $facade->getNet());
        static::assertEquals(200, $facade->getTotal());
        static::assertEquals(200, $facade->getRounded());
        static::assertEquals(300, $facade->getPosition());
        static::assertEquals(99.99, $facade->getRaw());

        static::assertSame($price$facade->create([]));
    }
}

                'id' => $id,
                'price' => [['currencyId' => Defaults::CURRENCY, 'gross' => 1000, 'net' => 1000, 'linked' => false]],
            ],
        ]$versionContext);

        $product = $this->productRepository->search(new Criteria([$id])$context)->first();
        static::assertInstanceOf(ProductEntity::class$product);
        $price = $product->getCurrencyPrice(Defaults::CURRENCY);
        static::assertInstanceOf(Price::class$price);
        static::assertEquals(100, $price->getGross());
        static::assertEquals(10, $price->getNet());

        $product = $this->productRepository->search(new Criteria([$id])$versionContext)->first();
        static::assertInstanceOf(ProductEntity::class$product);
        $price = $product->getCurrencyPrice(Defaults::CURRENCY);
        static::assertInstanceOf(Price::class$price);
        static::assertEquals(1000, $price->getGross());
        static::assertEquals(1000, $price->getNet());

        $this->productRepository->merge($versionId$context);

        $product = $this->productRepository->search(new Criteria([$id])$context)->first();
        
static::assertSame($id$product->getId());

        static::assertEquals(new Price(Defaults::CURRENCY, 10, 15, false)$product->getCurrencyPrice(Defaults::CURRENCY));
        static::assertInstanceOf(ProductPriceCollection::class$product->getPrices());
        static::assertCount(2, $product->getPrices());

        $price = $product->getPrices()->get($ruleA);
        static::assertInstanceOf(ProductPriceEntity::class$price);
        $currencyPrice = $price->getPrice()->getCurrencyPrice(Defaults::CURRENCY);
        static::assertInstanceOf(Price::class$currencyPrice);
        static::assertSame(15.0, $currencyPrice->getGross());
        static::assertSame(10.0, $currencyPrice->getNet());

        $price = $product->getPrices()->get($ruleB);
        static::assertInstanceOf(ProductPriceEntity::class$price);
        $currencyPrice = $price->getPrice()->getCurrencyPrice(Defaults::CURRENCY);
        static::assertInstanceOf(Price::class$currencyPrice);
        static::assertSame(10.0, $currencyPrice->getGross());
        static::assertSame(8.0, $currencyPrice->getNet());
    }

    public function testProductPricesSortByGrossPrice(): void
    {
        

        $currency = $price->getCurrencyPrice($this->context->getCurrencyId());

        if (!$currency instanceof Price) {
            throw CartException::invalidPriceDefinition();
        }

        if ($context->getTaxState() === CartPrice::TAX_STATE_GROSS) {
            return $currency->getGross();
        }

        return $currency->getNet();
    }

    private function overwrite(QuantityPriceDefinition $definition): void
    {
        if ($this->item instanceof LineItem) {
            $this->item->markModifiedByApp();

            $this->item->setPriceDefinition($definition);
        }

        $new = $this->priceStubs->calculateQuantity($definition$this->context);

        
$price = $entity->get('data');

        /** @var PriceCollection $price */
        static::assertInstanceOf(PriceCollection::class$price);

        $price = $price->getCurrencyPrice(Defaults::CURRENCY);
        /** @var Price $price */
        static::assertInstanceOf(Price::class$price);

        static::assertInstanceOf(Price::class$price->getListPrice());
        static::assertEquals(2, $price->getListPrice()->getNet());
    }

    public function testListPriceInCriteriaParts(): void
    {
        $context = WriteContext::createFromContext(Context::createDefaultContext());

        $ids = new TestDataCollection();

        $data = [
            [
                'id' => $ids->create('was'),
                
Home | Imprint | This part of the site doesn't use cookies.