/** * Get options array. * * @param $attribute * @param bool $isEmpty * * @return array */ public function getValueSelectOptions($attribute, $isEmpty = false) { $options = []; if ($isEmpty) { $options = $this->yesno->toOptionArray(); return $options; } switch ($attribute) { case 'country_id': $options = $this->country->toOptionArray(); break; case 'region_id': $options = $this->allregion->toOptionArray(); break; case 'shipping_method': $options = $this->allShippingMethods->toOptionArray(); break; case 'method': $options = $this->allPaymentMethods->toOptionArray(); break; case 'customer_group_id': $options = $this->group->toOptionArray(); break; default: $attribute = $this->configFactory->getAttribute('catalog_product', $attribute); if ($attribute->usesSource()) { $options = $attribute->getSource()->getAllOptions(); } } return $options; }
/** * RegionList constructor. * @param \Magento\Directory\Model\ResourceModel\Country\CollectionFactory $countryCollectionFactory * @param \Magento\Directory\Model\ResourceModel\Region\CollectionFactory $regionCollectionFactory * @param \Magento\Store\Model\StoreManagerInterface $storeManager * @param \Magento\Framework\View\Element\Context $context * @param Config $config */ public function __construct(\Magento\Directory\Model\ResourceModel\Country\CollectionFactory $countryCollectionFactory, \Magento\Directory\Model\ResourceModel\Region\CollectionFactory $regionCollectionFactory, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\View\Element\Context $context, Config $config) { $this->storeManager = $storeManager; $this->request = $context->getRequest(); $this->config = $config; return parent::__construct($countryCollectionFactory, $regionCollectionFactory); }
/** * Get value select options * * @return array|mixed */ public function getValueSelectOptions() { if (!$this->hasData('value_select_options')) { switch ($this->getAttribute()) { case 'country_id': $options = $this->_directoryCountry->toOptionArray(); break; case 'region_id': $options = $this->_directoryAllregion->toOptionArray(); break; case 'shipping_method': $options = $this->_shippingAllmethods->toOptionArray(); break; case 'payment_method': $options = $this->_paymentAllmethods->toOptionArray(); break; default: $options = []; } $this->setData('value_select_options', $options); } return $this->getData('value_select_options'); }