Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Billing.php
Go to the documentation of this file.
1 <?php
7 
13 class Billing extends \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend
14 {
19  public function beforeSave($object)
20  {
21  $defaultBilling = $object->getDefaultBilling();
22  if ($defaultBilling === null) {
23  $object->unsetDefaultBilling();
24  }
25  }
26 
31  public function afterSave($object)
32  {
33  if ($defaultBilling = $object->getDefaultBilling()) {
34  $addressId = false;
39  foreach ($object->getAddresses() as $address) {
40  if ($address->getPostIndex() == $defaultBilling) {
41  $addressId = $address->getId();
42  }
43  }
44  if ($addressId) {
45  $object->setDefaultBilling($addressId);
46  $this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getAttributeCode());
47  }
48  }
49  }
50 }
$address
Definition: customer.php:38