Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Address.php
Go to the documentation of this file.
1 <?php
7 
11 
15 class Address extends SalesResource implements OrderAddressResourceInterface
16 {
22  protected $_eventPrefix = 'sales_order_address_resource';
23 
27  protected $_validator;
28 
32  protected $gridPool;
33 
44  public function __construct(
45  \Magento\Framework\Model\ResourceModel\Db\Context $context,
46  Snapshot $entitySnapshot,
47  \Magento\Framework\Model\ResourceModel\Db\VersionControl\RelationComposite $entityRelationComposite,
49  \Magento\SalesSequence\Model\Manager $sequenceManager,
50  \Magento\Sales\Model\Order\Address\Validator $validator,
52  $connectionName = null
53  ) {
54  $this->_validator = $validator;
55  $this->gridPool = $gridPool;
56  parent::__construct(
57  $context,
58  $entitySnapshot,
59  $entityRelationComposite,
60  $attribute,
63  );
64  }
65 
71  protected function _construct()
72  {
73  $this->_init('sales_order_address', 'entity_id');
74  }
75 
81  public function getAllAttributes()
82  {
83  $attributes = [
84  'city' => __('City'),
85  'company' => __('Company'),
86  'country_id' => __('Country'),
87  'email' => __('Email'),
88  'firstname' => __('First Name'),
89  'lastname' => __('Last Name'),
90  'region_id' => __('State/Province'),
91  'street' => __('Street Address'),
92  'telephone' => __('Phone Number'),
93  'postcode' => __('Zip/Postal Code'),
94  ];
95  asort($attributes);
96  return $attributes;
97  }
98 
106  protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
107  {
108  parent::_beforeSave($object);
109  if (!$object->getParentId() && $object->getOrder()) {
110  $object->setParentId($object->getOrder()->getId());
111  }
112  // Init customer address id if customer address is assigned
113  $customerData = $object->getCustomerAddressData();
114  if ($customerData) {
115  $object->setCustomerAddressId($customerData->getId());
116  }
117  $warnings = $this->_validator->validate($object);
118  if (!empty($warnings)) {
119  throw new \Magento\Framework\Exception\LocalizedException(
120  __("We can't save the address:\n%1", implode("\n", $warnings))
121  );
122  }
123  return $this;
124  }
125 }
$customerData
__()
Definition: __.php:13
__construct(\Magento\Framework\Model\ResourceModel\Db\Context $context, Snapshot $entitySnapshot, \Magento\Framework\Model\ResourceModel\Db\VersionControl\RelationComposite $entityRelationComposite, \Magento\Sales\Model\ResourceModel\Attribute $attribute, \Magento\SalesSequence\Model\Manager $sequenceManager, \Magento\Sales\Model\Order\Address\Validator $validator, \Magento\Sales\Model\ResourceModel\GridPool $gridPool, $connectionName=null)
Definition: Address.php:44
_beforeSave(\Magento\Framework\Model\AbstractModel $object)
Definition: Address.php:106
$attributes
Definition: matrix.phtml:13