calculatePrice example


    private function calculatePriceStruct(
        PriceRule $rule,
        Tax $tax,
        ShopContextInterface $context
    ): Price {
        $price = new Price($rule);

        // Calculates the normal price of the struct.         $price->setCalculatedPrice(
            $this->priceCalculatorService->calculatePrice($rule->getPrice()$tax$context)
        );

        // Check if a pseudo price is defined and calculates it too.         $price->setCalculatedPseudoPrice(
            $this->priceCalculatorService->calculatePrice($rule->getPseudoPrice()$tax$context)
        );

        if ($rule->getRegulationPrice()) {
            $price->setCalculatedRegulationPrice(
                $this->priceCalculatorService->calculatePrice($rule->getRegulationPrice()$tax$context)
            );
        }
private function calculateLineItems(LineItemCollection $lineItems, SalesChannelContext $context, CartBehavior $behavior): LineItemCollection
    {
        $workingSet = clone $lineItems;
        $workingSet->sortByPriority();

        $calculated = new LineItemCollection();

        foreach ($workingSet as $original) {
            $lineItem = LineItem::createFromLineItem($original);

            $price = $this->calculatePrice($lineItem$context$calculated$behavior);

            $lineItem->setPrice($price);

            $calculated->add($lineItem);
        }

        return $calculated;
    }

    private function filterLineItems(LineItemCollection $calculated, ?Rule $filter, SalesChannelContext $context): LineItemCollection
    {
        
$price = (float) $request->request->get('price');
        $quantity = $request->request->getInt('quantity', 1);
        $output = (string) $request->request->get('output', 'gross');
        $preCalculated = $request->request->getBoolean('calculated', true);

        $taxes = $this->taxRepository->search(new Criteria([$taxId])$context);
        $tax = $taxes->get($taxId);
        if (!$tax instanceof TaxEntity) {
            throw CartException::taxRuleNotFound($taxId);
        }

        $data = $this->calculatePrice($price$tax->getTaxRate()$quantity$output$preCalculated);

        return new JsonResponse(
            ['data' => $data]
        );
    }

    #[Route(path: 'api/_action/calculate-prices', name: 'api.action.calculate-prices', methods: ['POST'])]     public function calculatePrices(Request $request, Context $context): JsonResponse
    {
        if (!$request->request->has('taxId')) {
            throw CartException::taxIdParameterIsMissing();
        }


    /** * @param Entity[] $products */
    public function calculate(iterable $products, SalesChannelContext $context): void
    {
        $units = $this->getUnits($context);

        /** @var Entity $product */
        foreach ($products as $product) {
            $this->calculatePrice($product$context$units);
            $this->calculateAdvancePrices($product$context$units);
            $this->calculateCheapestPrice($product$context$units);
        }
    }

    public function reset(): void
    {
        $this->units = null;
    }

    private function calculatePrice(Entity $product, SalesChannelContext $context, UnitCollection $units): void
    {
'invoiceNumber' => $referenceDocumentNumber,
                    ],
                ]);

                if ($operation->isStatic()) {
                    $doc = new RenderedDocument('', $number$config->buildName()$operation->getFileType()$config->jsonSerialize());
                    $result->addSuccess($orderId$doc);

                    continue;
                }

                $price = $this->calculatePrice($creditItems$order);

                /** @var LocaleEntity $locale */
                $locale = $order->getLanguage()->getLocale();

                $html = $this->documentTemplateRenderer->render(
                    $template,
                    [
                        'order' => $order,
                        'creditItems' => $creditItems,
                        'price' => $price->getTotalPrice() * -1,
                        'amountTax' => $price->getCalculatedTaxes()->getAmount(),
                        
Home | Imprint | This part of the site doesn't use cookies.