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
166328
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;
    }
277331
public function createProductAttribute(
        Attribute $attribute,
        ProductInterface $product,
        AttributeValue $attributeValue
    ) {
        $productAttribute = $this->productAttributeRepository->createNew();
        $productAttribute->setAttribute($attribute);
        $productAttribute->setProduct($product);
        $productAttribute->setAttributeValue($attributeValue);
        $this->entityManager->persist($productAttribute);

        $product->addProductAttribute($productAttribute);

        return $productAttribute;
    }
126601
public function syncWithProductType(ProductTypeContract $productType, $attributeIds, array $requiredAttributes = [])
    {
        $attributeIds = is_array($attributeIds) ? $attributeIds : [$attributeIds];

        $pivot = [];
        foreach ($attributeIds as $id) {
            $pivot[$id] = ['required' => in_array($id, $requiredAttributes)];
        }

        return $productType->attributes()->sync($pivot);
    }
1198204
private function initField(AttributeInterface $attribute)
    {
        $fieldName = $attribute->getAttributeCode();
        $fieldConfig = $this->attributeHelper->getMappingFieldOptions($attribute);

        if ($attribute->usesSource()) {
            $optionFieldName = $this->attributeHelper->getOptionTextFieldName($fieldName);
            $fieldType = FieldInterface::FIELD_TYPE_TEXT;
            $fieldOptions = ['name' => $optionFieldName, 'type' => $fieldType, 'fieldConfig' => $fieldConfig];
            $this->fields[$optionFieldName] = $this->fieldFactory->create($fieldOptions);

            // Reset parent field values : only the option text field should be used for spellcheck and autocomplete.
            $fieldConfig['is_used_in_spellcheck'] = false;
            $fieldConfig['is_searchable'] = false;
        }

        $fieldType    = $this->attributeHelper->getFieldType($attribute);
        $fieldOptions = ['name' => $fieldName, 'type' => $fieldType, 'fieldConfig' => $fieldConfig];

        $this->fields[$fieldName] = $this->fieldFactory->create($fieldOptions);

        return $this;
    }
1333697
private function getAttributesArrayFromLoadedProduct($product)
    {
        //attributes array from loaded product
        $attributes = $this->config->getEntityAttributes(
            \Magento\Catalog\Model\Product::ENTITY,
            $product
        );

        return array_keys($attributes);
    }
944359
public function indexAction(ProductInterface $product, ProductTranslation $translation)
    {
        $apiProduct = $this->getProductFactory()->createApiEntity($product, $translation->getLocale());

        return $this->render(
            $this->getProductViewTemplate(),
            [
                'product' => $apiProduct,
                'urls' => $this->getAllRoutesOfProduct($product),
            ]
        );
    }
491477
public function toOptionArray()
    {
        $defaultOptions = $this->defaultOptions();
        $productCondition = $this->productFactory;
        $productAttributes = $productCondition->loadAttributeOptions()
            ->getAttributeOption();
        $pAttributes = [];
        foreach ($productAttributes as $code => $label) {
            if (strpos($code, 'quote_item_') === false) {
                $pAttributes[$code] = $label;
            }
        }
        $options = array_merge($defaultOptions, $pAttributes);

        return $options;
    }
929115
public function getLineItemForProduct(Product $product)
    {
        // Find the Order within this OrderCollection for the Product's Seller
        $order = $this->getOrderForSeller($product->getSeller());

        $lineItem = $order->getLineItemForProduct($product);

        return $lineItem;
    }
1272133
function productOptionInformation( $objectAttribute, $optionID, $productItem )
    {
        $multioption = $objectAttribute->attribute( 'content' );

        foreach ( $multioption->attribute( 'multioption_list' ) as $multioptionElement )
        {
            foreach ( $multioptionElement['optionlist'] as $option )
            {
                if ( $option['option_id'] != $optionID )
                    continue;

                return array( 'id' => $option['option_id'],
                              'name' => $multioptionElement['name'],
                              'value' => $option['value'],
                              'additional_price' => $option['additional_price'] );
            }
        }
    }
482730
protected function getAttributeContext(
        DataInterface $object,
        $attribute,
        /** @noinspection PhpUnusedParameterInspection */
        $rawValue,
        array $context
    ) {
        return array_merge(
            $context,
            [
                'parent' => $object,
                'attribute' => $attribute,
            ]
        );
    }
25915
protected function attachFields(array &$product)
    {
        if (empty($product)) {
            return $product;
        }

        $product['field'] = $this->product_field->getList($product['product_id']);

        if (empty($product['field']['option'])) {
            return $product;
        }

        foreach ($product['field']['option'] as &$field_values) {
            $field_values = array_unique($field_values);
        }

        return $product;
    }
25745
public function renderPropertiesAction(ProductInterface $product)
    {
        $provider = $this->get('sonata.product.pool')->getProvider($product);

        return $this->render(sprintf('%s:properties.html.twig', $provider->getBaseControllerName()), [
            'product' => $product,
        ]);
    }
166292
public function getValueSelectOptions($attribute, $isEmpty = false)
    {
        $options = [];
        if ($isEmpty) {
            $options
                = $this->yesno->toOptionArray();

            return $options;
        }

        switch ($attribute) {
            case 'country_id':
                $options = $this->country->toOptionArray();
                break;

            case 'region_id':
                $options = $this->allregion->toOptionArray();
                break;

            case 'shipping_method':
                $options = $this->allShippingMethods->toOptionArray();
                break;

            case 'method':
                $options = $this->allPaymentMethods->toOptionArray();
                break;

            case 'customer_group_id':
                $options = $this->sourceGroup->toOptionArray();
                break;

            default:
                $attribute
                    = $this->configFactory->getAttribute(
                        'catalog_product',
                        $attribute
                    );
                if ($attribute->usesSource()) {
                    $options = $attribute->getSource()->getAllOptions();
                }
        }

        return $options;
    }
799389
protected function getAttributes(ContentInterface $owner)
    {
        /** @var AttributeInterface $attributes */
        $attributes = $owner->getValueSet()->getAttributes();

        $choices = [];
        foreach ($attributes as $attribute) {
            if (!in_array($attribute->getValueType(), ['select', 'radio', 'checklist'])) {
                continue;
            }
            $choices[$attribute->getDisplayName()] = $attribute->getName();
        }

        return $choices;
    }
713036
public function getConverterOptions($converter, $attribute)
    {
        $lcAttr = strtolower($attribute);

        $options = [];
        if (isset($this->converterOptions[$converter]) && isset($this->converterOptions[$converter][$lcAttr])) {
            $options = $this->converterOptions[$converter][$lcAttr];
        }

        return $options;
    }
1088214
public function getFilterField(AttributeInterface $attribute)
    {
        $field = $attribute->getAttributeCode();

        if ($attribute->usesSource()) {
            $field = $this->getOptionTextFieldName($field);
        }

        return $field;
    }
222840
function productOptionInformation( $objectAttribute, $optionID, $productItem )
    {
        $option = $objectAttribute->attribute( 'content' );
        foreach( $option->attribute( 'option_list' ) as $optionArray )
        {
            if ( $optionArray['id'] == $optionID )
            {
                return array( 'id' => $optionArray['id'],
                              'name' => $option->attribute( 'name' ),
                              'value' => $optionArray['value'],
                              'additional_price' => $optionArray['additional_price'] );
            }
        }
        return false;
    }