|
10 | 10 |
|
11 | 11 | use Magento\Customer\Api\AddressMetadataInterface;
|
12 | 12 | use Magento\Customer\Model\Metadata\Form as CustomerForm;
|
| 13 | +use Magento\Framework\Api\ExtensibleDataObjectConverter; |
13 | 14 | use Magento\Framework\App\ObjectManager;
|
14 | 15 | use Magento\Quote\Model\Quote\Address;
|
15 | 16 | use Magento\Quote\Model\Quote\Item;
|
| 17 | +use Magento\Sales\Api\Data\OrderAddressInterface; |
| 18 | +use Magento\Sales\Model\Order; |
16 | 19 |
|
17 | 20 | /**
|
18 | 21 | * Order create model
|
@@ -235,6 +238,11 @@ class Create extends \Magento\Framework\DataObject implements \Magento\Checkout\
|
235 | 238 | */
|
236 | 239 | private $serializer;
|
237 | 240 |
|
| 241 | + /** |
| 242 | + * @var ExtensibleDataObjectConverter |
| 243 | + */ |
| 244 | + private $dataObjectConverter; |
| 245 | + |
238 | 246 | /**
|
239 | 247 | * @param \Magento\Framework\ObjectManagerInterface $objectManager
|
240 | 248 | * @param \Magento\Framework\Event\ManagerInterface $eventManager
|
@@ -265,6 +273,7 @@ class Create extends \Magento\Framework\DataObject implements \Magento\Checkout\
|
265 | 273 | * @param \Magento\Quote\Model\QuoteFactory $quoteFactory
|
266 | 274 | * @param array $data
|
267 | 275 | * @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
|
| 276 | + * @param ExtensibleDataObjectConverter|null $dataObjectConverter |
268 | 277 | * @SuppressWarnings(PHPMD.ExcessiveParameterList)
|
269 | 278 | */
|
270 | 279 | public function __construct(
|
@@ -296,7 +305,8 @@ public function __construct(
|
296 | 305 | \Magento\Sales\Api\OrderManagementInterface $orderManagement,
|
297 | 306 | \Magento\Quote\Model\QuoteFactory $quoteFactory,
|
298 | 307 | array $data = [],
|
299 |
| - \Magento\Framework\Serialize\Serializer\Json $serializer = null |
| 308 | + \Magento\Framework\Serialize\Serializer\Json $serializer = null, |
| 309 | + ExtensibleDataObjectConverter $dataObjectConverter = null |
300 | 310 | ) {
|
301 | 311 | $this->_objectManager = $objectManager;
|
302 | 312 | $this->_eventManager = $eventManager;
|
@@ -328,6 +338,8 @@ public function __construct(
|
328 | 338 | $this->serializer = $serializer ?: ObjectManager::getInstance()
|
329 | 339 | ->get(\Magento\Framework\Serialize\Serializer\Json::class);
|
330 | 340 | parent::__construct($data);
|
| 341 | + $this->dataObjectConverter = $dataObjectConverter ?: ObjectManager::getInstance() |
| 342 | + ->get(ExtensibleDataObjectConverter::class); |
331 | 343 | }
|
332 | 344 |
|
333 | 345 | /**
|
@@ -514,9 +526,7 @@ public function initFromOrder(\Magento\Sales\Model\Order $order)
|
514 | 526 |
|
515 | 527 | $shippingAddress = $order->getShippingAddress();
|
516 | 528 | if ($shippingAddress) {
|
517 |
| - $addressDiff = array_diff_assoc($shippingAddress->getData(), $order->getBillingAddress()->getData()); |
518 |
| - unset($addressDiff['address_type'], $addressDiff['entity_id']); |
519 |
| - $shippingAddress->setSameAsBilling(empty($addressDiff)); |
| 529 | + $shippingAddress->setSameAsBilling($this->isAddressesAreEqual($order)); |
520 | 530 | }
|
521 | 531 |
|
522 | 532 | $this->_initBillingAddressFromOrder($order);
|
@@ -2010,4 +2020,26 @@ protected function _getNewCustomerEmail()
|
2010 | 2020 |
|
2011 | 2021 | return $email;
|
2012 | 2022 | }
|
| 2023 | + |
| 2024 | + /** |
| 2025 | + * Checks id shipping and billing addresses are equal. |
| 2026 | + * |
| 2027 | + * @param Order $order |
| 2028 | + * @return bool |
| 2029 | + */ |
| 2030 | + private function isAddressesAreEqual(Order $order) |
| 2031 | + { |
| 2032 | + $shippingAddress = $order->getShippingAddress(); |
| 2033 | + $billingAddress = $order->getBillingAddress(); |
| 2034 | + $shippingData = $this->dataObjectConverter->toFlatArray($shippingAddress, [], OrderAddressInterface::class); |
| 2035 | + $billingData = $this->dataObjectConverter->toFlatArray($billingAddress, [], OrderAddressInterface::class); |
| 2036 | + unset( |
| 2037 | + $shippingData['address_type'], |
| 2038 | + $shippingData['entity_id'], |
| 2039 | + $billingData['address_type'], |
| 2040 | + $billingData['entity_id'] |
| 2041 | + ); |
| 2042 | + |
| 2043 | + return $shippingData == $billingData; |
| 2044 | + } |
2013 | 2045 | }
|
0 commit comments