Example #1
0
 /**
  * Method is invoked before save
  *
  * @param \Magento\Framework\DataObject $object
  * @return $this
  */
 public function beforeSave($object)
 {
     if ($object->getOrder()) {
         $object->setOrderId($object->getOrder()->getId());
         $object->setBillingAddressId($object->getOrder()->getBillingAddress()->getId());
     }
     return parent::beforeSave($object);
 }
Example #2
0
 /**
  * Perform operation after save
  *
  * @param \Magento\Framework\DataObject $object
  * @return void
  */
 public function afterSave($object)
 {
     $billingAddressId = false;
     foreach ($object->getAddressesCollection() as $address) {
         if ('billing' == $address->getAddressType()) {
             $billingAddressId = $address->getId();
         }
     }
     if ($billingAddressId) {
         $object->setBillingAddressId($billingAddressId);
         $this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getAttributeCode());
     }
 }