configurableProductHelper = $configurableProductHelper; $this->configurableOptionsFormatter = $configurableOptionsFormatter; } /** * Load available selections from configurable options and variant. * * @param ProductInterface $product * @param array $options * @param array $selectedOptions * @return array */ public function getAvailableSelections(ProductInterface $product, array $options, array $selectedOptions): array { $attributes = $this->getAttributes($product); $availableSelections = []; foreach ($options as $attributeId => $option) { if (in_array($attributeId, ['index','salable','canDisplayShowOutOfStockStatus']) || isset($selectedOptions[$attributeId])) { continue; } $availableSelections[] = $this->configurableOptionsFormatter->format( $attributes[$attributeId], $option ?? [] ); } return $availableSelections; } /** * Retrieve configurable attributes for the product * * @param ProductInterface $product * @return Attribute[] */ private function getAttributes(ProductInterface $product): array { $allowedAttributes = $this->configurableProductHelper->getAllowAttributes($product); $attributes = []; foreach ($allowedAttributes as $attribute) { $attributes[$attribute->getAttributeId()] = $attribute; } return $attributes; } }