本文整理汇总了PHP中Magento\Directory\Helper\Data类的典型用法代码示例。如果您正苦于以下问题:PHP Data类的具体用法?PHP Data怎么用?PHP Data使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Data类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testGetConfigurationCountryCodeFromDefault
/**
* @param string|null $request
* @param string|null|false $config
* @param string|null $default
* @dataProvider getConfigurationCountryCodeFromDefaultDataProvider
*/
public function testGetConfigurationCountryCodeFromDefault($request, $config, $default)
{
$this->_configurationCountryCodePrepareRequest($request);
$this->_configurationCountryCodePrepareConfig($config);
$this->directoryHelperMock->expects($this->once())->method('getDefaultCountry')->will($this->returnValue($default));
$this->_configurationCountryCodeAssertResult($default);
}
示例2: 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;
}
示例3: validateValue
/**
* @param string $value
* @return true|string[]
*/
public function validateValue($value)
{
$countryId = $this->getExtractedData('country_id');
$optionalZip = $this->_directoryData->getCountriesWithOptionalZip();
if (!in_array($countryId, $optionalZip)) {
return parent::validateValue($value);
}
return true;
}
示例4: getElementHtml
/**
* Add Weight Switcher radio-button element html to weight field
*
* @return string
*/
public function getElementHtml()
{
if (!$this->getForm()->getDataObject()->getTypeInstance()->hasWeight()) {
$this->weightSwitcher->setValue(WeightResolver::HAS_NO_WEIGHT);
}
if ($this->getDisabled()) {
$this->weightSwitcher->setDisabled($this->getDisabled());
}
return '<div class="admin__field-control weight-switcher">' . '<div class="admin__control-switcher" data-role="weight-switcher">' . $this->weightSwitcher->getLabelHtml() . '<div class="admin__field-control-group">' . $this->weightSwitcher->getElementHtml() . '</div>' . '</div>' . '<div class="admin__control-addon">' . parent::getElementHtml() . '<label class="admin__addon-suffix" for="' . $this->getHtmlId() . '"><span>' . $this->directoryHelper->getWeightUnit() . '</span></label>' . '</div>' . '</div>';
}
示例5: testValidateValue
/**
* @param string $value to assign to boolean
* @param bool $expected text output
* @param string $countryId
* @param bool $isOptional
*
* @dataProvider validateValueDataProvider
*/
public function testValidateValue($value, $expected, $countryId, $isOptional)
{
$storeLabel = 'Zip/Postal Code';
$this->attributeMetadataMock->expects($this->once())->method('getStoreLabel')->willReturn($storeLabel);
$this->directoryHelper->expects($this->once())->method('isZipCodeOptional')->willReturnMap([[$countryId, $isOptional]]);
$object = $this->getClass($value);
$object->setExtractedData(['country_id' => $countryId]);
$actual = $object->validateValue($value);
$this->assertEquals($expected, $actual);
}
示例6: testValidateValue
/**
* @param string $value to assign to boolean
* @param bool $expected text output
* @param string $countryId
* @param bool $isOptional
*
* @dataProvider validateValueDataProvider
*/
public function testValidateValue($value, $expected, $countryId, $isOptional)
{
$storeLabel = 'Zip/Postal Code';
$this->attributeMock->expects($this->once())->method('getStoreLabel')->willReturn($storeLabel);
$this->directoryHelperMock->expects($this->once())->method('isZipCodeOptional')->willReturnMap([[$countryId, $isOptional]]);
$object = new \Magento\Customer\Model\Attribute\Data\Postcode($this->localeMock, $this->loggerMock, $this->localeResolverMock, $this->directoryHelperMock);
$object->setAttribute($this->attributeMock);
$object->setExtractedData(['country_id' => $countryId]);
$actual = $object->validateValue($value);
$this->assertEquals($expected, $actual);
}
示例7: getConfigurationCountryCode
/**
* Get selected merchant country code in system configuration
*
* @return string
*/
public function getConfigurationCountryCode()
{
$countryCode = $this->_request->getParam(\Magento\Paypal\Model\Config\StructurePlugin::REQUEST_PARAM_COUNTRY);
if ($countryCode === null || preg_match('/^[a-zA-Z]{2}$/', $countryCode) == 0) {
$countryCode = $this->_backendConfig->getConfigDataValue(\Magento\Paypal\Block\Adminhtml\System\Config\Field\Country::FIELD_CONFIG_PATH);
}
if (empty($countryCode)) {
$countryCode = $this->directoryHelper->getDefaultCountry();
}
return $countryCode;
}
示例8: _afterLoad
/**
* Substitute empty value with Default country.
*
* @return void
*/
protected function _afterLoad()
{
$value = (string) $this->getValue();
if (empty($value)) {
if ($this->getWebsite()) {
$defaultCountry = $this->_storeManager->getWebsite($this->getWebsite())->getConfig(\Magento\Directory\Helper\Data::XML_PATH_DEFAULT_COUNTRY);
} else {
$defaultCountry = $this->directoryHelper->getDefaultCountry($this->getStore());
}
$this->setValue($defaultCountry);
}
}
示例9: getCountryInfo
/**
* {@inheritdoc}
*/
public function getCountryInfo($countryId)
{
$store = $this->storeManager->getStore();
$storeLocale = $this->scopeConfig->getValue('general/locale/code', \Magento\Store\Model\ScopeInterface::SCOPE_STORES, $store->getCode());
$countries = $this->directoryHelper->getCountryCollection($store)->addCountryIdFilter($countryId)->load();
if ($countries->count() == 0) {
throw new NoSuchEntityException(__('Requested country is not available.'));
}
$regions = $this->directoryHelper->getRegionData();
$country = $countries->getItemById($countryId);
$countryInfo = $this->setCountryInfo($country, $regions, $storeLocale);
return $countryInfo;
}
示例10: isZipCodeRequired
/**
* Determine whether zip-code is required for the country of destination
*
* @param string|null $countryId
* @return bool
*/
public function isZipCodeRequired($countryId = null)
{
if ($countryId != null) {
return !$this->_directoryData->isZipCodeOptional($countryId);
}
return true;
}
示例11: _validate
/**
* Validate Customer Addresses attribute values.
*
* @param CustomerAddressModel $customerAddressModel the model to validate
* @return InputException
*
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
private function _validate(CustomerAddressModel $customerAddressModel)
{
$exception = new InputException();
if ($customerAddressModel->getShouldIgnoreValidation()) {
return $exception;
}
if (!\Zend_Validate::is($customerAddressModel->getFirstname(), 'NotEmpty')) {
$exception->addError(__(InputException::REQUIRED_FIELD, ['fieldName' => 'firstname']));
}
if (!\Zend_Validate::is($customerAddressModel->getLastname(), 'NotEmpty')) {
$exception->addError(__(InputException::REQUIRED_FIELD, ['fieldName' => 'lastname']));
}
if (!\Zend_Validate::is($customerAddressModel->getStreetLine(1), 'NotEmpty')) {
$exception->addError(__(InputException::REQUIRED_FIELD, ['fieldName' => 'street']));
}
if (!\Zend_Validate::is($customerAddressModel->getCity(), 'NotEmpty')) {
$exception->addError(__(InputException::REQUIRED_FIELD, ['fieldName' => 'city']));
}
if (!\Zend_Validate::is($customerAddressModel->getTelephone(), 'NotEmpty')) {
$exception->addError(__(InputException::REQUIRED_FIELD, ['fieldName' => 'telephone']));
}
$havingOptionalZip = $this->directoryData->getCountriesWithOptionalZip();
if (!in_array($customerAddressModel->getCountryId(), $havingOptionalZip) && !\Zend_Validate::is($customerAddressModel->getPostcode(), 'NotEmpty')) {
$exception->addError(__(InputException::REQUIRED_FIELD, ['fieldName' => 'postcode']));
}
if (!\Zend_Validate::is($customerAddressModel->getCountryId(), 'NotEmpty')) {
$exception->addError(__(InputException::REQUIRED_FIELD, ['fieldName' => 'countryId']));
}
if ($customerAddressModel->getCountryModel()->getRegionCollection()->getSize() && !\Zend_Validate::is($customerAddressModel->getRegionId(), 'NotEmpty') && $this->directoryData->isRegionRequired($customerAddressModel->getCountryId())) {
$exception->addError(__(InputException::REQUIRED_FIELD, ['fieldName' => 'regionId']));
}
return $exception;
}
示例12: testGetDefaultCountry
public function testGetDefaultCountry()
{
$storeId = 'storeId';
$country = 'country';
$this->scopeConfigMock->expects($this->once())->method('getValue')->with(Data::XML_PATH_DEFAULT_COUNTRY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId)->will($this->returnValue($country));
$this->assertEquals($country, $this->_object->getDefaultCountry($storeId));
}
示例13: toOptionArray
/**
* Convert collection items to select options array
*
* @param string|boolean $emptyLabel
* @return array
*/
public function toOptionArray($emptyLabel = ' ')
{
$options = $this->_toOptionArray('country_id', 'name', ['title' => 'iso2_code']);
$sort = [];
foreach ($options as $data) {
$name = (string) $this->_localeLists->getCountryTranslation($data['value']);
if (!empty($name)) {
$sort[$name] = $data['value'];
}
}
$this->_arrayUtils->ksortMultibyte($sort, $this->_localeResolver->getLocale());
foreach (array_reverse($this->_foregroundCountries) as $foregroundCountry) {
$name = array_search($foregroundCountry, $sort);
unset($sort[$name]);
$sort = [$name => $foregroundCountry] + $sort;
}
$options = [];
foreach ($sort as $label => $value) {
$option = ['value' => $value, 'label' => $label];
if ($this->helperData->isRegionRequired($value)) {
$option['is_region_required'] = true;
}
$options[] = $option;
}
if (count($options) > 0 && $emptyLabel !== false) {
array_unshift($options, ['value' => '', 'label' => $emptyLabel]);
}
return $options;
}
示例14: testValidate
/**
* @param $data
* @param $expected
*
* @dataProvider validateDataProvider
*/
public function testValidate($data, $expected)
{
$this->directoryDataMock->expects($this->once())->method('getCountriesWithOptionalZip')->will($this->returnValue([]));
$this->directoryDataMock->expects($this->never())->method('isRegionRequired');
$this->model->setData($data);
$this->assertEquals($expected, $this->model->validate());
}
示例15: validate
/**
* Validate address attribute values
*
* @return bool|array
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function validate()
{
$errors = [];
if (!\Zend_Validate::is($this->getFirstname(), 'NotEmpty')) {
$errors[] = __('Please enter the first name.');
}
if (!\Zend_Validate::is($this->getLastname(), 'NotEmpty')) {
$errors[] = __('Please enter the last name.');
}
if (!\Zend_Validate::is($this->getStreetLine(1), 'NotEmpty')) {
$errors[] = __('Please enter the street.');
}
if (!\Zend_Validate::is($this->getCity(), 'NotEmpty')) {
$errors[] = __('Please enter the city.');
}
if (!\Zend_Validate::is($this->getTelephone(), 'NotEmpty')) {
$errors[] = __('Please enter the phone number.');
}
$_havingOptionalZip = $this->_directoryData->getCountriesWithOptionalZip();
if (!in_array($this->getCountryId(), $_havingOptionalZip) && !\Zend_Validate::is($this->getPostcode(), 'NotEmpty')) {
$errors[] = __('Please enter the zip/postal code.');
}
if (!\Zend_Validate::is($this->getCountryId(), 'NotEmpty')) {
$errors[] = __('Please enter the country.');
}
if ($this->getCountryModel()->getRegionCollection()->getSize() && !\Zend_Validate::is($this->getRegionId(), 'NotEmpty') && $this->_directoryData->isRegionRequired($this->getCountryId())) {
$errors[] = __('Please enter the state/province.');
}
if (empty($errors) || $this->getShouldIgnoreValidation()) {
return true;
}
return $errors;
}