expandVariants example

/** * {@inheritdoc} */
    public function generateCondition(
        ConditionInterface $condition,
        QueryBuilder $query,
        ShopContextInterface $context
    ) {
        $conditions = $this->criteria->getConditionsByClass(VariantCondition::class);

        $conditions = array_filter($conditionsfunction DVariantCondition $condition) {
            return $condition->expandVariants();
        });

        if (empty($conditions)) {
            // variants will ne be splitted => only check if product has an available variant             $this->priceHelper->joinAvailableVariant($query);

            return;
        }

        // variants will be displayed => add stock condition         $query->andWhere('(variant.laststock * variant.instock) >= (variant.laststock * variant.minpurchase)');
    }
$this->config = $config;
    }

    /** * {@inheritdoc} */
    public function updatePrices(Criteria $criteria, ProductSearchResult $result, ShopContextInterface $context)
    {
        $conditions = $criteria->getConditionsByClass(VariantCondition::class);

        $conditions = array_filter($conditionsfunction DVariantCondition $condition) {
            return $condition->expandVariants();
        });

        if (empty($conditions)) {
            return;
        }

        // executed if no price condition included in search request
        $this->loadPrices($criteria$result$context);
    }

    
/** * {@inheritdoc} */
    public function generateCondition(
        ConditionInterface $condition,
        QueryBuilder $query,
        ShopContextInterface $context
    ) {
        $conditions = $this->criteria->getConditionsByClass(VariantCondition::class);
        $conditions = array_filter($conditionsfunction DVariantCondition $condition) {
            return $condition->expandVariants();
        });

        if (!$query->hasState(self::STATE_INCLUDES_PSEUDO_PRICE_VARIANTS)) {
            if (empty($conditions)) {
                $this->variantHelper->joinVariants($query);
                $this->joinPrices($query$context);
            } else {
                $this->listingPriceSwitcher->joinPrice($query$this->criteria, $context);
                $query->andWhere('listing_price.pseudoprice > 0');
            }

            
'filterConfiguration.options.id',
                $criteriaPart->getOptionIds()
            )
        );
    }

    private function buildGroupBy(Criteria $criteria): ?string
    {
        $conditions = $criteria->getConditionsByClass(VariantCondition::class);

        $conditions = array_filter($conditionsfunction DVariantCondition $condition) {
            return $condition->expandVariants();
        });

        $groups = array_map(function DVariantCondition $condition) {
            return $condition->getGroupId();
        }$conditions);

        if (empty($conditions)) {
            return null;
        }

        sort($groups, SORT_NUMERIC);

        

    private function getListing(
        ?int $categoryId,
        ShopContextInterface $context,
        Enlight_Controller_Request_Request $request,
        Criteria $criteria
    ): array {
        $conditions = $criteria->getConditionsByClass(VariantCondition::class);
        $conditions = array_filter($conditionsfunction DVariantCondition $condition) {
            return $condition->expandVariants();
        });

        if (\count($conditions) > 0) {
            $this->config->offsetSet('forceArticleMainImageInListing', 0);
            $searchResult = $this->searchService->search($criteria$context);
            $this->config->offsetSet('forceArticleMainImageInListing', 1);
        } else {
            $searchResult = $this->searchService->search($criteria$context);
        }

        $products = [];
        
return $this->gateway->getOptions($valueIds$context);
    }

    /** * Modifies the query reading products from the database to reflect the selected options */
    private function rebuildQuery(Criteria $criteria, QueryBuilder $query, VariantFacet $facet): void
    {
        $conditions = $criteria->getConditionsByClass(VariantCondition::class);
        $conditions = array_filter($conditionsfunction DVariantCondition $condition) {
            return $condition->expandVariants();
        });

        $variantAlias = 'variant';
        if (empty($conditions)) {
            $this->helper->joinAvailableVariant($query);
            $variantAlias = 'availableVariant';
        }

        $query->innerJoin($variantAlias, 's_article_configurator_option_relations', 'variantOptions', 'variantOptions.article_id = ' . $variantAlias . '.id');

        $query->resetQueryPart('orderBy');
        
$where = implode(' OR ', $where);

        $query->innerJoin(
            'variant',
            's_article_configurator_option_relations',
            $tableKey,
            'variant.id = ' . $tableKey . '.article_id AND (' . $where . ')'
        );

        if (!$condition->expandVariants()) {
            return;
        }

        if (!$query->hasState('variant_group_by')) {
            $query->resetQueryPart('groupBy');
        }

        $query->addState('variant_group_by');
        $query->addGroupBy($tableKey . '.option_id');
    }

    
/** * {@inheritdoc} */
    public function generateCondition(
        ConditionInterface $condition,
        QueryBuilder $query,
        ShopContextInterface $context
    ) {
        $conditions = $this->criteria->getConditionsByClass(VariantCondition::class);
        $conditions = array_filter($conditionsfunction DVariantCondition $condition) {
            return $condition->expandVariants();
        });

        if (!$query->hasState(self::STATE_INCLUDES_IMMEDIATE_DELIVERY_VARIANTS)) {
            if (empty($conditions)) {
                $this->variantHelper->joinVariants($query);
                $query->andWhere('allVariants.instock >= allVariants.minpurchase');
            } else {
                $query->andWhere('variant.instock >= variant.minpurchase');
            }
            $query->addState(self::STATE_INCLUDES_IMMEDIATE_DELIVERY_VARIANTS);
        }
    }
$search->addPostFilter(
            new TermQuery('hasStock', true)
        );
    }

    private function buildGroupBy(Criteria $criteria): ?string
    {
        $conditions = $criteria->getConditionsByClass(VariantCondition::class);

        $conditions = array_filter($conditionsfunction DVariantCondition $condition) {
            return $condition->expandVariants();
        });

        $groups = array_map(function DVariantCondition $condition) {
            return $condition->getGroupId();
        }$conditions);

        if (empty($conditions)) {
            return null;
        }

        sort($groups, SORT_NUMERIC);

        
$result = $this->decorated->search($criteria$context);
        if (!$criteria->hasConditionOfClass(VariantCondition::class)) {
            return $result;
        }

        $this->listingPriceService->updatePrices($criteria$result$context);

        $products = $result->getProducts();
        $configurations = $this->configuratorService->getProductsConfigurations($products$context);

        $filterGroupIds = array_map(function D$variantCondition) {
            if ($variantCondition->expandVariants()) {
                return $variantCondition->getGroupId();
            }

            return null;
        }$criteria->getConditionsByClass(VariantCondition::class));

        if (!empty($filterGroupIds)) {
            foreach ($products as $product) {
                if (!\array_key_exists($product->getNumber()$configurations)) {
                    continue;
                }

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

        /* * Query to get the id of the cheapest price */
        $cheapestPriceIdQuery = $this->connection->createQueryBuilder();

        $joinCondition = ' cheapestPrices.articleID = details.articleID ';
        foreach ($criteria->getConditionsByClass(VariantCondition::class) as $condition) {
            if ($condition->expandVariants()) {
                $joinCondition = $this->joinVariantCondition($mainQuery$cheapestPriceIdQuery$cheapestPriceQuery$condition) . $joinCondition;
            }
        }

        /* * Last graduation configuration only needs to use for the cheapest price, not for the different price count. * Get the cheapest price of the fallback customer group, if no price of the current customer group is available. */
        $countSubQuery = clone $cheapestPriceQuery;
        $graduation = 'IF(prices.id IS NOT NULL, prices.from = 1, defaultPrices.from = 1)';
        if ($this->config->get('useLastGraduationForCheapestPrice')) {
            

    public function rewriteLinks(
        Criteria $criteria,
        array $articles,
        ShopContextInterface $context,
        $categoryId = null
    ) {
        $conditions = $criteria->getConditionsByClass(VariantCondition::class);
        $conditions = array_filter($conditionsfunction DVariantCondition $condition) {
            return $condition->expandVariants();
        });

        $products = array_map(function Darray $product) {
            return new BaseProduct($product['articleID']$product['articleDetailsID']$product['ordernumber']);
        }$articles);

        $configurations = [];
        if (!empty($conditions)) {
            $configurations = $this->configuratorService->getProductsConfigurations($products$context);
        }

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