/** * {@inheritdoc} */ public function getTypes() { $output = []; foreach ($this->productOptionConfig->getAll() as $option) { foreach ($option['types'] as $type) { if ($type['disabled']) { continue; } $itemData = [Data\OptionType::LABEL => __($type['label']), Data\OptionType::CODE => $type['name'], Data\OptionType::GROUP => __($option['label'])]; $output[] = $this->optionTypeBuilder->populateWithArray($itemData)->create(); } } return $output; }
/** * @return $this */ protected function _prepareLayout() { foreach ($this->_productOptionConfig->getAll() as $option) { $this->addChild($option['name'] . '_option_type', $option['renderer']); } return parent::_prepareLayout(); }
/** * {@inheritdoc} */ public function toOptionArray() { $groups = [['value' => '', 'label' => __('-- Please select --')]]; foreach ($this->_productOptionConfig->getAll() as $option) { $types = []; foreach ($option['types'] as $type) { if ($type['disabled']) { continue; } $types[] = ['label' => __($type['label']), 'value' => $type['name']]; } if (count($types)) { $groups[] = ['label' => __($option['label']), 'value' => $types]; } } return $groups; }
/** * @param \Magento\Catalog\Model\ProductOptions\ConfigInterface $productOptionConfig * @param \Magento\Catalog\Model\Config\Source\Product\Options\Price $priceConfig */ public function __construct(\Magento\Catalog\Model\ProductOptions\ConfigInterface $productOptionConfig, \Magento\Catalog\Model\Config\Source\Product\Options\Price $priceConfig) { foreach ($productOptionConfig->getAll() as $option) { foreach ($option['types'] as $type) { $this->productOptionTypes[] = $type['name']; } } foreach ($priceConfig->toOptionArray() as $item) { $this->priceTypes[] = $item['value']; } }
/** * Get options for drop-down control with product option types * * @return array */ protected function getProductOptionTypes() { $options = []; $groupIndex = 0; foreach ($this->productOptionsConfig->getAll() as $option) { $group = ['value' => $groupIndex, 'label' => $option['label'], 'optgroup' => []]; foreach ($option['types'] as $type) { if ($type['disabled']) { continue; } //TODO: Wrap label with __() or remove this TODO after MAGETWO-49771 is closed $group['optgroup'][] = ['label' => $type['label'], 'value' => $type['name']]; } if (count($group['optgroup'])) { $options[] = $group; $groupIndex += 1; } } return $options; }