getPriceGroups example



    /** * 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. */
    private function getHighestQuantityDiscount(ListProduct $product, ShopContextInterface $context, int $quantity): ?PriceDiscount
    {
        $priceGroups = $context->getPriceGroups();
        if (empty($priceGroups)) {
            return null;
        }

        $productPriceGroup = $product->getPriceGroup();
        if (!$productPriceGroup instanceof PriceGroup) {
            return null;
        }

        $id = $productPriceGroup->getId();
        if (!isset($priceGroups[$id])) {
            


    /** * 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. */
    private function getHighestQuantityDiscount(ListProduct $product, ShopContextInterface $context, int $quantity): ?PriceDiscount
    {
        $priceGroups = $context->getPriceGroups();
        if (empty($priceGroups)) {
            return null;
        }

        $productPriceGroup = $product->getPriceGroup();
        if (!$productPriceGroup instanceof PriceGroup) {
            return null;
        }

        $id = $productPriceGroup->getId();
        if (!isset($priceGroups[$id])) {
            
$state = null;
        if ($stateId !== null) {
            $state = $this->countryGateway->getState($stateId$context);
        }

        if (!$area && $country instanceof Country && \is_int($country->getAreaId())) {
            $area = $this->countryGateway->getArea($country->getAreaId()$context);
        }

        $taxRules = $this->taxGateway->getRules($currentCustomerGroup$area$country$state);

        $priceGroups = $this->priceGroupDiscountGateway->getPriceGroups($currentCustomerGroup$context);

        return new ShopContext(
            $baseUrl,
            $shop,
            $currency,
            $currentCustomerGroup,
            $fallbackCustomerGroup,
            $taxRules,
            $priceGroups,
            $area,
            $country,
            
$fallbackPrices = $this->buildPrices(
                $fallbackProducts,
                $fallbackPrices,
                $context->getFallbackCustomerGroup()
            );

            // Do not use array_merge here. Since it will reindex the numbers of fallbackPrices.             $prices += $fallbackPrices;
        }

        $priceGroups = $context->getPriceGroups();

        /* * If one of the products has a configured price group, * the graduated prices has to be build over the defined price group graduations. * * The price group discounts are defined with a percentage discount, which calculated * on the first graduated price of the product. */
        foreach ($products as $product) {
            if (!$product->isPriceGroupActive() || !$product->getPriceGroup()) {
                continue;
            }
Home | Imprint | This part of the site doesn't use cookies.