directoryHelper = $directoryHelper; parent::__construct($localeDate, $logger, $localeResolver); } /** * Validate postal/zip code * Return true and skip validation if country zip code is optional * * @param array|string $value * @return array|bool */ public function validateValue($value) { $attribute = $this->getAttribute(); $countryId = $this->getExtractedData('country_id'); if ($this->directoryHelper->isZipCodeOptional($countryId)) { return true; } $errors = []; if (empty($value) && $value !== '0') { $label = __($attribute->getStoreLabel()); $errors[] = __('"%1" is a required value.', $label); } if (count($errors) == 0) { return true; } return $errors; } /** * Extract data from request and return value * * @param RequestInterface $request * @return array|string */ public function extractValue(RequestInterface $request) { $value = $this->_getRequestValue($request); return $this->_applyInputFilter($value); } /** * Export attribute value to entity model * * @param array|string $value * @return $this */ public function compactValue($value) { if ($value !== false) { $this->getEntity()->setDataUsingMethod($this->getAttribute()->getAttributeCode(), $value); } return $this; } /** * Restore attribute value from SESSION to entity model * * @param array|string $value * @return $this */ public function restoreValue($value) { return $this->compactValue($value); } /** * Return formated attribute value from entity model * * @param string $format * @return string|array * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function outputValue($format = AttributeDataFactory::OUTPUT_FORMAT_TEXT) { $value = $this->getEntity() ->getData($this->getAttribute()->getAttributeCode()); $value = $this->_applyOutputFilter($value); return $value; } }