本文整理汇总了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;
}
示例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);
}
示例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;
}
示例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;
}