Billing.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Sales\Model\ResourceModel\Order\Attribute\Backend;
  7. /**
  8. * Order billing address backend
  9. *
  10. * @author Magento Core Team <core@magentocommerce.com>
  11. */
  12. class Billing extends \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend
  13. {
  14. /**
  15. * Perform operation before save
  16. *
  17. * @param \Magento\Framework\DataObject $object
  18. * @return void
  19. */
  20. public function beforeSave($object)
  21. {
  22. $billingAddressId = $object->getBillingAddressId();
  23. if ($billingAddressId === null) {
  24. $object->unsetBillingAddressId();
  25. }
  26. }
  27. /**
  28. * Perform operation after save
  29. *
  30. * @param \Magento\Framework\DataObject $object
  31. * @return void
  32. */
  33. public function afterSave($object)
  34. {
  35. $billingAddressId = false;
  36. foreach ($object->getAddressesCollection() as $address) {
  37. if ('billing' == $address->getAddressType()) {
  38. $billingAddressId = $address->getId();
  39. }
  40. }
  41. if ($billingAddressId) {
  42. $object->setBillingAddressId($billingAddressId);
  43. $this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getAttributeCode());
  44. }
  45. }
  46. }