本文整理汇总了PHP中Magento\Directory\Helper\Data::isRegionRequired方法的典型用法代码示例。如果您正苦于以下问题:PHP Data::isRegionRequired方法的具体用法?PHP Data::isRegionRequired怎么用?PHP Data::isRegionRequired使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Directory\Helper\Data
的用法示例。
在下文中一共展示了Data::isRegionRequired方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: _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;
}
示例4: updateRegionData
/**
* Update region data
*
* @param array $attributeValues
* @return void
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
protected function updateRegionData(&$attributeValues)
{
if ($this->helperData->isRegionRequired($attributeValues['country_id'])) {
$newRegion = $this->regionFactory->create()->load($attributeValues['region_id']);
$attributeValues['region_code'] = $newRegion->getCode();
$attributeValues['region'] = $newRegion->getDefaultName();
} else {
$attributeValues['region_id'] = null;
}
$regionData = [RegionInterface::REGION_ID => !empty($attributeValues['region_id']) ? $attributeValues['region_id'] : null, RegionInterface::REGION => !empty($attributeValues['region']) ? $attributeValues['region'] : null, RegionInterface::REGION_CODE => !empty($attributeValues['region_code']) ? $attributeValues['region_code'] : null];
$region = $this->regionDataFactory->create();
$this->dataObjectHelper->populateWithArray($region, $regionData, '\\Magento\\Customer\\Api\\Data\\RegionInterface');
$attributeValues['region'] = $region;
}
示例5: isStateRequired
/**
* Checks if state for current country id is required
*
* @param string $countryId
* @return bool
*/
protected function isStateRequired($countryId)
{
$country = $this->countryFactory->create()->load($countryId);
return $this->directoryHelper->isRegionRequired($countryId) && $country->getRegionCollection()->getSize();
}