public function testToOptionArray() { $allOptions = [['types' => [['disabled' => false, 'label' => 'typeLabel', 'name' => 'typeName']], 'label' => 'optionLabel'], ['types' => [['disabled' => true]], 'label' => 'optionLabelDisabled']]; $expect = [['value' => '', 'label' => __('-- Please select --')], ['label' => 'optionLabel', 'optgroup-name' => 'optionLabel', 'value' => [['label' => 'typeLabel', 'value' => 'typeName']]]]; $this->productOptionConfig->expects($this->any())->method('getAll')->will($this->returnValue($allOptions)); $this->assertEquals($expect, $this->model->toOptionArray()); }
/** * @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']; } }
/** * {@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; }
/** * 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; }
public function testModifyMeta() { $this->priceCurrency->expects($this->any())->method('getCurrencySymbol')->willReturn('$'); $this->productOptionsConfigMock->expects($this->once())->method('getAll')->willReturn([]); $this->assertArrayHasKey(CustomOptions::GROUP_CUSTOM_OPTIONS_NAME, $this->getModel()->modifyMeta([])); }