Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
Address Class Reference
Inheritance diagram for Address:
AbstractAddress AbstractExtensibleModel AddressModelInterface AbstractModel CustomAttributesDataInterface DataObject ExtensibleDataInterface

Public Member Functions

 __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, \Magento\Customer\Model\Address\Config $addressConfig, \Magento\Directory\Model\RegionFactory $regionFactory, \Magento\Directory\Model\CountryFactory $countryFactory, AddressMetadataInterface $metadataService, AddressInterfaceFactory $addressDataFactory, RegionInterfaceFactory $regionDataFactory, \Magento\Framework\Api\DataObjectHelper $dataObjectHelper, CustomerFactory $customerFactory, \Magento\Framework\Reflection\DataObjectProcessor $dataProcessor, \Magento\Framework\Indexer\IndexerRegistry $indexerRegistry, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
 
 updateData (AddressInterface $address)
 
 getDataModel ($defaultBillingAddressId=null, $defaultShippingAddressId=null)
 
 getCustomerId ()
 
 setCustomerId ($id)
 
 getCustomer ()
 
 setCustomer (Customer $customer)
 
 getAttributes ()
 
 getDefaultAttributeCodes ()
 
 __clone ()
 
 getEntityType ()
 
 getRegionId ()
 
 setRegionId ($regionId)
 
 getEntityTypeId ()
 
 afterSave ()
 
 afterDeleteCommit ()
 
 getAttributeSetId ()
 
- Public Member Functions inherited from AbstractAddress
 __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)
 
 getName ()
 
 getStreet ()
 
 getStreetLine ($number)
 
 getStreetFull ()
 
 setStreetFull ($street)
 
 setStreet ($street)
 
 setData ($key, $value=null)
 
 explodeStreetAddress ()
 
 getRegion ()
 
 getRegionCode ()
 
 getRegionId ()
 
 getCountry ()
 
 getCountryModel ()
 
 getRegionModel ($regionId=null)
 
 format ($type)
 
 getConfig ()
 
 beforeSave ()
 
 validate ()
 
 unsRegion ()
 
- Public Member Functions inherited from AbstractExtensibleModel
 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, ExtensionAttributesFactory $extensionFactory, AttributeValueFactory $customAttributeFactory, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
 
 getCustomAttributes ()
 
 getCustomAttribute ($attributeCode)
 
 setCustomAttributes (array $attributes)
 
 setCustomAttribute ($attributeCode, $attributeValue)
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 getData ($key='', $index=null)
 
 setId ($value)
 
 __sleep ()
 
 __wakeup ()
 
- Public Member Functions inherited from AbstractModel
 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
 
 __sleep ()
 
 __wakeup ()
 
 setIdFieldName ($name)
 
 getIdFieldName ()
 
 getId ()
 
 setId ($value)
 
 isDeleted ($isDeleted=null)
 
 hasDataChanges ()
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 setDataChanges ($value)
 
 getOrigData ($key=null)
 
 setOrigData ($key=null, $data=null)
 
 dataHasChangedFor ($field)
 
 getResourceName ()
 
 getResourceCollection ()
 
 getCollection ()
 
 load ($modelId, $field=null)
 
 beforeLoad ($identifier, $field=null)
 
 afterLoad ()
 
 isSaveAllowed ()
 
 setHasDataChanges ($flag)
 
 save ()
 
 afterCommitCallback ()
 
 isObjectNew ($flag=null)
 
 beforeSave ()
 
 validateBeforeSave ()
 
 getCacheTags ()
 
 cleanModelCache ()
 
 afterSave ()
 
 delete ()
 
 beforeDelete ()
 
 afterDelete ()
 
 afterDeleteCommit ()
 
 getResource ()
 
 getEntityId ()
 
 setEntityId ($entityId)
 
 clearInstance ()
 
 getStoredData ()
 
 getEventPrefix ()
 
- Public Member Functions inherited from DataObject
 __construct (array $data=[])
 
 addData (array $arr)
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 getData ($key='', $index=null)
 
 getDataByPath ($path)
 
 getDataByKey ($key)
 
 setDataUsingMethod ($key, $args=[])
 
 getDataUsingMethod ($key, $args=null)
 
 hasData ($key='')
 
 toArray (array $keys=[])
 
 convertToArray (array $keys=[])
 
 toXml (array $keys=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 convertToXml (array $arrAttributes=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 toJson (array $keys=[])
 
 convertToJson (array $keys=[])
 
 toString ($format='')
 
 __call ($method, $args)
 
 isEmpty ()
 
 serialize ($keys=[], $valueSeparator='=', $fieldSeparator=' ', $quote='"')
 
 debug ($data=null, &$objects=[])
 
 offsetSet ($offset, $value)
 
 offsetExists ($offset)
 
 offsetUnset ($offset)
 
 offsetGet ($offset)
 

Protected Member Functions

 _construct ()
 
 _createCustomer ()
 
 getCustomAttributesCodes ()
 
- Protected Member Functions inherited from AbstractAddress
 isAddressMultilineAttribute ($code)
 
 _implodeArrayField (array $data)
 
 _implodeArrayValues ($value)
 
 _createRegionInstance ()
 
 _createCountryInstance ()
 
 isCompanyRequired ()
 
 isTelephoneRequired ()
 
 isFaxRequired ()
 
- Protected Member Functions inherited from AbstractExtensibleModel
 filterCustomAttributes ($data)
 
 initializeCustomAttributes ()
 
 convertCustomAttributeValues (array &$customAttributes)
 
 getCustomAttributesCodes ()
 
 _setExtensionAttributes (\Magento\Framework\Api\ExtensionAttributesInterface $extensionAttributes)
 
 _getExtensionAttributes ()
 
- Protected Member Functions inherited from AbstractModel
 _construct ()
 
 _init ($resourceModel)
 
 _setResourceModel ($resourceName, $collectionName=null)
 
 _getResource ()
 
 _getEventData ()
 
 _beforeLoad ($modelId, $field=null)
 
 _afterLoad ()
 
 _hasModelChanged ()
 
 _getValidatorBeforeSave ()
 
 _createValidatorBeforeSave ()
 
 _getValidationRulesBeforeSave ()
 
 _clearReferences ()
 
 _clearData ()
 
- Protected Member Functions inherited from DataObject
 _getData ($key)
 
 _underscore ($name)
 

Protected Attributes

 $_customer
 
 $_customerFactory
 
 $dataProcessor
 
 $dataObjectHelper
 
 $indexerRegistry
 
- Protected Attributes inherited from AbstractAddress
 $_eventPrefix = 'customer_address'
 
 $_eventObject = 'customer_address'
 
 $_directoryData = null
 
 $_eavConfig
 
 $_addressConfig
 
 $_regionFactory
 
 $_countryFactory
 
 $metadataService
 
 $addressDataFactory
 
 $regionDataFactory
 
 $dataObjectHelper
 
- Protected Attributes inherited from AbstractExtensibleModel
 $extensionAttributesFactory
 
 $extensionAttributes
 
 $customAttributeFactory
 
 $customAttributesCodes = null
 
 $customAttributesChanged = false
 
- Protected Attributes inherited from AbstractModel
 $_eventPrefix = 'core_abstract'
 
 $_eventObject = 'object'
 
 $_idFieldName = 'id'
 
 $_hasDataChanges = false
 
 $_origData
 
 $_isDeleted = false
 
 $_resource
 
 $_resourceCollection
 
 $_resourceName
 
 $_collectionName
 
 $_cacheTag = false
 
 $_dataSaveAllowed = true
 
 $_isObjectNew = null
 
 $_validatorBeforeSave = null
 
 $_eventManager
 
 $_cacheManager
 
 $_registry
 
 $_logger
 
 $_appState
 
 $_actionValidator
 
 $storedData = []
 
- Protected Attributes inherited from DataObject
 $_data = []
 

Additional Inherited Members

- Data Fields inherited from AbstractAddress
const TYPE_BILLING = 'billing'
 
const TYPE_SHIPPING = 'shipping'
 
- Data Fields inherited from CustomAttributesDataInterface
const CUSTOM_ATTRIBUTES = 'custom_attributes'
 
- Data Fields inherited from ExtensibleDataInterface
const EXTENSION_ATTRIBUTES_KEY = 'extension_attributes'
 
- Static Protected Attributes inherited from AbstractAddress
static $_countryModels = []
 
static $_regionModels = []
 
- Static Protected Attributes inherited from DataObject
static $_underscoreCache = []
 

Detailed Description

Customer address model

@api @method int getParentId() getParentId() @method \Magento\Customer\Model\Address setParentId() setParentId(int $parentId) @SuppressWarnings(PHPMD.CouplingBetweenObjects)

Since
100.0.2

Definition at line 23 of file Address.php.

Constructor & Destructor Documentation

◆ __construct()

__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,
\Magento\Customer\Model\Address\Config  $addressConfig,
\Magento\Directory\Model\RegionFactory  $regionFactory,
\Magento\Directory\Model\CountryFactory  $countryFactory,
AddressMetadataInterface  $metadataService,
AddressInterfaceFactory  $addressDataFactory,
RegionInterfaceFactory  $regionDataFactory,
\Magento\Framework\Api\DataObjectHelper  $dataObjectHelper,
CustomerFactory  $customerFactory,
\Magento\Framework\Reflection\DataObjectProcessor  $dataProcessor,
\Magento\Framework\Indexer\IndexerRegistry  $indexerRegistry,
\Magento\Framework\Model\ResourceModel\AbstractResource  $resource = null,
\Magento\Framework\Data\Collection\AbstractDb  $resourceCollection = null,
array  $data = [] 
)
Parameters
\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
Address\Config$addressConfig
\Magento\Directory\Model\RegionFactory$regionFactory
\Magento\Directory\Model\CountryFactory$countryFactory
AddressMetadataInterface$metadataService
AddressInterfaceFactory$addressDataFactory
RegionInterfaceFactory$regionDataFactory
\Magento\Framework\Api\DataObjectHelper$dataObjectHelper
CustomerFactory$customerFactory
\Magento\Framework\Reflection\DataObjectProcessor$dataProcessor
\Magento\Framework\Indexer\IndexerRegistry$indexerRegistry
\Magento\Framework\Model\ResourceModel\AbstractResource | null$resource
\Magento\Framework\Data\Collection\AbstractDb | null$resourceCollection
array$data@SuppressWarnings(PHPMD.ExcessiveParameterList)

Definition at line 80 of file Address.php.

100  {
101  $this->dataProcessor = $dataProcessor;
102  $this->_customerFactory = $customerFactory;
103  $this->indexerRegistry = $indexerRegistry;
104  parent::__construct(
105  $context,
106  $registry,
107  $extensionFactory,
109  $directoryData,
110  $eavConfig,
111  $addressConfig,
112  $regionFactory,
113  $countryFactory,
118  $resource,
119  $resourceCollection,
120  $data
121  );
122  }
$resource
Definition: bulk.php:12

Member Function Documentation

◆ __clone()

__clone ( )
Returns
void

Definition at line 266 of file Address.php.

267  {
268  $this->setId(null);
269  }

◆ _construct()

_construct ( )
protected
Returns
void

Definition at line 127 of file Address.php.

128  {
129  $this->_init(\Magento\Customer\Model\ResourceModel\Address::class);
130  }

◆ _createCustomer()

_createCustomer ( )
protected
Returns
Customer

Definition at line 306 of file Address.php.

307  {
308  return $this->_customerFactory->create();
309  }

◆ afterDeleteCommit()

afterDeleteCommit ( )

Init indexing process after customer delete

Returns
\Magento\Framework\Model\AbstractModel

Definition at line 340 of file Address.php.

341  {
342  $this->reindex();
343  return parent::afterDeleteCommit();
344  }

◆ afterSave()

afterSave ( )

Processing object after save data

Returns
$this

Definition at line 326 of file Address.php.

327  {
328  $indexer = $this->indexerRegistry->get(Customer::CUSTOMER_GRID_INDEXER_ID);
329  if ($indexer->getState()->getStatus() == StateInterface::STATUS_VALID) {
330  $this->_getResource()->addCommitCallback([$this, 'reindex']);
331  }
332  return parent::afterSave();
333  }

◆ getAttributes()

getAttributes ( )

Retrieve address entity attributes

Returns
Attribute[]

Definition at line 243 of file Address.php.

244  {
245  $attributes = $this->getData('attributes');
246  if ($attributes === null) {
247  $attributes = $this->_getResource()->loadAllAttributes($this)->getSortedAttributes();
248  $this->setData('attributes', $attributes);
249  }
250  return $attributes;
251  }
$attributes
Definition: matrix.phtml:13

◆ getAttributeSetId()

getAttributeSetId ( )

Retrieve attribute set id for customer address.

Returns
int
Since
101.0.0

Definition at line 388 of file Address.php.

389  {
390  return parent::getAttributeSetId() ?: AddressMetadataInterface::ATTRIBUTE_SET_ID_ADDRESS;
391  }

◆ getCustomAttributesCodes()

getCustomAttributesCodes ( )
protected

{}

Since
100.0.6

Definition at line 362 of file Address.php.

363  {
364  return array_keys($this->getAttributeList()->getAttributes());
365  }

◆ getCustomer()

getCustomer ( )

Retrieve address customer

Returns
Customer|false

Definition at line 214 of file Address.php.

215  {
216  if (!$this->getCustomerId()) {
217  return false;
218  }
219  if (empty($this->_customer)) {
220  $this->_customer = $this->_createCustomer()->load($this->getCustomerId());
221  }
222  return $this->_customer;
223  }

◆ getCustomerId()

getCustomerId ( )

Retrieve address customer identifier

Returns
int

Definition at line 191 of file Address.php.

192  {
193  return $this->_getData('customer_id') ? $this->_getData('customer_id') : $this->getParentId();
194  }

◆ getDataModel()

getDataModel (   $defaultBillingAddressId = null,
  $defaultShippingAddressId = null 
)

{}

Definition at line 173 of file Address.php.

174  {
175  if ($this->getCustomerId() || $this->getParentId()) {
176  if ($this->getCustomer()->getDefaultBillingAddress()) {
177  $defaultBillingAddressId = $this->getCustomer()->getDefaultBillingAddress()->getId();
178  }
179  if ($this->getCustomer()->getDefaultShippingAddress()) {
180  $defaultShippingAddressId = $this->getCustomer()->getDefaultShippingAddress()->getId();
181  }
182  }
183  return parent::getDataModel($defaultBillingAddressId, $defaultShippingAddressId);
184  }

◆ getDefaultAttributeCodes()

getDefaultAttributeCodes ( )

Get attributes created by default

Returns
string[]

Definition at line 258 of file Address.php.

259  {
260  return $this->_getResource()->getDefaultAttributes();
261  }

◆ getEntityType()

getEntityType ( )

Return Entity Type instance

Returns
\Magento\Eav\Model\Entity\Type

Definition at line 276 of file Address.php.

277  {
278  return $this->_getResource()->getEntityType();
279  }

◆ getEntityTypeId()

getEntityTypeId ( )

Return Entity Type ID

Returns
int

Definition at line 316 of file Address.php.

317  {
318  return $this->getEntityType()->getId();
319  }

◆ getRegionId()

getRegionId ( )

Return Region ID

Returns
int

Definition at line 286 of file Address.php.

287  {
288  return (int)$this->getData('region_id');
289  }

◆ setCustomer()

setCustomer ( Customer  $customer)

Specify address customer

Parameters
Customer$customer
Returns
$this

Definition at line 231 of file Address.php.

232  {
233  $this->_customer = $customer;
234  $this->setCustomerId($customer->getId());
235  return $this;
236  }
$customer
Definition: customers.php:11

◆ setCustomerId()

setCustomerId (   $id)

Declare address customer identifier

Parameters
int$id
Returns
$this

Definition at line 202 of file Address.php.

203  {
204  $this->setParentId($id);
205  $this->setData('customer_id', $id);
206  return $this;
207  }
$id
Definition: fieldset.phtml:14

◆ setRegionId()

setRegionId (   $regionId)

Set Region ID. $regionId is automatically converted to integer

Parameters
int$regionId
Returns
$this

Definition at line 297 of file Address.php.

298  {
299  $this->setData('region_id', (int)$regionId);
300  return $this;
301  }

◆ updateData()

updateData ( AddressInterface  $address)

Update Model with the data from Data Interface

Parameters
AddressInterface$address
Returns
$this Use Api/RepositoryInterface for the operations in the Data Interfaces. Don't rely on Address Model

Definition at line 139 of file Address.php.

140  {
141  // Set all attributes
142  $attributes = $this->dataProcessor
143  ->buildOutputDataArray($address, \Magento\Customer\Api\Data\AddressInterface::class);
144 
145  foreach ($attributes as $attributeCode => $attributeData) {
147  $this->setRegion($address->getRegion()->getRegion());
148  $this->setRegionCode($address->getRegion()->getRegionCode());
149  $this->setRegionId($address->getRegion()->getRegionId());
150  } else {
152  }
153  }
154  // Need to explicitly set this due to discrepancy in the keys between model and data object
155  $this->setIsDefaultBilling($address->isDefaultBilling());
156  $this->setIsDefaultShipping($address->isDefaultShipping());
157  if (!$this->getAttributeSetId()) {
158  $this->setAttributeSetId(AddressMetadataInterface::ATTRIBUTE_SET_ID_ADDRESS);
159  }
160  $customAttributes = $address->getCustomAttributes();
161  if ($customAttributes !== null) {
162  foreach ($customAttributes as $attribute) {
163  $this->setData($attribute->getAttributeCode(), $attribute->getValue());
164  }
165  }
166 
167  return $this;
168  }
$address
Definition: customer.php:38
$attributeCode
Definition: extend.phtml:12
$attributes
Definition: matrix.phtml:13
setDataUsingMethod($key, $args=[])
Definition: DataObject.php:204

Field Documentation

◆ $_customer

$_customer
protected

Definition at line 30 of file Address.php.

◆ $_customerFactory

$_customerFactory
protected

Definition at line 35 of file Address.php.

◆ $dataObjectHelper

$dataObjectHelper
protected

Definition at line 45 of file Address.php.

◆ $dataProcessor

$dataProcessor
protected

Definition at line 40 of file Address.php.

◆ $indexerRegistry

$indexerRegistry
protected

Definition at line 50 of file Address.php.


The documentation for this class was generated from the following file: