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