getPrices example

$data[0]['categories'] = $this->getArticleCategories($id);
        $data[0]['seoCategories'] = $this->getArticleSeoCategories($id);

        $data[0]['similar'] = $this->getArticleSimilars($id);
        $data[0]['streams'] = $this->getArticleRelatedProductStreams($id);
        $data[0]['related'] = $this->getArticleRelated($id);
        $data[0]['images'] = $this->getArticleImages($id);

        $data[0]['links'] = $this->getArticleLinks($id);
        $data[0]['downloads'] = $this->getArticleDownloads($id);
        $data[0]['customerGroups'] = $this->getArticleCustomerGroups($id);
        $data[0]['mainPrices'] = $this->getPrices($data[0]['mainDetail']['id']$tax);
        $data[0]['configuratorSet'] = $this->getArticleConfiguratorSet($id);

        $data[0]['dependencies'] = [];

        if (!empty($data[0]['configuratorSetId'])) {
            $data[0]['dependencies'] = $this->getArticleDependencies($data[0]['configuratorSetId']);
        }

        $data[0]['configuratorTemplate'] = $this->getArticleConfiguratorTemplate($id$tax);

        if ($data[0]['added'] && $data[0]['added'] instanceof DateTime) {
            


    /** * @param array $data * * @throws CustomValidationException * * @return Collection */
    protected function preparePriceAssociation($data, ProductModel $article, Detail $variant, Tax $tax)
    {
        $prices = $this->checkDataReplacement($variant->getPrices()$data, 'prices', true);

        foreach ($data['prices'] as &$priceData) {
            $price = $this->getOneToManySubElement(
                $prices,
                $priceData,
                Price::class
            D;

            if (empty($priceData['customerGroupKey'])) {
                $priceData['customerGroupKey'] = 'EK';
            }

            
$key = DeliveryProcessor::buildKey($delivery->getShippingMethod()->getId());

        if (!$data->has($key)) {
            throw ShippingException::shippingMethodNotFound($delivery->getShippingMethod()->getId());
        }

        /** @var ShippingMethodEntity $shippingMethod */
        $shippingMethod = $data->get($key);

        foreach ($context->getRuleIds() as $ruleId) {
            /** @var ShippingMethodPriceCollection $shippingPrices */
            $shippingPrices = $shippingMethod->getPrices()->filterByProperty('ruleId', $ruleId);

            $costs = $this->getMatchingPriceOfRule($delivery$context$shippingPrices);
            if ($costs !== null) {
                break;
            }
        }

        // Fetch default price if no rule matched         if ($costs === null) {
            /** @var ShippingMethodPriceCollection $shippingPrices */
            $shippingPrices = $shippingMethod->getPrices()->filterByProperty('ruleId', null);
            


        if ($product->getCover()) {
            $promotion['image'] = $this->convertMediaStruct($product->getCover());
        }

        if ($product->getVoteAverage()) {
            $promotion['sVoteAverage'] = $this->convertVoteAverageStruct($product->getVoteAverage());
        }

        $promotion['prices'] = [];
        foreach ($product->getPrices() as $price) {
            $promotion['prices'][] = $this->convertProductPriceStruct($price);
        }

        $promotion['linkBasket'] = $this->config->get('baseFile') .
            '?sViewport=basket&sAdd=' . $promotion['ordernumber'];

        $promotion['linkDetails'] = $this->config->get('baseFile') .
            '?sViewport=detail&sArticle=' . $promotion['articleID'];

        $promotion['linkVariant'] = $this->config->get('baseFile') .
            '?sViewport=detail&sArticle=' . $promotion['articleID'] . '&number=' . $promotion['ordernumber'];

        
$successCallback($order);
    }

    public static function creditNoteRendererCustomerGroupDataProvider(): \Generator
    {
        yield 'render credit_note with customer group gross' => [
            false,
            [7],
            [-100],
            function DOrderEntity $order): void {
                static::assertNotNull($lineItems = $order->getLineItems());
                $taxAmount = $lineItems->getPrices()->sum()->getCalculatedTaxes()->getAmount();

                static::assertEquals($order->getPrice()->getTotalPrice(), 100);
                static::assertEquals($order->getAmountNet(), -(-100 - $taxAmount));
            },
        ];

        yield 'render credit_note with customer group net' => [
            true,
            [7],
            [-100],
            function DOrderEntity $order): void {
                

    public function assignProductData(ListProduct $listProduct, ListProduct $product)
    {
        trigger_error(sprintf('%s:%s is deprecated since Shopware 5.6 and will be removed with 5.7. Will be removed without replacement.', __CLASS__, __METHOD__), E_USER_DEPRECATED);

        $product->setShippingFree($listProduct->isShippingFree());
        $product->setMainVariantId($listProduct->getMainVariantId());
        $product->setAllowsNotification($listProduct->allowsNotification());
        $product->setHighlight($listProduct->highlight());
        $product->setUnit($listProduct->getUnit());
        $product->setTax($listProduct->getTax());
        $product->setPrices($listProduct->getPrices());
        $product->setManufacturer($listProduct->getManufacturer());
        $product->setCover($listProduct->getCover());
        $product->setCheapestPrice($listProduct->getCheapestPrice());
        $product->setName($listProduct->getName());
        $product->setAdditional($listProduct->getAdditional());
        $product->setCloseouts($listProduct->isCloseouts());
        $product->setEan($listProduct->getEan());
        $product->setHeight($listProduct->getHeight());
        $product->setKeywords($listProduct->getKeywords());
        $product->setLength($listProduct->getLength());
        $product->setLongDescription($listProduct->getLongDescription());
        

    }

    /** * @return list<string> */
    public function getPriceIds(): array
    {
        $ids = [[]];

        foreach ($this->getIterator() as $element) {
            $ids[] = $element->getPrices()->getIds();
        }

        return array_merge(...$ids);
    }

    public function getPrices(): ShippingMethodPriceCollection
    {
        $prices = [[]];

        foreach ($this->getIterator() as $element) {
            $prices[] = $element->getPrices()->getElements();
        }


    public function adjust(Cart $cart, TaxProviderResult $result, SalesChannelContext $context): void
    {
        $lineItems = $cart->getLineItems();
        $deliveries = $cart->getDeliveries();

        $this->applyLineItemTaxes($lineItems$result->getLineItemTaxes());
        $this->applyDeliveryTaxes($deliveries$result->getDeliveryTaxes());

        $price = $this->amountCalculator->calculate(
            $cart->getLineItems()->getPrices(),
            $cart->getDeliveries()->getShippingCosts(),
            $context
        );

        // either take the price from the tax provider result or take the calculated taxes         $taxes = $price->getCalculatedTaxes()->filter(fn (CalculatedTax $tax) => $tax->getTax() > 0.0);
        $price->setCalculatedTaxes($taxes);

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

        
$data->set(LineItemGroupBuilder::class$this->groupBuilder);

        return $lineItem->getRequirement()->match($scopeWithoutLineItem);
    }

    /** * calculate the cart sum */
    private function calculateCart(Cart $cart, SalesChannelContext $context): void
    {
        $amount = $this->amountCalculator->calculate(
            $cart->getLineItems()->getPrices(),
            $cart->getDeliveries()->getShippingCosts(),
            $context
        );

        $cart->setPrice($amount);
    }

    /** * @throws CartException */
    private function enrichPackagesWithCartData(DiscountPackageCollection $result, Cart $cart, SalesChannelContext $context): DiscountPackageCollection
    {
$criteria->addFilter(new EqualsFilter('order_delivery.orderId', $orderId));
        $orderDeliveryRepository = $this->getContainer()->get('order_delivery.repository');
        $deliveries = $orderDeliveryRepository->search($criteria$versionContext);

        /** @var OrderDeliveryEntity $delivery */
        $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
    {
        
$calculator = new PercentagePriceCalculator(
            $rounding,
            new QuantityPriceCalculator(
                new GrossPriceCalculator($taxCalculator$rounding),
                new NetPriceCalculator($taxCalculator$rounding),
            ),
            new PercentageTaxRuleBuilder()
        );

        $price = $calculator->calculate(
            $calculation->getPercentageDiscount(),
            $calculation->getPrices(),
            Generator::createSalesChannelContext()
        );
        $expected = $calculation->getExpected();

        static::assertEquals($expected$price);
        static::assertEquals($expected->getCalculatedTaxes()$price->getCalculatedTaxes());
        static::assertEquals($expected->getTaxRules()$price->getTaxRules());
        static::assertEquals($expected->getTotalPrice()$price->getTotalPrice());
        static::assertEquals($expected->getUnitPrice()$price->getUnitPrice());
        static::assertEquals($expected->getQuantity()$price->getQuantity());
    }

    
$ruleId = 'cb34dc6f20b6479aa975e1290f442e65';
        $this->createProduct($productId);
        $this->createRule($ruleId);

        $progress = $this->import($context, ProductPriceDefinition::ENTITY_NAME, '/fixtures/advanced_prices.csv', 'advanced_prices.csv');

        static::assertImportExportSucceeded($progress$this->getInvalidLogContent($progress->getInvalidRecordsLogId()));

        /** @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();
        
$calculator = new AbsolutePriceCalculator(
            new QuantityPriceCalculator(
                new GrossPriceCalculator($taxCalculator$rounding),
                new NetPriceCalculator($taxCalculator$rounding),
            ),
            new PercentageTaxRuleBuilder()
        );

        $calculatedPrice = $calculator->calculate(
            $calculation->getDiscount(),
            $calculation->getPrices(),
            Generator::createSalesChannelContext()
        );

        static::assertEquals($calculation->getExpected()->getCalculatedTaxes()$calculatedPrice->getCalculatedTaxes());
        static::assertEquals($calculation->getExpected()->getTaxRules()$calculatedPrice->getTaxRules());
        static::assertEquals($calculation->getExpected()->getTotalPrice()$calculatedPrice->getTotalPrice());
        static::assertEquals($calculation->getExpected()->getUnitPrice()$calculatedPrice->getUnitPrice());
        static::assertEquals($calculation->getExpected()->getQuantity()$calculatedPrice->getQuantity());
    }

    /** * @return array<string, list<AbsoluteCalculation>> */
$filter = $this->filter;
        if ($filter !== null) {
            $context = $scope->getSalesChannelContext();

            $goods = $goods->filter(static function DLineItem $lineItem) use ($filter$context) {
                $scope = new LineItemScope($lineItem$context);

                return $filter->match($scope);
            });
        }

        return RuleComparison::numeric($goods->getPrices()->sum()->getTotalPrice()$this->amount, $this->operator);
    }

    public function getConstraints(): array
    {
        return [
            'amount' => RuleConstraints::float(),
            'operator' => RuleConstraints::numericOperators(false),
        ];
    }
}
$this->productRepository->create($products$context);

        $criteria = new Criteria([$greenId$parentId$redId]);
        $criteria->addAssociation('prices');
        $context->setConsiderInheritance(true);

        $products = $this->productRepository->search($criteria$context);

        /** @var ProductEntity $parent */
        $parent = $products->get($parentId);
        static::assertInstanceOf(ProductEntity::class$parent);
        static::assertInstanceOf(ProductPriceCollection::class$parent->getPrices());

        /** @var ProductEntity $red */
        $red = $products->get($redId);
        static::assertInstanceOf(ProductEntity::class$red);
        $productPriceCollection = $red->getPrices();
        static::assertNotNull($productPriceCollection);

        static::assertCount(2, $productPriceCollection);
        static::assertInstanceOf(ProductPriceCollection::class$productPriceCollection);

        /** @var ProductEntity $green */
        
Home | Imprint | This part of the site doesn't use cookies.