/**
  * @param Attribute $attribute
  * @param array $config
  * @return array
  */
 protected function getAttributeOptionsData($attribute, $config)
 {
     $attributeOptionsData = [];
     foreach ($attribute->getOptions() as $attributeOption) {
         $optionId = $attributeOption['value_index'];
         $attributeOptionsData[] = ['id' => $optionId, 'label' => $attributeOption['label'], 'products' => isset($config[$attribute->getAttributeId()][$optionId]) ? $config[$attribute->getAttributeId()][$optionId] : []];
     }
     return $attributeOptionsData;
 }
示例#2
0
 /**
  * @param Option $option
  * @param Attribute $configurableAttribute
  * @return Attribute
  */
 public function getModelFromData(Option $option, Attribute $configurableAttribute)
 {
     /** @var \Magento\ConfigurableProduct\Model\Product\Type\Configurable\Attribute $returnConfigurableAttribute */
     $returnConfigurableAttribute = $this->attributeFactory->create();
     $returnConfigurableAttribute->setData($configurableAttribute->getData());
     $returnConfigurableAttribute->addData($option->__toArray());
     $returnConfigurableAttribute->setId($configurableAttribute->getId());
     $returnConfigurableAttribute->setAttributeId($configurableAttribute->getAttributeId());
     $returnConfigurableAttribute->setValues($configurableAttribute->getPrices());
     $values = $option->getValues();
     if (!is_null($values)) {
         $prices = [];
         foreach ($values as $value) {
             $prices[] = $this->valueConverter->convertArrayFromData($value);
         }
         $returnConfigurableAttribute->setValues($prices);
     }
     return $returnConfigurableAttribute;
 }