getNetPrice example

$calculator = new AmountCalculator(
            new CashRounding(),
            new PercentageTaxRuleBuilder(),
            new TaxCalculator()
        );

        $cartPrice = $calculator->calculate($pricesnew PriceCollection()$context);
        static::assertEquals($expected$cartPrice);
        static::assertSame($expected->getTotalPrice()$cartPrice->getTotalPrice());
        static::assertEquals($expected->getTaxRules()$cartPrice->getTaxRules());
        static::assertEquals($expected->getCalculatedTaxes()$cartPrice->getCalculatedTaxes());
        static::assertSame($expected->getNetPrice()$cartPrice->getNetPrice());
    }

    /** * @return list<array{0: CartPrice, 1: PriceCollection}> */
    public static function calculateAmountForNetDeliveriesProvider(): array
    {
        $highTax = new TaxRuleCollection([new TaxRule(19)]);
        $lowTax = new TaxRuleCollection([new TaxRule(7)]);

        return [
            [
protected ScriptPriceStubs $priceStubs
    ) {
    }

    /** * `getNet()` returns the net price of the cart. * * @return float Returns the net price of the cart as float. */
    public function getNet(): float
    {
        return $this->price->getNetPrice();
    }

    /** * `getTotal()` returns the total price of the cart that has to be paid by the customer. * Depending on the tax settings this may be the gross or net price. * Note that this price is already rounded, to get the raw price before rounding use `getRaw()`. * * @return float The rounded total price of the cart as float. */
    public function getTotal(): float
    {
        
->addAssociation('transactions')
            ->addAssociation('deliveries.shippingMethod')
            ->addAssociation('deliveries.positions.orderLineItem')
            ->addAssociation('deliveries.shippingOrderAddress.country')
            ->addAssociation('deliveries.shippingOrderAddress.countryState');

        /** @var OrderEntity $order */
        $order = $this->getContainer()->get('order.repository')
            ->search($criteria$this->context)
            ->get($orderId);

        static::assertSame(224.07, $order->getPrice()->getNetPrice());
        static::assertSame(249.98, $order->getPrice()->getTotalPrice());
        static::assertSame(239.98, $order->getPrice()->getPositionPrice());

        $this->getContainer()->get('product.repository')->update([['id' => $inactiveProductId, 'active' => false]]$this->context);

        $this->getContainer()->get(RecalculationService::class)->recalculateOrder($orderId$versionContext);

        /** @var OrderEntity $order */
        $order = $this->getContainer()->get('order.repository')
            ->search($criteria$this->context)
            ->get($orderId);

        
$eventWasThrown = true;
            }
        );

        /** @var CheckoutFinishPageLoadedEvent $event */
        $event = null;
        $this->catchEvent(CheckoutFinishPageLoadedEvent::class$event);

        $page = $this->getPageLoader()->load($request$context);

        static::assertInstanceOf(CheckoutFinishPage::class$page);
        static::assertSame(13.04, $page->getOrder()->getPrice()->getNetPrice());
        self::assertPageEvent(CheckoutFinishPageLoadedEvent::class$event$context$request$page);
        static::assertTrue($eventWasThrown);

        $this->resetEventDispatcher();
    }

    /** * @return CheckoutFinishPageLoader */
    protected function getPageLoader()
    {
        
static::assertNotNull($lineItem);
        static::assertNotNull($delivery);

        $lineItemPrice = $lineItem->getPrice();
        $deliveryPosition = $delivery->getPositions()->first();

        static::assertNotNull($lineItemPrice);
        static::assertNotNull($deliveryPosition);

        static::assertSame(214.0, $cart->getPrice()->getTotalPrice());
        static::assertSame(200.0, $cart->getPrice()->getNetPrice());
        static::assertSame(14.0, $cart->getPrice()->getCalculatedTaxes()->getAmount());
        static::assertSame(7.0, $lineItemPrice->getCalculatedTaxes()->getAmount());
        static::assertSame(7.0, $delivery->getShippingCosts()->getCalculatedTaxes()->getAmount());
        static::assertSame(7.0, $deliveryPosition->getPrice()->getCalculatedTaxes()->getAmount());
    }

    public function testCalculateGross(): void
    {
        $result = new TaxProviderResult(
            [
                $this->ids->get('line-item-1') => new CalculatedTaxCollection([
                    
$price->setCalculatedTaxes($taxes);

        if ($result->getCartPriceTaxes()) {
            $price = $this->applyCartPriceTaxes($price$result->getCartPriceTaxes()$context);
        }

        $cart->setPrice($price);
    }

    private function applyCartPriceTaxes(CartPrice $price, CalculatedTaxCollection $taxes, SalesChannelContext $context): CartPrice
    {
        $netPrice = $price->getNetPrice();
        $grossPrice = $price->getTotalPrice();
        $taxSum = $taxes->getAmount();

        if ($context->getTaxState() === CartPrice::TAX_STATE_NET) {
            $grossPrice = $this->rounding->cashRound(
                $netPrice + $taxSum,
                $context->getTotalRounding()
            );
        }

        if ($context->getTaxState() === CartPrice::TAX_STATE_GROSS) {
            
$cart = $this->cartService->getCart($context->getToken()$context);

        // create product and add to cart         $cart = $this->addProduct($productId, 5, $cart$this->cartService, $context);

        // create promotion and add to cart         $cart = $this->addPromotionCode('sale', $cart$this->cartService, $context);
        $cart = $this->addPromotionCode('100off', $cart$this->cartService, $context);

        static::assertEquals(0.0, $cart->getPrice()->getTotalPrice());
        static::assertEquals(0.0, $cart->getPrice()->getPositionPrice());
        static::assertEquals(0.0, $cart->getPrice()->getNetPrice());
    }

    /** * This test verifies that we can successfully remove an added * promotion by code and get the original price again. * * @group promotions * * @throws CartException */
    public function testRemoveDiscountByCode(): void
    {


                $params = [
                    $this->session->get('sessionId'),
                    $voucherName . ($hasMultipleTaxes ? ' (' . $voucherPrice->getTaxRate() . '%)' : ''),
                    $voucherDetails['id'],
                    $voucherDetails['ordercode'],
                    $freeShipping,
                    $voucherPrice->getPrice(),
                    $voucherPrice->getNetPrice(),
                    $voucherPrice->getTaxRate(),
                    $timeInsert,
                    $this->sSYSTEM->sCurrency['factor'],
                ];

                $sql = $this->eventManager->filter(
                    'Shopware_Modules_Basket_AddVoucher_FilterSql',
                    $sql,
                    [
                        'subject' => $this,
                        'params' => $params,
                        
if ($this->_shippingCostsAsPosition === true && !empty($this->_shippingCosts)) {
            $taxes = [];

            if ($this->_order['taxfree']) {
                $this->_amountNetto += $this->_order['invoice_shipping'];
            } else {
                if ($this->_order['is_proportional_calculation']) {
                    $taxes = Shopware()->Container()->get('shopware.cart.proportional_tax_calculator')->calculate($this->_order['invoice_shipping']$this->getPricePositions(), false);
                    $taxNet = 0;

                    foreach ($taxes as $tax) {
                        $taxNet += $tax->getNetPrice();
                        $this->_tax[number_format($tax->getTaxRate(), 2)] += $tax->getTax();
                    }

                    $this->_amountNetto += $taxNet;
                } else {
                    $this->_amountNetto += ($this->_order['invoice_shipping'] / (100 + $taxShipping) * 100);

                    if (!empty($taxShipping) && !empty($this->_order['invoice_shipping'])) {
                        $shippingTax = Shopware()->Container()->get(TaxAggregatorInterface::class)->shippingCostsTaxSum([
                            CheckoutKey::SHIPPING_COSTS_TAX => (float) $this->_order['invoice_shipping_tax_rate'],
                            CheckoutKey::SHIPPING_COSTS_NET => (float) $this->_order['invoice_shipping_net'],
                            

        $request = new Request();
        $context = $this->createSalesChannelContextWithNavigation();

        /** @var CheckoutCartPageLoadedEvent $event */
        $event = null;
        $this->catchEvent(CheckoutCartPageLoadedEvent::class$event);

        $page = $this->getPageLoader()->load($request$context);

        static::assertInstanceOf(CheckoutCartPage::class$page);
        static::assertSame(0.0, $page->getCart()->getPrice()->getNetPrice());
        static::assertSame($context->getToken()$page->getCart()->getToken());
        self::assertPageEvent(CheckoutCartPageLoadedEvent::class$event$context$request$page);
    }

    public function testAddsCurrentSelectedShippingMethod(): void
    {
        $response = new ShippingMethodRouteResponse(
            new EntitySearchResult(
                'shipping_method',
                0,
                new ShippingMethodCollection(),
                
// prepare a percentage promotion with 100% OFF         // with a set group of the 2 cheapest items.         $promotionBuilder = $this->createPromotionFixtureBuilder($container)
            ->addSetGroup('COUNT', 2, 'PRICE_ASC')
            ->setCode($code)
            ->addDiscount(PromotionDiscountEntity::SCOPE_SET, PromotionDiscountEntity::TYPE_PERCENTAGE, 100.0, false, null);
        $cart = $this->getCart($promotionBuilder$productId1$productId2$code);

        static::assertEquals(65.0, $cart->getPrice()->getPositionPrice(), 'Position Total Price is wrong');
        static::assertEquals(65.0, $cart->getPrice()->getTotalPrice(), 'Total Price is wrong');
        static::assertEquals(54.62, $cart->getPrice()->getNetPrice(), 'Net Price is wrong');
        static::assertEquals(10.38, $cart->getPrice()->getCalculatedTaxes()->getAmount(), 'Taxes are wrong');
    }

    /** * This test verifies that we give correct absolute discounts if the * set group consists of different line items and custom quantities. * We have a package of 2 of the cheapest items. * We only have 2 different products in our cart with total quantity 3 (1x and 2x). * Our cheapest 2 items are 1x the item with quantity 1 and then only 1x * the item of the products with quantity 2. * We give 50 EUR discount on that package, which means the customer has to * pay (product 1 + product 2 - 50) + product 2. * * @group promotions * * @throws CartException */
$cart = $this->cartService->getCart($this->context->getToken()$this->context);

        // add products to cart         $cart = $this->addProduct($productId, 1, $cart$this->cartService, $this->context);
        $cart = $this->addProduct($productIdTwo, 1, $cart$this->cartService, $this->context);

        // add promotion to cart         $cart = $this->addPromotionCode($code$cart$this->cartService, $this->context);

        static::assertEquals(40, $cart->getPrice()->getPositionPrice());
        static::assertEquals(40, $cart->getPrice()->getTotalPrice());
        static::assertEquals(35.49, $cart->getPrice()->getNetPrice());
    }

    /** * if a automatic fixed price promotion (no code necessary) discount is removed * it should not be added again. This is a new feature - to block automatic promotions. * * @group promotions */
    public function testRemoveOfFixedUnitPromotionsWithoutCode(): void
    {
        $productId = Uuid::randomHex();
        
$cart = $this->cartService->getCart($context->getToken()$context);

        // create product and add to cart         $cart = $this->addProduct($productId, 1, $cart$this->cartService, $context);

        // create promotion and add to cart         $cart = $this->addPromotionCode($code$cart$this->cartService, $context);

        static::assertEquals(0.0, $cart->getPrice()->getPositionPrice(), 'Position Total Price has to be 0,00');
        static::assertEquals(0.0, $cart->getPrice()->getTotalPrice(), 'Total Price has to be 0,00');
        static::assertEquals(0.0, $cart->getPrice()->getCalculatedTaxes()->getAmount(), 'Taxes have to be 0,00');
        static::assertEquals(0.0, $cart->getPrice()->getNetPrice(), 'Net Price has to be 0,00');
    }

    /** * This test verifies that our promotion components are really involved in our checkout. * We add a product to the cart and apply a code for a promotion with 50% discount. * Our cart should have a total value of 15,00 in the end. * * @group promotions * * @throws CartException */
    

    protected function sumByTax(array $prices)
    {
        $sum = [];
        foreach ($prices as $price) {
            $key = (string) $price->getTaxRate();
            $taxPrice = 0;
            if (\array_key_exists($key$sum)) {
                $taxPrice = $sum[$key];
            }

            $taxPrice += $price->getNetPrice();

            $sum[$key] = $taxPrice;
        }

        return $sum;
    }
}
->setValue('price', ':price')
            ->setValue('netprice', ':netPrice')
            ->setValue('tax_rate', ':taxRate')
            ->setValue('datum', ':datum')
            ->setValue('modus', ':mode')
            ->setValue('currencyFactor', ':currencyFactor')
            ->setParameters([
                'sessionId' => $discountContext->getSessionId(),
                'articleName' => $discountContext->getDiscountName(),
                'ordernumber' => $discountContext->getOrderNumber(),
                'price' => $price->getPrice(),
                'netPrice' => $price->getNetPrice(),
                'taxRate' => $price->getTaxRate(),
                'mode' => $discountContext->getBasketMode(),
                'currencyFactor' => $discountContext->getCurrencyFactor(),
                'datum' => (new DateTime())->format('Y-m-d H:i:s'),
                'articleID' => 0,
                'quantity' => 1,
            ]);

        return $query;
    }

    
Home | Imprint | This part of the site doesn't use cookies.