getPositionPrice example

// add a new promotion black friday         $this->createTestFixturePercentagePromotion($promotionId$code, 100, null, $this->getContainer());

        $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 */


    /** * @throws UnsupportedOperatorException */
    public function match(RuleScope $scope): bool
    {
        if (!$scope instanceof CartRuleScope) {
            return false;
        }

        return RuleComparison::numeric($scope->getCart()->getPrice()->getPositionPrice()$this->amount, $this->operator);
    }

    public function getConstraints(): array
    {
        return [
            'amount' => RuleConstraints::float(),
            'operator' => RuleConstraints::numericOperators(false),
        ];
    }

    public function getConfig(): RuleConfig
    {
->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);

        static::assertNotNull($order);
        
$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 */
    
        $this->createTestFixtureFixedDiscountPromotion($promotionId, 40, PromotionDiscountEntity::SCOPE_CART, $code$this->getContainer()$this->context);

        $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
    {
if ($context->getTaxState() === CartPrice::TAX_STATE_GROSS) {
            $netPrice = $this->rounding->cashRound(
                $grossPrice - $taxSum,
                $context->getTotalRounding()
            );
        }

        return new CartPrice(
            $netPrice,
            $grossPrice,
            $price->getPositionPrice(),
            $taxes,
            $price->getTaxRules(),
            $context->getTaxState(),
            $grossPrice
        );
    }

    /** * @param array<string, CalculatedTaxCollection>|null $taxes */
    private function applyLineItemTaxes(LineItemCollection $lineItems, ?array $taxes): void
    {


    /** * `getPosition()` returns the sum price of all line-items in the cart. * In the position price the shipping costs are excluded. * Depending on the tax settings this may be the gross or net price og the line-items. * * @return float The position price as float. */
    public function getPosition(): float
    {
        return $this->price->getPositionPrice();
    }

    /** * Alias for `getTotal()`. * * @return float The rounded total price of the cart as float. */
    public function getRounded(): float
    {
        return $this->getTotal();
    }

    


        if (!$currencyFactor) {
            throw new EntityNotFoundException('currency', $currencyId);
        }

        return $this->currencyFactor[$currencyId] = (float) $currencyFactor;
    }

    private function validateTaxFree(SalesChannelContext $context, Cart $cart, CartBehavior $behaviorContext): Cart
    {
        $totalCartNetAmount = $cart->getPrice()->getPositionPrice();
        if ($context->getTaxState() === CartPrice::TAX_STATE_GROSS) {
            $totalCartNetAmount = $totalCartNetAmount - $cart->getLineItems()->getPrices()->getCalculatedTaxes()->getAmount();
        }
        $taxState = $this->detectTaxType($context$totalCartNetAmount);
        $previous = $context->getTaxState();
        if ($taxState === $previous) {
            return $cart;
        }

        $context->setTaxState($taxState);
        $cart->setData(null);
        
        $this->createTestFixtureProduct($productId1, 65, 19, $container$this->context);
        $this->createTestFixtureProduct($productId2, 30, 7, $container$this->context);

        // 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 */
        $this->createTestFixtureAbsolutePromotion($promotionId$code, 45, $this->getContainer());

        $cart = $this->cartService->getCart($context->getToken()$context);

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

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

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

    /** * 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 a currency dependent discount. * The standard value of discount would be 15, but our currency price value is 30 * Our cart should have a total value of 70,00 (and not 85 as standard) in the end. * * @group promotions */
    
$taxAmount = $creditItemsCalculatedPrice->getCalculatedTaxes()->getAmount();
        $taxes = $creditItemsCalculatedPrice->getCalculatedTaxes();

        foreach ($taxes as $tax) {
            $tax->setTax($tax->getTax() !== 0.0 ? -$tax->getTax() : 0.0);
        }

        if ($order->getPrice()->hasNetPrices()) {
            $price = new CartPrice(
                -$totalPrice,
                -($totalPrice + $taxAmount),
                -$order->getPositionPrice(),
                $taxes,
                $creditItemsCalculatedPrice->getTaxRules(),
                $order->getTaxStatus()
            );
        } else {
            $price = new CartPrice(
                -($totalPrice - $taxAmount),
                -$totalPrice,
                -$order->getPositionPrice(),
                $taxes,
                $creditItemsCalculatedPrice->getTaxRules(),
                
Home | Imprint | This part of the site doesn't use cookies.