getCheapestUnitPrice example

$cheapestPriceRule = $cheapestPriceData[$number]['price'];
                $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()) {
            
$key = $customerGroup . '_' . $context->getCurrency()->getId();

                $rule = $rules[$context->getFallbackCustomerGroup()->getKey()] ?? null;
                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;
                }
            }
        }
$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());
        $product->setHasAvailableVariant($listProduct->hasAvailableVariant());
        $product->setCheapestUnitPrice($listProduct->getCheapestUnitPrice());
        $product->setFallbackPriceCount($listProduct->getFallbackPriceCount());
        $product->setCustomerPriceCount($listProduct->getCustomerPriceCount());

        foreach ($listProduct->getAttributes() as $name => $attribute) {
            $product->addAttribute($name$attribute);
        }

        foreach ($listProduct->getStates() as $state) {
            $product->addState($state);
        }
    }
}
$product->getManufacturer()->setCoverMedia($manufacturerCovers[$product->getManufacturer()->getCoverId()]);
            }

            $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;
    }

    
Home | Imprint | This part of the site doesn't use cookies.