Sonata\ProductBundle\Model\BaseProductProvider::getVariationsChoices PHP Method

getVariationsChoices() public method

public getVariationsChoices ( Sonata\Component\Product\ProductInterface $product, array $fields = [] )
$product Sonata\Component\Product\ProductInterface
$fields array
    public function getVariationsChoices(ProductInterface $product, array $fields = array())
    {
        if (!($this->hasEnabledVariations($product) || $product->getParent())) {
            // Product is neither master nor a variation, not concerned
            return array();
        }
        $fields = $this->getMergedFields($fields);
        // We retrieve the variations fresh from DB so we may find the values
        $variations = $this->getEnabledVariations($product->getParent() ?: $product);
        $accessor = PropertyAccess::createPropertyAccessor();
        $choices = array();
        foreach ($variations as $mVariation) {
            foreach ($fields as $field) {
                $variationValue = $accessor->getValue($mVariation, $field);
                if (!array_key_exists($field, $choices) || !in_array($variationValue, $choices[$field])) {
                    $choices = array_merge_recursive($choices, array($field => array($variationValue)));
                }
            }
        }
        // Sort options
        foreach ($fields as $field) {
            natcasesort($choices[$field]);
        }
        return $choices;
    }