public function getAvailableOptions(
        ProductInterface $product,
        AttributeInterface $attribute
    ) {
        $availableOptions = new ArrayCollection();

        foreach ($product->getVariants() as $variant) {

            /**
             * @var VariantInterface $variant
             */
            if (!$variant->isEnabled() || $variant->getStock() <= 0) {
                continue;
            }

            foreach ($variant->getOptions() as $option) {
                /**
                 * @var ValueInterface $option
                 */
                if ($option->getAttribute() == $attribute &&
                    !$availableOptions->contains($option)
                ) {
                    $availableOptions->add($option);
                }
            }
        }

        return $availableOptions;
    }
public function getAvailableOptions(
        ProductInterface $product,
        AttributeInterface $attribute
    ) {
        $availableOptions = new ArrayCollection();

        foreach ($product->getVariants() as $variant) {

            /**
             * @var VariantInterface $variant
             */
            if (!$variant->isEnabled() || $variant->getStock() <= 0) {
                continue;
            }

            foreach ($variant->getOptions() as $option) {
                /**
                 * @var ValueInterface $option
                 */
                if ($option->getAttribute() == $attribute &&
                    !$availableOptions->contains($option)
                ) {
                    $availableOptions->add($option);
                }
            }
        }

        return $availableOptions;
    }
public function getAvailableOptions ( ProductInterface $ product , AttributeInterface $ attribute ) { $ availableOptions = new ArrayCollection ( ) ; foreach ( $ product -> getVariants ( ) as $ variant ) { /**
             * @var VariantInterface $variant
             */ if ( ! $ variant -> isEnabled ( ) || $ variant -> getStock ( ) <= 0 ) { continue ; } foreach ( $ variant -> getOptions ( ) as $ option ) { /**
                 * @var ValueInterface $option
                 */ if ( $ option -> getAttribute ( ) == $ attribute && ! $ availableOptions -> contains ( $ option ) ) { $ availableOptions -> add ( $ option ) ; } } } return $ availableOptions ; }
Returns an array of unique available options for a Product.

Returned Options belong to Variants available for purchase

@param ProductInterface   $product   Product
@param AttributeInterface $attribute Attribute

@return ArrayCollection
Returns an array of unique available options for a Product .