当前位置: 首页>>代码示例>>PHP>>正文


PHP Data::getRegionJson方法代码示例

本文整理汇总了PHP中Magento\Directory\Helper\Data::getRegionJson方法的典型用法代码示例。如果您正苦于以下问题:PHP Data::getRegionJson方法的具体用法?PHP Data::getRegionJson怎么用?PHP Data::getRegionJson使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\Directory\Helper\Data的用法示例。


在下文中一共展示了Data::getRegionJson方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: render

 /**
  * Output the region element and javasctipt that makes it dependent from country element
  *
  * @param \Magento\Framework\Data\Form\Element\AbstractElement $element
  * @return string
  *
  * @SuppressWarnings(PHPMD.UnusedLocalVariable)
  */
 public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element)
 {
     if ($country = $element->getForm()->getElement('country_id')) {
         $countryId = $country->getValue();
     } else {
         return $element->getDefaultHtml();
     }
     $regionId = $element->getForm()->getElement('region_id')->getValue();
     $html = '<div class="field field-state required">';
     $element->setClass('input-text');
     $element->setRequired(true);
     $html .= $element->getLabelHtml() . '<div class="control">';
     $html .= $element->getElementHtml();
     $selectName = str_replace('region', 'region_id', $element->getName());
     $selectId = $element->getHtmlId() . '_id';
     $html .= '<select id="' . $selectId . '" name="' . $selectName . '" class="select required-entry" style="display:none">';
     $html .= '<option value="">' . __('Please select') . '</option>';
     $html .= '</select>';
     $html .= '<script>' . "\n";
     $html .= 'require(["prototype", "mage/adminhtml/form"], function(){';
     $html .= '$("' . $selectId . '").setAttribute("defaultValue", "' . $regionId . '");' . "\n";
     $html .= 'new regionUpdater("' . $country->getHtmlId() . '", "' . $element->getHtmlId() . '", "' . $selectId . '", ' . $this->_directoryHelper->getRegionJson() . ');' . "\n";
     $html .= '});';
     $html .= '</script>' . "\n";
     $html .= '</div></div>' . "\n";
     return $html;
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:35,代码来源:Region.php

示例2: testGetRegionJson

 public function testGetRegionJson()
 {
     $countries = array(new \Magento\Framework\Object(array('country_id' => 'Country1')), new \Magento\Framework\Object(array('country_id' => 'Country2')));
     $countryIterator = new \ArrayIterator($countries);
     $this->_countryCollection->expects($this->atLeastOnce())->method('getIterator')->will($this->returnValue($countryIterator));
     $regions = array(new \Magento\Framework\Object(array('country_id' => 'Country1', 'region_id' => 'r1', 'code' => 'r1-code', 'name' => 'r1-name')), new \Magento\Framework\Object(array('country_id' => 'Country1', 'region_id' => 'r2', 'code' => 'r2-code', 'name' => 'r2-name')), new \Magento\Framework\Object(array('country_id' => 'Country2', 'region_id' => 'r3', 'code' => 'r3-code', 'name' => 'r3-name')));
     $regionIterator = new \ArrayIterator($regions);
     $this->_regionCollection->expects($this->once())->method('addCountryFilter')->with(array('Country1', 'Country2'))->will($this->returnSelf());
     $this->_regionCollection->expects($this->once())->method('load');
     $this->_regionCollection->expects($this->once())->method('getIterator')->will($this->returnValue($regionIterator));
     $expectedDataToEncode = array('config' => array('show_all_regions' => false, 'regions_required' => array()), 'Country1' => array('r1' => array('code' => 'r1-code', 'name' => 'r1-name'), 'r2' => array('code' => 'r2-code', 'name' => 'r2-name')), 'Country2' => array('r3' => array('code' => 'r3-code', 'name' => 'r3-name')));
     $this->_coreHelper->expects($this->once())->method('jsonEncode')->with(new \PHPUnit_Framework_Constraint_IsIdentical($expectedDataToEncode))->will($this->returnValue('encoded_json'));
     // Test
     $result = $this->_object->getRegionJson();
     $this->assertEquals('encoded_json', $result);
 }
开发者ID:buskamuza,项目名称:magento2-skeleton,代码行数:16,代码来源:DataTest.php

示例3: _getElementHtml

 /**
  * @param AbstractElement $element
  * @return string
  */
 protected function _getElementHtml(AbstractElement $element)
 {
     $html = parent::_getElementHtml($element);
     $js = '<script type="text/javascript">
            var updater = new RegionUpdater("tax_defaults_country", "none", "tax_defaults_region", %s, "nullify");
            if(updater.lastCountryId) {
                var tmpRegionId = $("tax_defaults_region").value;
                var tmpCountryId = updater.lastCountryId;
                updater.lastCountryId=false;
                updater.update();
                updater.lastCountryId = tmpCountryId;
                $("tax_defaults_region").value = tmpRegionId;
            } else {
                updater.update();
            }
            </script>';
     $html .= sprintf($js, $this->_directoryHelper->getRegionJson());
     return $html;
 }
开发者ID:Atlis,项目名称:docker-magento2,代码行数:23,代码来源:Updater.php

示例4: _getElementHtml

 /**
  * @param AbstractElement $element
  * @return string
  */
 protected function _getElementHtml(AbstractElement $element)
 {
     $html = parent::_getElementHtml($element);
     $html .= "<script type=\"text/javascript\">" . "require(['mage/adminhtml/form'], function(){" . "window.updater = new RegionUpdater('tax_defaults_country'," . " 'tax_region', 'tax_defaults_region', " . $this->_directoryHelper->getRegionJson() . ", 'disable');});</script>";
     return $html;
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:10,代码来源:Updater.php


注:本文中的Magento\Directory\Helper\Data::getRegionJson方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。