/** * Convert option data object value to array representation * * @param \Magento\Catalog\Service\V1\Product\CustomOptions\Data\Option $option * @return array */ public function convert(\Magento\Catalog\Service\V1\Product\CustomOptions\Data\Option $option) { /** @var Metadata $value */ $value = current($option->getMetadata()); $output = [Metadata::PRICE => $value->getPrice(), Metadata::PRICE_TYPE => $value->getPriceType(), Metadata::SKU => $value->getSku()]; foreach ($value->getCustomAttributes() as $attribute) { $output[$attribute->getAttributeCode()] = $attribute->getValue(); } return $output; }
/** * {@inheritdoc} */ public function convert(Option $option) { $output = []; foreach ($option->getMetadata() as $value) { $attributes = $value->getCustomAttributes(); $valueItem = [Metadata::PRICE => $value->getPrice(), Metadata::PRICE_TYPE => $value->getPriceType(), Metadata::SKU => $value->getSku()]; foreach ($attributes as $attribute) { $valueItem[$attribute->getAttributeCode()] = $attribute->getValue(); } $output[] = $valueItem; } return ['values' => $output]; }