本文整理汇总了PHP中Magento\Directory\Helper\Data::isZipCodeOptional方法的典型用法代码示例。如果您正苦于以下问题:PHP Data::isZipCodeOptional方法的具体用法?PHP Data::isZipCodeOptional怎么用?PHP Data::isZipCodeOptional使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Directory\Helper\Data
的用法示例。
在下文中一共展示了Data::isZipCodeOptional方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例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;
}
if ($this->helperData->isZipCodeOptional($value)) {
$option['is_zipcode_optional'] = true;
}
$options[] = $option;
}
if (count($options) > 0 && $emptyLabel !== false) {
array_unshift($options, ['value' => '', 'label' => $emptyLabel]);
}
return $options;
}
示例3: validateValue
/**
* Validate postal/zip code
* Return true and skip validation if country zip code is optional
*
* @param array|null|string $value
* @return array|bool
*/
public function validateValue($value)
{
$attribute = $this->getAttribute();
$label = __($attribute->getStoreLabel());
$countryId = $this->getExtractedData('country_id');
if ($this->directoryHelper->isZipCodeOptional($countryId)) {
return true;
}
$errors = [];
if (empty($value) && $value !== '0') {
$errors[] = __('"%1" is a required value.', $label);
}
if (count($errors) == 0) {
return true;
}
return $errors;
}
示例4: initAddressForm
/**
* @param AddressInterface $address
* @return $this
*/
public function initAddressForm(AddressInterface $address)
{
$form = $this->initForm()->getForm();
$postcode = $form->getElement('postcode');
if ($postcode) {
$postcode->removeClass('required-entry')->setRequired(!$this->_directoryHelper->isZipCodeOptional($address->getCountryId()));
}
$form->addValues($this->addressMapper->toFlatArray($address))->setHtmlIdPrefix("_item{$address->getId()}")->setFieldNameSuffix('address[' . $address->getId() . ']');
$this->addValuesToNamePrefixElement($address->getPrefix())->addValuesToNameSuffixElement($address->getSuffix());
return $this;
}
示例5: isValid
/**
* Check if postcode is valid
*
* @param string $countryId
* @param string $postcode
* @return bool
*/
public function isValid($countryId, $postcode)
{
return $this->directoryHelper->isZipCodeOptional($countryId) || !empty($postcode);
}