joinAvailableVariant example

$priceTable = $this->listingPriceHelper->getPriceTable($context);

        $query = $this->connection->createQueryBuilder();

        $selection = 'MIN(' . $this->listingPriceHelper->getSelection($context) . ') as cheapest_price';

        $query->select(['prices.*', $selection]);
        $query->from('s_articles', 'product');
        $query->innerJoin('product', 's_core_tax', 'tax', 'tax.id = product.taxID');
        $query->innerJoin('product', '(' . $priceTable->getSQL() . ')', 'prices', 'product.id = prices.articleID');

        $this->joinAvailableVariant($query);
        $this->listingPriceHelper->joinPriceGroup($query);

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

        
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)');
    }

    public function setCriteria(Criteria $criteria)
    {
        $this->criteria = $criteria;
    }
$priceTable = $this->listingPriceHelper->getPriceTable($context);
        $priceTable->innerJoin('defaultPrice', 's_articles_details', 'details', 'details.id = defaultPrice.articledetailsID');
        $priceTable->andWhere('(details.laststock * details.instock) >= (details.laststock * details.minpurchase)');
        $priceTable->andWhere('details.active = 1');

        $query->from('s_articles', 'product');
        $query->innerJoin('product', '(' . $priceTable->getSQL() . ')', 'prices', 'product.id = prices.articleID');
        $query->innerJoin('prices', 's_articles_details', 'variant', 'variant.id = prices.articledetailsID AND variant.active = 1');
        $query->innerJoin('product', 's_core_tax', 'tax', 'tax.id = product.taxID');

        $this->joinAvailableVariant($query);
        $query->andWhere('prices.articledetailsID = availableVariant.id');

        $this->listingPriceHelper->joinPriceGroup($query);

        $conditions = $criteria->getConditionsByClass(VariantCondition::class);

        /** @var VariantCondition $condition */
        foreach ($conditions as $condition) {
            if (!$condition->expandVariants()) {
                continue;
            }

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

    /** * {@inheritdoc} */
    public function joinDefaultPrices(QueryBuilder $query, ShopContextInterface $context)
    {
        if ($query->hasState(self::STATE_INCLUDES_DEFAULT_PRICE)) {
            return;
        }
        $this->joinAvailableVariant($query);

        $graduation = 'defaultPrice.from = 1';
        $discountStart = '1';
        if ($this->config->get('useLastGraduationForCheapestPrice')) {
            $graduation = "IF(priceGroup.id IS NOT NULL, defaultPrice.from = 1, defaultPrice.to = 'beliebig')";
            $discountStart = '(SELECT MAX(discountstart) FROM s_core_pricegroups_discounts subPriceGroup WHERE subPriceGroup.id = priceGroup.id AND subPriceGroup.customergroupID = :priceGroupCustomerGroup)';
        }

        $query->leftJoin(
            'product',
            's_core_pricegroups_discounts',
            

    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');
        $query->innerJoin('variantOptions', 's_article_configurator_options', 'options', 'options.id = variantOptions.option_id AND options.group_id IN (:variantGroupIds)');
        $query->addGroupBy('variantOptions.option_id');
        $query->select('variantOptions.option_id as id');
        $query->setParameter('variantGroupIds', $facet->getGroupIds(), Connection::PARAM_INT_ARRAY);
    }

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