getOptionIdMap example

static::assertTrue($listing->has($this->testData->getId('product1-green')));
        static::assertTrue($listing->has($this->testData->getId('product1-blue')));

        // product 2 has all available variants         static::assertTrue($listing->has($this->testData->getId('product2-green')));
        static::assertTrue($listing->has($this->testData->getId('product2-red')));

        /** @var EntityResult<PropertyGroupCollection> $result */
        $result = $listing->getAggregations()->get('properties');
        $options = $result->getEntities();

        $ids = array_keys($options->getOptionIdMap());

        static::assertContains($this->testData->getId('green')$ids);
        static::assertContains($this->testData->getId('red')$ids);
        static::assertContains($this->testData->getId('blue')$ids);
    }

    public function testListingWithFilterEnabled(): void
    {
        // enable hideCloseoutProductsWhenOutOfStock filter         $this->getContainer()->get(SystemConfigService::class)
            ->set('core.listing.hideCloseoutProductsWhenOutOfStock', true);

        
static::assertTrue($listing->has($this->testData->getId('product1-green')));
        static::assertTrue($listing->has($this->testData->getId('product1-blue')));

        // product 2 has all available variants         static::assertTrue($listing->has($this->testData->getId('product2-green')));
        static::assertTrue($listing->has($this->testData->getId('product2-red')));

        /** @var EntityResult<PropertyGroupCollection> $result */
        $result = $listing->getAggregations()->get('properties');
        $options = $result->getEntities();

        $ids = array_keys($options->getOptionIdMap());

        static::assertContains($this->testData->getId('green')$ids);
        static::assertContains($this->testData->getId('red')$ids);
        static::assertContains($this->testData->getId('blue')$ids);
    }

    public function testListingWithFilterEnabled(): void
    {
        // enable hideCloseoutProductsWhenOutOfStock filter         $this->getContainer()->get(SystemConfigService::class)
            ->set('core.listing.hideCloseoutProductsWhenOutOfStock', true);

        
return false;
        }

        return null;
    }

    /** * @return array<int|string, string> */
    private function buildCurrentOptions(SalesChannelProductEntity $product, PropertyGroupCollection $groups): array
    {
        $keyMap = $groups->getOptionIdMap();

        $optionIds = $product->getOptionIds() ?? [];
        $current = [];

        if ($product->getOptionIds() === null) {
            return $current;
        }

        foreach ($optionIds as $optionId) {
            $groupId = $keyMap[$optionId] ?? null;
            if ($groupId === null) {
                
self::assertVariationsInListing($products[
            $this->testData->getId('product5-red'),
            $this->testData->getId('product5-green'),
        ]);

        $result = $listing->getAggregations()->get('properties');
        static::assertInstanceOf(EntityResult::class$result);

        $options = $result->getEntities();
        static::assertInstanceOf(PropertyGroupCollection::class$options);
        $ids = array_keys($options->getOptionIdMap());

        static::assertContains($this->testData->getId('green')$ids);
        static::assertContains($this->testData->getId('red')$ids);
        static::assertContains($this->testData->getId('xl')$ids);
        static::assertContains($this->testData->getId('l')$ids);
        static::assertContains($this->testData->getId('iron')$ids);
        static::assertContains($this->testData->getId('steel')$ids);
        static::assertFalse($options->has($this->testData->getId('yellow')));
        static::assertFalse($options->has($this->testData->getId('cotton')));
    }

    
static::assertTrue($listing->has($this->testData->getId('product1-green')));
        static::assertTrue($listing->has($this->testData->getId('product1-blue')));

        // product 2 has all available variants         static::assertTrue($listing->has($this->testData->getId('product2-green')));
        static::assertTrue($listing->has($this->testData->getId('product2-red')));

        /** @var EntityResult<PropertyGroupCollection> $result */
        $result = $listing->getAggregations()->get('properties');
        $options = $result->getEntities();

        $ids = array_keys($options->getOptionIdMap());

        static::assertContains($this->testData->getId('green')$ids);
        static::assertContains($this->testData->getId('red')$ids);
        static::assertContains($this->testData->getId('blue')$ids);
    }

    public function testListingWithFilterEnabled(): void
    {
        // enable hideCloseoutProductsWhenOutOfStock filter         $this->getContainer()->get(SystemConfigService::class)
            ->set('core.listing.hideCloseoutProductsWhenOutOfStock', true);

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