11 use Magento\Customer\Api\Data\AddressInterfaceFactory;
13 use Magento\Customer\Api\Data\RegionInterfaceFactory;
123 private $compositeValidator;
149 \
Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory,
151 \
Magento\Directory\Helper\Data $directoryData,
154 \
Magento\Directory\Model\RegionFactory $regionFactory,
155 \
Magento\Directory\Model\CountryFactory $countryFactory,
161 \
Magento\Framework\Data\Collection\AbstractDb $resourceCollection =
null,
165 $this->_directoryData = $directoryData;
168 $this->_addressConfig = $addressConfig;
169 $this->_regionFactory = $regionFactory;
170 $this->_countryFactory = $countryFactory;
176 ->get(CompositeValidator::class);
196 if ($this->_eavConfig->getAttribute(
'customer_address',
'prefix')->getIsVisible() && $this->getPrefix()) {
197 $name .= $this->getPrefix() .
' ';
199 $name .= $this->getFirstname();
200 $middleName = $this->_eavConfig->getAttribute(
'customer_address',
'middlename');
201 if ($middleName->getIsVisible() && $this->getMiddlename()) {
202 $name .=
' ' . $this->getMiddlename();
204 $name .=
' ' . $this->getLastname();
205 if ($this->_eavConfig->getAttribute(
'customer_address',
'suffix')->getIsVisible() && $this->getSuffix()) {
206 $name .=
' ' . $this->getSuffix();
243 $street = $this->
getData(
'street');
244 return is_array($street) ? implode(
"\n", $street) : $street;
266 $this->
setData(
'street', $street);
279 if (is_array($key)) {
284 return parent::setData($key,
$value);
327 foreach (
$value as $val) {
328 if (is_scalar($val)) {
349 foreach ($streetLines as
$i => $line) {
350 $this->
setData(
'street' . (
$i + 1), $line);
362 $regionId = $this->
getData(
'region_id');
363 $region = $this->
getData(
'region');
365 if (!$regionId && is_numeric($region)) {
366 if ($this->
getRegionModel($region)->getCountryId() == $this->getCountryId()) {
368 $this->
setData(
'region_id', $region);
371 if ($this->
getRegionModel($regionId)->getCountryId() == $this->getCountryId()) {
374 }
elseif (is_string($region)) {
375 $this->
setData(
'region', $region);
378 return $this->
getData(
'region');
388 $regionId = $this->
getData(
'region_id');
389 $region = $this->
getData(
'region');
391 if (!$regionId && is_numeric($region)) {
392 if ($this->
getRegionModel($region)->getCountryId() == $this->getCountryId()) {
396 if ($this->
getRegionModel($regionId)->getCountryId() == $this->getCountryId()) {
399 }
elseif (is_string($region)) {
400 $this->
setData(
'region_code', $region);
402 return $this->
getData(
'region_code');
410 $regionId = $this->
getData(
'region_id');
411 $region = $this->
getData(
'region');
413 if (is_numeric($region)) {
414 $this->
setData(
'region_id', $region);
419 $this->getCountryId()
421 $this->
setData(
'region_id', $regionModel->getId());
424 return $this->
getData(
'region_id');
432 $country = $this->getCountryId();
433 return $country ? $country : $this->
getData(
'country');
443 if (!isset(self::$_countryModels[$this->getCountryId()])) {
445 $country->load($this->getCountryId());
446 self::$_countryModels[$this->getCountryId()] = $country;
449 return self::$_countryModels[$this->getCountryId()];
460 if ($regionId ===
null) {
464 if (!isset(self::$_regionModels[$regionId])) {
466 $region->load($regionId);
467 self::$_regionModels[$regionId] = $region;
470 return self::$_regionModels[$regionId];
487 if (!($formatType = $this->
getConfig()->getFormatByCode(
$type)) || !$formatType->getRenderer()) {
490 $this->_eventManager->dispatch(
'customer_address_format', [
'type' => $formatType,
'address' => $this]);
491 return $formatType->getRenderer()->render($this);
509 parent::beforeSave();
524 public function getDataModel($defaultBillingAddressId =
null, $defaultShippingAddressId =
null)
526 $addressId = $this->
getId();
528 $attributes = $this->metadataService->getAllAttributesMetadata();
542 $region = $this->regionDataFactory->create();
549 $addressDataObject = $this->addressDataFactory->create();
550 $this->dataObjectHelper->populateWithArray(
553 \
Magento\Customer\Api\Data\AddressInterface::class
556 $addressDataObject->setId($addressId);
562 if ($defaultBillingAddressId == $addressId) {
563 $addressDataObject->setIsDefaultBilling(
true);
565 if ($defaultShippingAddressId == $addressId) {
566 $addressDataObject->setIsDefaultShipping(
true);
570 return $addressDataObject;
580 if ($this->getShouldIgnoreValidation()) {
584 $errors = $this->compositeValidator->validate($this);
598 return $this->_regionFactory->create();
606 return $this->_countryFactory->create();
625 return ($this->_eavConfig->getAttribute(
'customer_address',
'company')->getIsRequired());
634 return ($this->_eavConfig->getAttribute(
'customer_address',
'telephone')->getIsRequired());
643 return ($this->_eavConfig->getAttribute(
'customer_address',
'fax')->getIsRequired());
getCustomAttributesCodes()
elseif(isset( $params[ 'redirect_parent']))
getDataUsingMethod($key, $args=null)
__construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory, \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory, \Magento\Directory\Helper\Data $directoryData, \Magento\Eav\Model\Config $eavConfig, Config $addressConfig, \Magento\Directory\Model\RegionFactory $regionFactory, \Magento\Directory\Model\CountryFactory $countryFactory, AddressMetadataInterface $metadataService, AddressInterfaceFactory $addressDataFactory, RegionInterfaceFactory $regionDataFactory, \Magento\Framework\Api\DataObjectHelper $dataObjectHelper, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[], CompositeValidator $compositeValidator=null)
getRegionModel($regionId=null)
_implodeArrayValues($value)
_implodeArrayField(array $data)
isAddressMultilineAttribute($code)
getDataModel($defaultBillingAddressId=null, $defaultShippingAddressId=null)
getData($key='', $index=null)
setData($key, $value=null)
if(!isset($_GET['name'])) $name