getCombinations example


    public function testCombinationsAreInResultDeprecated(): void
    {
        if (Feature::isActive('v6.6.0.0')) {
            static::markTestSkipped('The load method has been deprecated and will be removed in v6.6.0.0');
        }

        $context = Context::createDefaultContext();
        $productId = $this->createProduct($context);
        $result = $this->loader->load($productId$context, TestDefaults::SALES_CHANNEL);

        foreach ($result->getCombinations() as $combinationHash => $combination) {
            static::assertTrue($result->hasCombination($combination));

            foreach ($combination as $optionId) {
                static::assertTrue($result->hasOptionId($optionId));
            }

            static::assertTrue(\in_array($combinationHash$result->getHashes(), true));
        }
    }

    public function testCombinationsAreInResult(): void
    {
$variantsString
        ));
    }

    /** * @param list<array<string>> $variants * * @return CombinationPayload */
    private function getCombinationsPayload(array $variants, string $parentId, string $productNumber): array
    {
        $combinations = $this->getCombinations($variants);
        $payload = [];

        foreach ($combinations as $key => $combination) {
            $options = [];

            if (\is_string($combination)) {
                $combination = [$combination];
            }

            foreach ($combination as $option) {
                [$group$option] = explode('|', $option);

                
static function DListProduct $product) {
                return $product->getId();
            },
            $products
        );

        if ($variantFacet) {
            $variantConfiguration = $this->configuratorService->getProductsConfigurations($products$context);

            $configurations = $this->configurationLoader->getConfigurations($productIds$context);

            $combinations = $this->configurationLoader->getCombinations($productIds);

            $listingPrices = $this->listingVariationLoader->getListingPrices($shop$products$variantConfiguration$variantFacet);

            $availability = $this->listingVariationLoader->getAvailability($products$variantConfiguration$variantFacet);
        }

        $manualPositions = $this->manualPositionLoader->get($productIds);

        $result = [];
        foreach ($products as $listProduct) {
            $product = Product::createFromListProduct($listProduct);
            
/** * @deprecated tag:v6.6.0 - Method will be removed. Use `loadCombinations` instead. */
    public function load(string $productId, Context $context, string $salesChannelId): AvailableCombinationResult
    {
        Feature::triggerDeprecationOrThrow(
            'v6.6.0.0',
            Feature::deprecatedMethodMessage(self::class, __METHOD__, 'loadCombinations')
        );

        $combinations = $this->getCombinations($productId$context$salesChannelId);

        $result = new AvailableCombinationResult();

        foreach ($combinations as $combination) {
            try {
                $options = json_decode((string) $combination['options'], true, 512, \JSON_THROW_ON_ERROR);
            } catch (\JsonException) {
                continue;
            }

            $available = (bool) $combination['available'];
            
if (Feature::isActive('v6.6.0.0')) {
            static::markTestSkipped('The load method has been deprecated and will be removed in v6.6.0.0');
        }

        $loader = $this->getAvailableCombinationLoader();
        $result = $loader->load(
            Uuid::randomHex(),
            Context::createDefaultContext(),
            TestDefaults::SALES_CHANNEL
        );

        $combinations = $result->getCombinations();
        static::assertSame([
            'a3f67ea263a4f2f5cf456e16de744b4b' => [
                'green',
                'red',
            ],
            'b6073234fc601007b541885dd70491f1' => [
                'green',
            ],
        ]$combinations);
    }

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