getPriceRules example

$product->setLongDescription($listProduct->getLongDescription());
        $product->setMinStock($listProduct->getMinStock());
        $product->setReleaseDate($listProduct->getReleaseDate());
        $product->setShippingTime($listProduct->getShippingTime());
        $product->setShortDescription($listProduct->getShortDescription());
        $product->setStock($listProduct->getStock());
        $product->setWeight($listProduct->getWeight());
        $product->setWidth($listProduct->getWidth());
        $product->setPriceGroup($listProduct->getPriceGroup());
        $product->setCreatedAt($listProduct->getCreatedAt());
        $product->setUpdatedAt($listProduct->getUpdatedAt());
        $product->setPriceRules($listProduct->getPriceRules());
        $product->setCheapestPriceRule($listProduct->getCheapestPriceRule());
        $product->setManufacturerNumber($listProduct->getManufacturerNumber());
        $product->setMetaTitle($listProduct->getMetaTitle());
        $product->setTemplate($listProduct->getTemplate());
        $product->setHasConfigurator($listProduct->hasConfigurator());
        $product->setSales($listProduct->getSales());
        $product->setHasEsd($listProduct->hasEsd());
        $product->setEsd($listProduct->getEsd());
        $product->setIsPriceGroupActive($listProduct->isPriceGroupActive());
        $product->setBlockedCustomerGroupIds($listProduct->getBlockedCustomerGroupIds());
        $product->setVoteAverage($listProduct->getVoteAverage());
        
$this->loadPrices($criteria$result$context);
    }

    private function loadPrices(Criteria $criteria, ProductSearchResult $result, ShopContextInterface $context): void
    {
        $cheapestPriceData = $this->variantCheapestPriceGateway->getList($result->getProducts()$context$context->getCurrentCustomerGroup()$criteria);

        foreach ($result->getProducts() as $product) {
            $number = $product->getNumber();

            if (!\array_key_exists($number$cheapestPriceData)) {
                $cheapestPriceRule = $product->getPriceRules()[0];
                $displayFromPrice = $product->displayFromPrice();
            } else {
                $cheapestPriceRule = $cheapestPriceData[$number]['price'];
                $displayFromPrice = $cheapestPriceData[$number]['different_price_count'] > 1;
            }

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

            $product->setCheapestPriceRule($cheapestPriceRule);
            

    public function calculateProduct(
        ListProduct $product,
        ShopContextInterface $context
    ) {
        $tax = $context->getTaxRule($product->getTax()->getId());
        if (!$tax instanceof Tax) {
            throw new StructNotFoundException(Tax::class$product->getTax()->getId());
        }

        $rules = $product->getPriceRules();

        $prices = [];
        foreach ($rules as $rule) {
            $prices[] = $this->calculatePriceStruct($rule$tax$context);
        }

        $product->setPrices($prices);

        $rules = $product->getPriceRules();
        if (!$product->getCheapestPriceRule() && !empty($rules)) {
            $product->setCheapestPriceRule(clone $rules[0]);
        }
Home | Imprint | This part of the site doesn't use cookies.