![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/cartforge.co/vendor/magento/module-sales/Model/ResourceModel/Order/Handler/ |
<?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ namespace Magento\Sales\Model\ResourceModel\Order\Handler; use Magento\Sales\Model\Order; use Magento\Sales\Model\ResourceModel\Attribute; class Address { /** * @var Attribute */ protected $attribute; /** * @param Attribute $attribute */ public function __construct( Attribute $attribute ) { $this->attribute = $attribute; } /** * Remove empty addresses from order * * @param Order $order * @return $this */ public function removeEmptyAddresses(Order $order) { if ($order->hasBillingAddressId() && $order->getBillingAddressId() === null) { $order->unsBillingAddressId(); } if ($order->hasShippingAddressId() && $order->getShippingAddressId() === null) { $order->unsShippingAddressId(); } return $this; } /** * Process addresses saving * * @param Order $order * @return $this * @throws \Exception */ public function process(Order $order) { if (null !== $order->getAddresses()) { /** @var \Magento\Sales\Model\Order\Address $address */ foreach ($order->getAddresses() as $address) { $address->setParentId($order->getId()); $address->setOrder($order); $address->save(); } $billingAddress = $order->getBillingAddress(); $attributesForSave = []; if ($billingAddress && $order->getBillingAddressId() != $billingAddress->getId()) { $order->setBillingAddressId($billingAddress->getId()); $attributesForSave[] = 'billing_address_id'; } $shippingAddress = $order->getShippingAddress(); if ($shippingAddress && $order->getShippingAddressId() != $shippingAddress->getId()) { $order->setShippingAddressId($shippingAddress->getId()); $attributesForSave[] = 'shipping_address_id'; } if (!empty($attributesForSave)) { $this->attribute->saveAttribute($order, $attributesForSave); } } return $this; } }