getCheapestPrice example

$displayFromPrice = $cheapestPriceData[$number]['different_price_count'] > 1;
            }

            if ($product->isPriceGroupActive()) {
                $cheapestPriceRule = $this->calculatePriceGroupDiscounts($product$cheapestPriceRule$context);
            }

            $product->setCheapestPriceRule($cheapestPriceRule);
            $this->priceCalculationService->calculateProduct($product$context);

            $product->setListingPrice($product->getCheapestUnitPrice());
            if ($this->config->get('calculateCheapestPriceWithMinPurchase') && $product->getCheapestPrice() instanceof Price) {
                $product->setListingPrice($product->getCheapestPrice());
            }

            $product->setDisplayFromPrice($displayFromPrice);
        }
    }

    private function calculatePriceGroupDiscounts(ListProduct $product, PriceRule $price, ShopContextInterface $context): PriceRule
    {
        if (!$product->isPriceGroupActive()) {
            return $price;
        }
$product->addAttribute('marketing', $this->marketingService->getProductAttribute($product));

            $this->priceCalculationService->calculateProduct($product$context);

            if (!$this->isProductValid($product$context)) {
                continue;
            }

            $product->setListingPrice($product->getCheapestUnitPrice());
            $product->setDisplayFromPrice(\count($product->getPrices()) > 1 || $product->hasDifferentPrices());
            $product->setAllowBuyInListing($this->allowBuyInListing($product));
            if ($this->config->get('calculateCheapestPriceWithMinPurchase') && $product->getCheapestPrice() instanceof Price) {
                $product->setListingPrice($product->getCheapestPrice());
            }
            $result[$number] = $product;
        }

        return $result;
    }

    /** * Checks if the provided product is allowed to display in the store front for * the provided context. */
->build(),
            ], Context::createDefaultContext());

        $salesChannelContext = $this->getContainer()->get(SalesChannelContextFactory::class)
            ->create(Uuid::randomHex(), TestDefaults::SALES_CHANNEL);
        /** @var SalesChannelProductEntity $productEntity */
        $productEntity = $this->getContainer()
            ->get('sales_channel.product.repository')
            ->search(new Criteria([$ids->get('p.1')])$salesChannelContext)
            ->first();

        static::assertInstanceOf(CheapestPrice::class$productEntity->getCheapestPrice());
    }

    public function testCheapestPriceOnSalesChannelProductEntityPartial(): void
    {
        $ids = new IdsCollection();

        $this->getContainer()->get('product.repository')
            ->create([
                (new ProductBuilder($ids, 'p.1'))
                    ->price(130)
                    ->prices('rule-a', 150)
                    
if (isset($rules[$customerGroup])) {
                    $rule = $rules[$customerGroup];
                }

                $product->setCheapestPriceRule($rule);

                $this->priceCalculationService->calculateProduct($product$context);

                $priceObj = $product->getCheapestUnitPrice();

                if ($this->config->get('calculateCheapestPriceWithMinPurchase')) {
                    $priceObj = $product->getCheapestPrice();
                }

                if ($priceObj) {
                    $priceObj->setRule(null);

                    $prices[$number][$key] = $priceObj;
                }
            }
        }

        return $prices;
    }
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());
        $product->setMinStock($listProduct->getMinStock());
        $product->setReleaseDate($listProduct->getReleaseDate());
        $product->setShippingTime($listProduct->getShippingTime());
        
$category = $context->getShop()->getCategory()->getId();
            $criteria->addBaseCondition(
                new CategoryCondition([$category])
            );

            $result = Shopware()->Container()->get(ProductSearchInterface::class)
                ->search($criteria$context);

            $products = array_values($result->getProducts());
            $products = array_map(function DListProduct $product) {
                $cheapestPrice = $product->getCheapestPrice();
                if (!$cheapestPrice instanceof Price) {
                    return $product;
                }
                $price = $cheapestPrice->getCalculatedPrice();
                $product = json_decode(json_encode($product, JSON_THROW_ON_ERROR), true);
                $product['cheapestPrice'] = $price;

                return $product;
            }$products);

            $success = true;
            
Home | Imprint | This part of the site doesn't use cookies.