예제 #1
0
 /**
  * Convert configurable attribute to option data object
  *
  * @param Attribute $configurableAttribute
  * @return \Magento\ConfigurableProduct\Service\V1\Data\Option
  */
 public function convertFromModel(Attribute $configurableAttribute)
 {
     $values = [];
     $prices = $configurableAttribute->getPrices();
     if (is_array($prices)) {
         foreach ($prices as $price) {
             $values[] = $this->valueBuilder->setIndex($price['value_index'])->setPrice($price['pricing_value'])->setPercent($price['is_percent'])->create();
         }
     }
     $data = [Option::ID => $configurableAttribute->getId(), Option::ATTRIBUTE_ID => $configurableAttribute->getAttributeId(), Option::LABEL => $configurableAttribute->getLabel(), Option::TYPE => $configurableAttribute->getProductAttribute()->getFrontend()->getInputType(), Option::POSITION => $configurableAttribute->getPosition(), Option::USE_DEFAULT => $configurableAttribute->getData('use_default'), Option::VALUES => $values];
     return $this->optionBuilder->populateWithArray($data)->create();
 }