Ejemplo n.º 1
0
 /**
  * @return array|null
  */
 public function getCountries()
 {
     if (null === $this->_countries) {
         $this->_countries = $this->_sourceCountry->toOptionArray();
     }
     return $this->_countries;
 }
Ejemplo n.º 2
0
 /**
  * Retrieve countries
  *
  * @return array|null
  */
 protected function getCountries()
 {
     if (null === $this->countries) {
         $this->countries = $this->sourceCountry->toOptionArray();
     }
     return $this->countries;
 }
 /**
  * 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;
 }
Ejemplo n.º 4
0
 /**
  * @param bool $noEmpty
  * @return array
  */
 public function toOptionArray($noEmpty = false)
 {
     $options = parent::toOptionArray($noEmpty);
     if (!$noEmpty) {
         if ($options) {
             $options[0]['label'] = __('None');
         } else {
             $options = [['value' => '', 'label' => __('None')]];
         }
     }
     return $options;
 }
Ejemplo n.º 5
0
 /**
  * @return array
  */
 public function getSepaCountries()
 {
     $sepaCountriesAllowed = ["AT", "BE", "BG", "CH", "CY", "CZ", "DE", "DK", "EE", "ES", "FI", "FR", "GB", "GF", "GI", "GP", "GR", "HR", "HU", "IE", "IS", "IT", "LI", "LT", "LU", "LV", "MC", "MQ", "MT", "NL", "NO", "PL", "PT", "RE", "RO", "SE", "SI", "SK"];
     $countryList = $this->_country->toOptionArray();
     $sepaCountries = [];
     foreach ($countryList as $key => $country) {
         $value = $country['value'];
         if (in_array($value, $sepaCountriesAllowed)) {
             $sepaCountries[$value] = $country['label'];
         }
     }
     return $sepaCountries;
 }
Ejemplo n.º 6
0
 /**
  * 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');
 }
Ejemplo n.º 7
0
 /**
  * @param bool $isMultiselect
  * @return array
  */
 public function toOptionArray($isMultiselect = false)
 {
     return parent::toOptionArray(true);
 }
Ejemplo n.º 8
0
 /**
  * @return $this
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 protected function _prepareForm()
 {
     $taxRateId = $this->_coreRegistry->registry(RegistryConstants::CURRENT_TAX_RATE_ID);
     try {
         if ($taxRateId) {
             $taxRateDataObject = $this->_taxRateRepository->get($taxRateId);
         }
     } catch (NoSuchEntityException $e) {
         /* tax rate not found */
     }
     $sessionFormValues = (array) $this->_coreRegistry->registry(RegistryConstants::CURRENT_TAX_RATE_FORM_DATA);
     $formData = isset($taxRateDataObject) ? $this->extractTaxRateData($taxRateDataObject) : [];
     $formData = array_merge($formData, $sessionFormValues);
     if (isset($formData['zip_is_range']) && $formData['zip_is_range'] && !isset($formData['tax_postcode'])) {
         $formData['tax_postcode'] = $formData['zip_from'] . '-' . $formData['zip_to'];
     }
     /** @var \Magento\Framework\Data\Form $form */
     $form = $this->_formFactory->create();
     $countries = $this->_country->toOptionArray(false, 'US');
     unset($countries[0]);
     if (!isset($formData['tax_country_id'])) {
         $formData['tax_country_id'] = $this->_scopeConfig->getValue(\Magento\Tax\Model\Config::CONFIG_XML_PATH_DEFAULT_COUNTRY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
     }
     if (!isset($formData['tax_region_id'])) {
         $formData['tax_region_id'] = $this->_scopeConfig->getValue(\Magento\Tax\Model\Config::CONFIG_XML_PATH_DEFAULT_REGION, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
     }
     $regionCollection = $this->_regionFactory->create()->getCollection()->addCountryFilter($formData['tax_country_id']);
     $regions = $regionCollection->toOptionArray();
     if ($regions) {
         $regions[0]['label'] = '*';
     } else {
         $regions = [['value' => '', 'label' => '*']];
     }
     $legend = $this->getShowLegend() ? __('Tax Rate Information') : '';
     $fieldset = $form->addFieldset('base_fieldset', ['legend' => $legend, 'class' => 'form-inline']);
     if (isset($formData['tax_calculation_rate_id']) && $formData['tax_calculation_rate_id'] > 0) {
         $fieldset->addField('tax_calculation_rate_id', 'hidden', ['name' => 'tax_calculation_rate_id', 'value' => $formData['tax_calculation_rate_id']]);
     }
     $fieldset->addField('code', 'text', ['name' => 'code', 'label' => __('Tax Identifier'), 'title' => __('Tax Identifier'), 'class' => 'required-entry', 'required' => true]);
     $fieldset->addField('zip_is_range', 'checkbox', ['name' => 'zip_is_range', 'label' => __('Zip/Post is Range'), 'value' => '1']);
     if (!isset($formData['tax_postcode'])) {
         $formData['tax_postcode'] = $this->_scopeConfig->getValue(\Magento\Tax\Model\Config::CONFIG_XML_PATH_DEFAULT_POSTCODE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
     }
     $fieldset->addField('tax_postcode', 'text', ['name' => 'tax_postcode', 'label' => __('Zip/Post Code'), 'note' => __("'*' - matches any; 'xyz*' - matches any that begins on 'xyz' and are not longer than %1.", $this->_taxData->getPostCodeSubStringLength())]);
     $fieldset->addField('zip_from', 'text', ['name' => 'zip_from', 'label' => __('Range From'), 'required' => true, 'maxlength' => 9, 'class' => 'validate-digits', 'css_class' => 'hidden']);
     $fieldset->addField('zip_to', 'text', ['name' => 'zip_to', 'label' => __('Range To'), 'required' => true, 'maxlength' => 9, 'class' => 'validate-digits', 'css_class' => 'hidden']);
     $fieldset->addField('tax_region_id', 'select', ['name' => 'tax_region_id', 'label' => __('State'), 'values' => $regions]);
     $fieldset->addField('tax_country_id', 'select', ['name' => 'tax_country_id', 'label' => __('Country'), 'required' => true, 'values' => $countries]);
     $fieldset->addField('rate', 'text', ['name' => 'rate', 'label' => __('Rate Percent'), 'title' => __('Rate Percent'), 'required' => true, 'class' => 'validate-not-negative-number']);
     $form->setAction($this->getUrl('tax/rate/save'));
     $form->setUseContainer(true);
     $form->setId(self::FORM_ELEMENT_ID);
     $form->setMethod('post');
     if (!$this->_storeManager->hasSingleStore()) {
         $form->addElement($this->_fieldsetFactory->create()->setLegend(__('Tax Titles')));
     }
     if (isset($formData['zip_is_range']) && $formData['zip_is_range']) {
         list($formData['zip_from'], $formData['zip_to']) = explode('-', $formData['tax_postcode']);
     }
     $form->setValues($formData);
     $this->setForm($form);
     $this->setChild('form_after', $this->getLayout()->createBlock('Magento\\Framework\\View\\Element\\Template')->setTemplate('Magento_Tax::rate/js.phtml'));
     return parent::_prepareForm();
 }
 /**
  * @return array
  */
 public function toOptionArray()
 {
     // Make US and CA show at top of list
     return parent::toOptionArray(true, \ClassyLlama\AvaTax\Helper\Config::$taxCalculationCountriesDefault);
 }
Ejemplo n.º 10
-1
 /**
  * @dataProvider toOptionArrayDataProvider
  * @param boolean $isMultiselect
  * @param string|array $foregroundCountries
  * @param array $expectedResult
  */
 public function testToOptionArray($isMultiselect, $foregroundCountries, $expectedResult)
 {
     $this->_collectionMock->expects($this->once())->method('loadData')->will($this->returnSelf());
     $this->_collectionMock->expects($this->once())->method('setForegroundCountries')->with($foregroundCountries)->will($this->returnSelf());
     $this->_collectionMock->expects($this->once())->method('toOptionArray')->will($this->returnValue([]));
     $this->assertEquals($this->_model->toOptionArray($isMultiselect, $foregroundCountries), $expectedResult);
 }