getFallbackCustomerGroup example

public function __construct(Shopware_Components_Config $config)
    {
        $this->config = $config;
    }

    /** * {@inheritdoc} */
    public function getSelection(ShopContextInterface $context)
    {
        $fallback = $context->getFallbackCustomerGroup();
        $current = $context->getCurrentCustomerGroup();
        $currency = $context->getCurrency();

        $priceField = 'defaultPrice.price';
        if ($fallback->getId() != $current->getId()) {
            $priceField = 'IFNULL(customerPrice.price, defaultPrice.price)';
        }

        $discount = $current->useDiscount() ? $current->getPercentageDiscount() : 0;

        $considerMinPurchase = $this->config->get('calculateCheapestPriceWithMinPurchase');

        
/** * {@inheritdoc} */
    public function getUrls(Context $routingContext, ShopContextInterface $shopContext)
    {
        if ($this->allExported) {
            return [];
        }

        $parentId = $shopContext->getShop()->getCategory()->getId();
        $categoryRepository = $this->modelManager->getRepository(Category::class);
        $categories = $categoryRepository->getActiveChildrenList($parentId$shopContext->getFallbackCustomerGroup()->getId(), null, $shopContext->getShop()->getId());

        foreach ($categories as $key => &$category) {
            if (!empty($category['external'])) {
                unset($categories[$key]);
                continue;
            }

            $category['urlParams'] = [
                'sViewport' => 'cat',
                'sCategory' => $category['id'],
                'title' => $category['name'],
            ];


        $priceTable = $this->createListingPriceTable($criteria$context);

        $query->addSelect('listing_price.*');
        $query->leftJoin('variant', '(' . $priceTable->getSQL() . ')', 'listing_price', implode(' AND ', $variantCondition));

        $query->andWhere('variant.laststock * variant.instock >= variant.laststock * variant.minpurchase');

        $query->andWhere('variant.active = 1');

        $query->setParameter(':fallbackCustomerGroup', $context->getFallbackCustomerGroup()->getKey());
        $query->setParameter(':priceGroupCustomerGroup', $context->getCurrentCustomerGroup()->getId());

        if ($this->hasDifferentCustomerGroups($context)) {
            $query->setParameter(':currentCustomerGroup', $context->getCurrentCustomerGroup()->getKey());
        }

        $query->addState(self::VARIANT_LISTING_PRICE_JOINED);
    }

    /** * @throws RuntimeException * @throws InvalidArgumentException */

    private function readCategoryUrls($parentId)
    {
        /** @var array<array<string, mixed>> $categories */
        $categories = $this->em
            ->getRepository(Category::class)
            ->getActiveChildrenList($parentId$this->contextService->getShopContext()->getFallbackCustomerGroup()->getId());

        foreach ($categories as &$category) {
            $category['show'] = empty($category['external']);

            $category['urlParams'] = [
                'sViewport' => 'cat',
                'sCategory' => $category['id'],
                'title' => $category['name'],
            ];

            if ($category['blog']) {
                

        );

        if (empty($fallbackProducts)) {
            return $this->calculatePriceGroupDiscounts($products$prices$context);
        }

        // if some product has no price, we have to load the fallback customer group prices for the fallbackProducts.         $fallbackPrices = $this->cheapestPriceGateway->getList(
            $fallbackProducts,
            $context,
            $context->getFallbackCustomerGroup()
        );

        $fallbackPrices = $this->buildPrices(
            $fallbackProducts,
            $fallbackPrices,
            $context->getFallbackCustomerGroup()
        );

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

        
if ($this->config->get('hideNoInStock')) {
            $query->andWhere('availableVariant.laststock * availableVariant.instock >= availableVariant.laststock * availableVariant.minpurchase');
        }

        $query->andWhere('availableVariant.active = 1');
        $query->andWhere('prices.articleID IN (:products)');

        $query->setParameter('to', 'beliebig');
        $query->setParameter('products', $ids, Connection::PARAM_INT_ARRAY);
        $query->setParameter('variants', $variantIds, Connection::PARAM_INT_ARRAY);

        $query->setParameter(':fallbackCustomerGroup', $context->getFallbackCustomerGroup()->getKey());
        $query->setParameter(':priceGroupCustomerGroup', $context->getCurrentCustomerGroup()->getId());

        if ($context->getCurrentCustomerGroup()->getId() !== $context->getFallbackCustomerGroup()->getId()) {
            $query->setParameter(':currentCustomerGroup', $context->getCurrentCustomerGroup()->getKey());
        }

        /** @var array[] $prices */
        $prices = $query->execute()->fetchAll(PDO::FETCH_GROUP);

        foreach ($prices as &$productPrices) {
            $priceResult = [];
            
$number = $product->getNumber();
            if (!isset($priceRules[$number])) {
                continue;
            }

            $rules = $priceRules[$number];

            foreach ($contexts as $context) {
                $customerGroup = $context->getCurrentCustomerGroup()->getKey();
                $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')) {
                    
 else {
            $priceTable->andWhere('defaultPrice.pseudoprice > 0');
        }

        $query->innerJoin(
            'allVariants',
            '(' . $priceTable->getSQL() . ')',
            'variantPrices',
            'variantPrices.articledetailsID = allVariants.id'
        );

        $query->setParameter(':fallbackCustomerGroup', $context->getFallbackCustomerGroup()->getKey());
        if ($hasDifferentCustomerGroups) {
            $query->setParameter(':currentCustomerGroup', $context->getCurrentCustomerGroup()->getKey());
        }
    }

    private function hasDifferentCustomerGroups(ShopContextInterface $context): bool
    {
        return $context->getCurrentCustomerGroup()->getId() !== $context->getFallbackCustomerGroup()->getId();
    }
}
$products,
            function DListProduct $product) use ($prices) {
                return !\array_key_exists($product->getNumber()$prices);
            }
        );

        if (!empty($fallbackProducts)) {
            // if some product has no price, we have to load the fallback customer group prices for the fallbackProducts.             $fallbackPrices = $this->graduatedPricesGateway->getList(
                $fallbackProducts,
                $context,
                $context->getFallbackCustomerGroup()
            );

            $fallbackPrices = $this->buildPrices(
                $fallbackProducts,
                $fallbackPrices,
                $context->getFallbackCustomerGroup()
            );

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

        
->addSelect($this->fieldHelper->getUnitFields())
            ->addSelect($this->fieldHelper->getTaxFields())
            ->addSelect($this->fieldHelper->getPriceGroupFields())
            ->addSelect($this->fieldHelper->getManufacturerFields())
            ->addSelect($this->fieldHelper->getEsdFields())
            ->addSelect('(' . $esdQuery->getSQL() . ') as __product_has_esd')
            ->addSelect('(' . $customerGroupQuery->getSQL() . ') as __product_blocked_customer_groups')
            ->addSelect('(' . $availableVariantQuery->getSQL() . ') as __product_has_available_variants')
            ->addSelect('(' . $fallbackPriceQuery->getSQL() . ') as __product_fallback_price_count')
            ->addSelect('manufacturerMedia.id as __manufacturer_img_id')
        ;
        $query->setParameter(':fallback', $context->getFallbackCustomerGroup()->getKey());
        if ($context->getCurrentCustomerGroup()->getId() !== $context->getFallbackCustomerGroup()->getId()) {
            $customerPriceQuery = $this->getPriceCountQuery(':current');
            $query->addSelect('(' . $customerPriceQuery->getSQL() . ') as __product_custom_price_count');
            $query->setParameter(':current', $context->getCurrentCustomerGroup()->getKey());
        }
        $query->from('s_articles_details', 'variant')
            ->innerJoin('variant', 's_articles', 'product', 'product.id = variant.articleID')
            ->innerJoin('product', 's_core_tax', 'tax', 'tax.id = product.taxID')
            ->leftJoin('variant', 's_core_units', 'unit', 'unit.id = variant.unitID')
            ->leftJoin('product', 's_articles_supplier', 'manufacturer', 'manufacturer.id = product.supplierID')
            ->leftJoin('product', 's_core_pricegroups', 'priceGroup', 'priceGroup.id = product.pricegroupID')
            
$query->andWhere('prices.articledetailsID = availableVariant.id');

        if ($this->config->get('useLastGraduationForCheapestPrice')) {
            $query->andWhere("IF(priceGroup.id IS NOT NULL, prices.from = 1, prices.to = 'beliebig')");
        } else {
            $query->andWhere('prices.from = 1');
        }

        $query->groupBy('product.id');

        $query->setParameter(':fallbackCustomerGroup', $context->getFallbackCustomerGroup()->getKey());
        $query->setParameter(':priceGroupCustomerGroup', $context->getCurrentCustomerGroup()->getId());

        if ($this->hasDifferentCustomerGroups($context)) {
            $query->setParameter(':currentCustomerGroup', $context->getCurrentCustomerGroup()->getKey());
        }

        return $query;
    }

    /** * @return bool */
$switch[] = sprintf($template, 'articleID as product_id');
        $switch[] = sprintf($template, 'articledetailsID as variant_id');

        return implode(',', $switch);
    }

    /** * @return bool */
    private function hasDifferentCustomerGroups(ShopContextInterface $context)
    {
        return $context->getCurrentCustomerGroup()->getId() !== $context->getFallbackCustomerGroup()->getId();
    }

    /** * Builds the tax cases for the price selection query * * @return string */
    private function buildTaxCase(ShopContextInterface $context)
    {
        $cases = [];
        foreach ($context->getTaxRules() as $rule) {
            
->innerJoin('variant', 's_articles', 'product', 'product.id = variant.articleID')
            ->leftJoin('variant', 's_core_units', 'unit', 'unit.id = variant.unitID')
            ->leftJoin('price', 's_articles_prices_attributes', 'priceAttribute', 'priceAttribute.priceID = price.id')
            ->innerJoin('price', '(' . $cheapestPriceQuery->getSQL() . ')', 'variantCheapestPrice', 'variantCheapestPrice.id = price.id');

        $this->fieldHelper->addUnitTranslation($mainQuery$context);
        $this->fieldHelper->addProductTranslation($mainQuery$context);
        $this->fieldHelper->addVariantTranslation($mainQuery$context);
        $this->fieldHelper->addPriceTranslation($mainQuery$context);

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

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