setCustomerGroup example

->addOrderBy('priceGroupDiscount.discountstart')
            ->setParameter(':customerGroup', $customerGroup->getId());

        $data = $query->execute()->fetchAll(PDO::FETCH_GROUP);

        $priceGroups = [];

        foreach ($data as $row) {
            $priceGroup = $this->priceHydrator->hydratePriceGroup($row);

            foreach ($priceGroup->getDiscounts() as $discount) {
                $discount->setCustomerGroup($customerGroup);
            }

            $priceGroups[$priceGroup->getId()] = $priceGroup;
        }

        return $priceGroups;
    }
}

    public function hydrate($data)
    {
        $shop = new Shop();
        $shop->setId((int) $data['__shop_id']);
        $shop->setIsDefault((bool) $data['__shop_default']);
        $shop->setName($data['__shop_name']);
        $shop->setTitle($data['__shop_title']);
        $shop->setFallbackId((int) $data['__shop_fallback_id']);
        $shop->setCurrency($this->currencyHydrator->hydrate($data));
        $shop->setCustomerGroup($this->customerGroupHydrator->hydrate($data));
        $shop->setCategory($this->categoryHydrator->hydrate($data));
        $shop->setLocale($this->localeHydrator->hydrate($data));

        $parent = $data;
        if ($data['parent']) {
            $parent = $data['parent'];
        }

        $shop->setTemplate($this->templateHydrator->hydrate($parent));
        $shop->setParentId((int) $parent['__shop_id']);
        $shop->setHost($parent['__shop_host']);
        
$price = $reference->getPrice() * $percent;

            $pseudo = $reference->getPseudoPrice();

            $rule->setPrice($price);

            $rule->setPseudoPrice($pseudo);

            $rule->setFrom($discount->getQuantity());

            $rule->setCustomerGroup($customerGroup);

            $rule->setTo(null);
            if ($previous) {
                $previous->setTo($rule->getFrom() - 1);
            }

            $previous = $rule;
            $prices[] = $rule;
        }

        return $prices;
    }
if (!empty($data['__customer_lockeduntil'])) {
            $customer->setLockedUntil(new DateTime($data['__customer_lockeduntil']));
        }
        if (!empty($data['__customer_firstlogin'])) {
            $customer->setFirstLogin(new DateTime($data['__customer_firstlogin']));
        }
        if (!empty($data['__customer_lastlogin'])) {
            $customer->setLastLogin(new DateTime($data['__customer_lastlogin']));
        }

        if ($data['__customer_customergroup']) {
            $customer->setCustomerGroup(
                $this->customerGroupHydrator->hydrate($data)
            );
        }

        if (isset($data['__customerAttribute_id'])) {
            $this->attributeHydrator->addAttribute($customer$data, 'customerAttribute');
        }

        return $customer;
    }
}
$mainQuery->setParameter(':customerGroup', $context->getCurrentCustomerGroup()->getKey())
            ->setParameter(':fallbackCustomerGroup', $context->getFallbackCustomerGroup()->getKey())
            ->setParameter(':variants', $variantIds, Connection::PARAM_INT_ARRAY)
            ->setParameter(':priceGroupCustomerGroup', $customerGroup->getId());

        $data = $mainQuery->execute()->fetchAll(PDO::FETCH_ASSOC);

        $prices = [];
        foreach ($data as $row) {
            $product = (string) $row['__variant_ordernumber'];
            $prices[$product]['price'] = $this->priceHydrator->hydrateCheapestPrice($row);
            $prices[$product]['price']->setCustomerGroup($customerGroup);

            $prices[$product]['different_price_count'] = (int) $row['__different_price_count'];
        }

        return $prices;
    }

    /** * @deprecated - Will be private in Shopware 5.8 * * @return string */
$prices = [];

        foreach ($products as $product) {
            $key = $product->getId();

            if (!\array_key_exists($key$priceRules) || empty($priceRules[$key])) {
                continue;
            }

            $cheapestPrice = $priceRules[$key];

            $cheapestPrice->setCustomerGroup($group);

            $prices[$product->getNumber()] = $cheapestPrice;
        }

        return $prices;
    }

    /** * 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. */
Home | Imprint | This part of the site doesn't use cookies.