public function findByOptionIds(ProductInterface $product, array $optionsSearchedIds = [])
    {
        sort($optionsSearchedIds);

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

            /**
             * @var VariantInterface $variant
             */
            $optionsConfiguredIds = array_map(
                function (ValueInterface $option) {
                    return $option->getId();
                },
                $variant->getOptions()->toArray()
            );

            sort($optionsConfiguredIds);

            if ($optionsSearchedIds == $optionsConfiguredIds) {
                /**
                 * Options match, we found the product Variant.
                 */

                return $variant;
            }
        }

        /**
         * No match, probable option misconfiguration in Variants.
         */

        return null;
    }
public function findByOptionIds(ProductInterface $product, array $optionsSearchedIds = [])
    {
        sort($optionsSearchedIds);

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

            /**
             * @var VariantInterface $variant
             */
            $optionsConfiguredIds = array_map(
                function (ValueInterface $option) {
                    return $option->getId();
                },
                $variant->getOptions()->toArray()
            );

            sort($optionsConfiguredIds);

            if ($optionsSearchedIds == $optionsConfiguredIds) {
                /**
                 * Options match, we found the product Variant.
                 */

                return $variant;
            }
        }

        /**
         * No match, probable option misconfiguration in Variants.
         */

        return null;
    }
public function findByOptionIds ( ProductInterface $ product , array $ optionsSearchedIds = [ ] ) { sort ( $ optionsSearchedIds ) ; foreach ( $ product -> getVariants ( ) as $ variant ) { /**
             * @var VariantInterface $variant
             */ $ optionsConfiguredIds = array_map ( function ( ValueInterface $ option ) { return $ option -> getId ( ) ; } , $ variant -> getOptions ( ) -> toArray ( ) ) ; sort ( $ optionsConfiguredIds ) ; if ( $ optionsSearchedIds == $ optionsConfiguredIds ) { /**
                 * Options match, we found the product Variant.
                 */ return $ variant ; } } /**
         * No match, probable option misconfiguration in Variants.
         */ return null ; }
Given a Product and an array of integer representing the IDs of a Value Entity,
returns the Variant that is associated with the options matching the IDs, if any.

@param ProductInterface $product            to compare Variants from
@param array            $optionsSearchedIds array containing IDs of the options to match

@return VariantInterface|null Variant if found, or null if not
Given a Product and an array of integer representing the IDs of a Value Entity returns the Variant that is associated with the options matching the IDs if any .