getVariantId example

$variantResponse = $this->findVariantRoute->load(
                $productId,
                new Request(
                    [
                        'switchedGroup' => $switchedGroup,
                        'options' => $options ?? [],
                    ]
                ),
                $salesChannelContext
            );

            $productId = $variantResponse->getFoundCombination()->getVariantId();
        } catch (VariantNotFoundException|ProductNotFoundException) {
            // nth         }

        $host = $request->attributes->get(RequestTransformer::SALES_CHANNEL_ABSOLUTE_BASE_URL)
            . $request->attributes->get(RequestTransformer::SALES_CHANNEL_BASE_URL);

        $url = $this->seoUrlPlaceholderHandler->replace(
            $this->seoUrlPlaceholderHandler->generate(
                'frontend.detail.page',
                ['productId' => $productId]
            ),
return array_shift($covers);
    }

    /** * {@inheritdoc} */
    public function getList($products, ShopContextInterface $context)
    {
        $ids = [];
        foreach ($products as $product) {
            $ids[] = $product->getVariantId();
        }
        $ids = array_unique($ids);

        $query = $this->getQuery($context);

        $query->andWhere('childImage.article_detail_id IN (:products)')
            ->orderBy('image.main')
            ->addOrderBy('image.position')
            ->setParameter(':products', $ids, Connection::PARAM_INT_ARRAY);

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

        

    protected $hasStock;

    /** * @return Product */
    public static function createFromListProduct(ListProduct $listProduct)
    {
        $product = new self(
            $listProduct->getId(),
            $listProduct->getVariantId(),
            $listProduct->getNumber()
        );

        foreach ($listProduct as $key => $value) {
            $product->$key = $value;
        }

        return $product;
    }

    /** * @return Option[] */
$result = $this->findProductVariantRoute->load(
            $this->ids->get('base'),
            new Request(
                [
                    'switchedGroup' => $switched,
                    'options' => $options,
                ]
            ),
            $this->context
        );

        static::assertEquals($this->ids->get('redXL')$result->getFoundCombination()->getVariantId());
    }

    public function testFindToNotCombinable(): void
    {
        // update red-xl to inactive         $this->repository->update(
            [
                ['id' => $this->ids->get('redXL'), 'active' => false],
            ],
            Context::createDefaultContext()
        );

        

        $ids = new IdsCollection();

        $options = [
            $ids->get('groupId1') => $ids->get('optionId1'),
            $ids->get('groupId1') => $ids->get('optionId2'),
            $ids->get('groupId2') => $ids->get('optionId3'),
        ];

        $foundCombo = new FoundCombination($ids->get('variantId')$options);

        static::assertEquals($ids->get('variantId')$foundCombo->getVariantId());
        static::assertEquals($options$foundCombo->getOptions());
    }
}

    protected $configuration = [];

    /** * @return Product */
    public static function createFromListProduct(ListProduct $listProduct)
    {
        $product = new self(
            $listProduct->getId(),
            $listProduct->getVariantId(),
            $listProduct->getNumber()
        );
        foreach ($listProduct as $key => $value) {
            $product->$key = $value;
        }

        return $product;
    }

    /** * @param Media[] $media */
return $result;
    }

    private function fetchPrices(array $products, ShopContextInterface $context): array
    {
        $ids = array_map(static function DListProduct $product) {
            return $product->getId();
        }$products);

        $variantIds = array_map(static function DListProduct $product) {
            return $product->getVariantId();
        }$products);

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

        $query->addSelect([
            'DISTINCT availableVariant.articleID',
            'relations.article_id as variant_id',
            'prices.price as price',
            'relations.option_id',
            'options.group_id',
        ]);

        
$variantResponse = $this->findVariantRoute->load(
            $productId,
            new Request(
                [
                    'switchedGroup' => $request->query->get('switched'),
                    'options' => $options ?? [],
                ]
            ),
            $context
        );

        $newProductId = $variantResponse->getFoundCombination()->getVariantId();

        $result = $this->productRoute->load($newProductId$request$contextnew Criteria());
        $product = $result->getProduct();
        $configurator = $result->getConfigurator();

        $request->request->set('parentId', $product->getParentId());
        $request->request->set('productId', $product->getId());
        $reviews = $this->productReviewLoader->load($request$context);
        $reviews->setParentId($product->getParentId() ?? $product->getId());

        $event = new SwitchBuyBoxVariantEvent($elementId$product$configurator$request$context);
        
return array_shift($prices);
    }

    /** * {@inheritdoc} */
    public function getList($products, ShopContextInterface $context, Group $customerGroup)
    {
        $ids = [];
        foreach ($products as $product) {
            $ids[] = $product->getVariantId();
        }
        $ids = array_unique($ids);

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

        $query->select($this->fieldHelper->getPriceFields());
        $query->addSelect('variants.ordernumber as number');
        $query->addSelect('GREATEST(price.from, variants.minpurchase) __price_from');

        $query->from('s_articles_prices', 'price')
            ->innerJoin('price', 's_articles_details', 'variants', 'variants.id = price.articledetailsID')
            
'data' => [],
                        ],
                    ],
                    $criteria,
                    $context
                )
            );

        $response = $this->route->load($this->ids->get('productId')$request$this->createMock(SalesChannelContext::class));

        static::assertInstanceOf(FindProductVariantRouteResponse::class$response);
        static::assertEquals($this->ids->get('found1')$response->getFoundCombination()->getVariantId());
        static::assertEquals($options$response->getFoundCombination()->getOptions());
    }

    public function testLoadFirstVariantNotFound(): void
    {
        $options = [
            $this->ids->get('group1') => $this->ids->get('option1'),
            $this->ids->get('group2') => $this->ids->get('option2'),
        ];

        $request = new Request(
            [
if ($product->getUpdatedAt()) {
            $updateDate = $product->getUpdatedAt()->format('Y-m-d');
        }
        $tax = $product->getTax();
        $taxRule = $this->contextService->getShopContext()->getTaxRule($product->getTax()->getId());
        if ($taxRule instanceof Tax) {
            $tax = $taxRule;
        }

        $data = [
            'articleID' => $product->getId(),
            'articleDetailsID' => $product->getVariantId(),
            'ordernumber' => $product->getNumber(),
            'highlight' => $product->highlight(),
            'description' => $product->getShortDescription(),
            'description_long' => $product->getLongDescription(),
            'esd' => $product->hasEsd(),
            'articleName' => $product->getName(),
            'taxID' => $product->getTax()->getId(),
            'tax' => $tax->getTax(),
            'instock' => $product->getStock(),
            'isAvailable' => $product->isAvailable(),
            'hasAvailableVariant' => $product->hasAvailableVariant(),
            
return;
        }

        $reference = ReferencePriceDto::createFromCheapestPrice($cheapest);

        $definition = $this->buildDefinition($product$cheapest->getPrice()$context$units$reference);

        $calculated = CalculatedCheapestPrice::createFrom(
            $this->calculator->calculate($definition$context)
        );
        $calculated->setVariantId($cheapest->getVariantId());

        $calculated->setHasRange($cheapest->hasRange());

        $product->assign(['calculatedCheapestPrice' => $calculated]);
    }

    private function buildDefinition(
        Entity $product,
        PriceCollection $prices,
        SalesChannelContext $context,
        UnitCollection $units,
        
/** * {@inheritdoc} */
    public function getList($products, ShopContextInterface $context)
    {
        if (empty($products)) {
            return [];
        }

        $ids = [];
        foreach ($products as $product) {
            $ids[] = $product->getVariantId();
        }
        $ids = array_unique($ids);

        $data = $this->getQuery($ids$context)->execute()->fetchAll(PDO::FETCH_GROUP);

        $result = [];
        foreach ($data as $key => $groups) {
            $result[$key] = $this->configuratorHydrator->hydrateGroups($groups);
        }

        return $result;
    }
/** * {@inheritdoc} */
    public function getList(
        $products,
        ShopContextInterface $context,
        Group $customerGroup,
        Criteria $criteria
    ) {
        $variantIds = array_map(function DBaseProduct $product) {
            return $product->getVariantId();
        }$products);

        /* * Query to select the data of the cheapest price */
        $mainQuery = $this->connection->createQueryBuilder();

        /* * Contains the cheapest price logic which product price should be selected. */
        $cheapestPriceQuery = $this->getCheapestPriceQuery($mainQuery$criteria);

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