getHighestQuantityDiscount example

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

    private function calculatePriceGroupDiscounts(ListProduct $product, PriceRule $price, ShopContextInterface $context): PriceRule
    {
        if (!$product->isPriceGroupActive()) {
            return $price;
        }

        $discount = $this->getHighestQuantityDiscount($product$context$price->getFrom());

        if (!$discount instanceof PriceDiscount) {
            return $price;
        }
        $price->setPrice($price->getPrice() / 100 * (100 - $discount->getPercent()));

        return $price;
    }

    /** * Returns the highest price group discount for the provided product. * * The price groups are stored in the provided context object. * If the product has no configured price group or the price group has no discount defined for the * current customer group, the function returns null. */
foreach ($products as $product) {
            if (!$product->isPriceGroupActive()) {
                continue;
            }

            $price = $prices[$product->getNumber()] ?? null;

            if (!$price instanceof PriceRule) {
                continue;
            }

            $discount = $this->getHighestQuantityDiscount($product$context$price->getFrom());

            if (!$discount) {
                continue;
            }
            $price->setPrice(
                $price->getPrice() / 100 * (100 - $discount->getPercent())
            );
        }

        return $prices;
    }

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