searchForOptions example



    #[Route(path: '/store-api/product/{productId}/find-variant', name: 'store-api.product.find-variant', methods: ['POST'], defaults: ['_entity' => 'product'])]     public function load(string $productId, Request $request, SalesChannelContext $context): FindProductVariantRouteResponse
    {
        /** @var string|null $switchedGroup */
        $switchedGroup = $request->get('switchedGroup');

        /** @var array<string, string> $options */
        $options = $request->get('options') ? $request->get('options', []) : [];

        $variantId = $this->searchForOptions($productId$context$options);

        if ($variantId !== null) {
            return new FindProductVariantRouteResponse(new FoundCombination($variantId$options));
        }

        while (\count($options) > 1) {
            foreach ($options as $groupId => $_optionId) {
                if ($groupId !== $switchedGroup) {
                    unset($options[$groupId]);

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