22 class Form extends \Magento\Backend\Block\Widget\Form\Generic
90 \
Magento\Framework\Data\FormFactory $formFactory,
91 \
Magento\Directory\Model\RegionFactory $regionFactory,
92 \
Magento\Directory\Model\Config\Source\Country $country,
94 \
Magento\Tax\Helper\Data $taxData,
95 \
Magento\Tax\Api\TaxRateRepositoryInterface $taxRateRepository,
96 \
Magento\Tax\Model\TaxRateCollection $taxRateCollection,
100 $this->_regionFactory = $regionFactory;
101 $this->_country = $country;
102 $this->_fieldsetFactory = $fieldsetFactory;
103 $this->_taxData = $taxData;
104 $this->_taxRateRepository = $taxRateRepository;
105 $this->_taxRateCollection = $taxRateCollection;
106 $this->_taxRateConverter = $taxRateConverter;
115 parent::_construct();
116 $this->setDestElementId(self::FORM_ELEMENT_ID);
131 $taxRateDataObject = $this->_taxRateRepository->get($taxRateId);
133 }
catch (NoSuchEntityException $e) {
138 $formData = isset($taxRateDataObject)
139 ? $this->_taxRateConverter->createArrayFromServiceObject($taxRateDataObject)
141 $formData = array_merge($formData, $sessionFormValues);
143 if (isset($formData[
'zip_is_range']) && $formData[
'zip_is_range'] && !isset($formData[
'tax_postcode'])) {
144 $formData[
'tax_postcode'] = $formData[
'zip_from'] .
'-' . $formData[
'zip_to'];
148 $form = $this->_formFactory->create();
150 $countries = $this->_country->toOptionArray(
false,
'US');
151 unset($countries[0]);
153 if (!isset($formData[
'tax_country_id'])) {
154 $formData[
'tax_country_id'] = $this->_scopeConfig->getValue(
155 \
Magento\Tax\Model\Config::CONFIG_XML_PATH_DEFAULT_COUNTRY,
156 \
Magento\Store\Model\ScopeInterface::SCOPE_STORE
160 if (!isset($formData[
'tax_region_id'])) {
161 $formData[
'tax_region_id'] = $this->_scopeConfig->getValue(
162 \
Magento\Tax\Model\Config::CONFIG_XML_PATH_DEFAULT_REGION,
163 \
Magento\Store\Model\ScopeInterface::SCOPE_STORE
167 $regionCollection = $this->_regionFactory->create()->getCollection()->addCountryFilter(
168 $formData[
'tax_country_id']
171 $regions = $regionCollection->toOptionArray();
173 $regions[0][
'label'] =
'*';
175 $regions = [[
'value' =>
'',
'label' =>
'*']];
178 $legend = $this->getShowLegend() ?
__(
'Tax Rate Information') :
'';
179 $fieldset = $form->addFieldset(
'base_fieldset', [
'legend' => $legend,
'class' =>
'form-inline']);
181 if (isset($formData[
'tax_calculation_rate_id']) && $formData[
'tax_calculation_rate_id'] > 0) {
183 'tax_calculation_rate_id',
185 [
'name' =>
'tax_calculation_rate_id',
'value' => $formData[
'tax_calculation_rate_id']]
194 'label' =>
__(
'Tax Identifier'),
195 'title' =>
__(
'Tax Identifier'),
196 'class' =>
'required-entry',
204 [
'name' =>
'zip_is_range',
'label' =>
__(
'Zip/Post is Range'),
'value' =>
'1']
207 if (!isset($formData[
'tax_postcode'])) {
208 $formData[
'tax_postcode'] = $this->_scopeConfig->getValue(
209 \
Magento\Tax\Model\Config::CONFIG_XML_PATH_DEFAULT_POSTCODE,
210 \
Magento\Store\Model\ScopeInterface::SCOPE_STORE
218 'name' =>
'tax_postcode',
219 'label' =>
__(
'Zip/Post Code'),
221 "'*' - matches any; 'xyz*' - matches any that begins on 'xyz' and are not longer than %1.",
222 $this->_taxData->getPostCodeSubStringLength()
231 'name' =>
'zip_from',
232 'label' =>
__(
'Range From'),
235 'class' =>
'validate-digits',
236 'css_class' =>
'hidden' 245 'label' =>
__(
'Range To'),
248 'class' =>
'validate-digits',
249 'css_class' =>
'hidden' 256 [
'name' =>
'tax_region_id',
'label' =>
__(
'State'),
'values' => $regions]
262 [
'name' =>
'tax_country_id',
'label' =>
__(
'Country'),
'required' =>
true,
'values' => $countries]
270 'label' =>
__(
'Rate Percent'),
271 'title' =>
__(
'Rate Percent'),
273 'class' =>
'validate-not-negative-number' 277 $form->setAction($this->
getUrl(
'tax/rate/save'));
278 $form->setUseContainer(
true);
279 $form->setId(self::FORM_ELEMENT_ID);
280 $form->setMethod(
'post');
282 if (!$this->_storeManager->hasSingleStore()) {
283 $form->addElement($this->_fieldsetFactory->create()->setLegend(
__(
'Tax Titles')));
286 if (isset($formData[
'zip_is_range']) && $formData[
'zip_is_range']) {
287 list($formData[
'zip_from'], $formData[
'zip_to']) = explode(
'-', $formData[
'tax_postcode']);
289 $form->setValues($formData);
295 \
Magento\Framework\View\Element\Template::class
299 return parent::_prepareForm();
const CURRENT_TAX_RATE_ID
getUrl($route='', $params=[])
const CURRENT_TAX_RATE_FORM_DATA