Shipping.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 shipping address backend
  9. *
  10. * @author Magento Core Team <core@magentocommerce.com>
  11. */
  12. class Shipping 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. $shippingAddressId = $object->getShippingAddressId();
  23. if ($shippingAddressId === null) {
  24. $object->unsetShippingAddressId();
  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. $shippingAddressId = false;
  36. foreach ($object->getAddressesCollection() as $address) {
  37. if ('shipping' == $address->getAddressType()) {
  38. $shippingAddressId = $address->getId();
  39. }
  40. }
  41. if ($shippingAddressId) {
  42. $object->setShippingAddressId($shippingAddressId);
  43. $this->getAttribute()->getEntity()
  44. ->saveAttribute($object, $this->getAttribute()->getAttributeCode());
  45. }
  46. }
  47. }