|
8 | 8 |
|
9 | 9 | use Magento\Customer\Api\AddressMetadataInterface;
|
10 | 10 | use Magento\Customer\Model\Metadata\Form as CustomerForm;
|
| 11 | +use Magento\Framework\Api\ExtensibleDataObjectConverter; |
| 12 | +use Magento\Framework\App\ObjectManager; |
| 13 | +use Magento\Quote\Model\Quote\Address; |
11 | 14 | use Magento\Quote\Model\Quote\Item;
|
| 15 | +use Magento\Sales\Api\Data\OrderAddressInterface; |
| 16 | +use Magento\Sales\Model\Order; |
12 | 17 |
|
13 | 18 | /**
|
14 | 19 | * Order create model
|
@@ -231,6 +236,11 @@ class Create extends \Magento\Framework\DataObject implements \Magento\Checkout\
|
231 | 236 | */
|
232 | 237 | private $serializer;
|
233 | 238 |
|
| 239 | + /** |
| 240 | + * @var ExtensibleDataObjectConverter |
| 241 | + */ |
| 242 | + private $dataObjectConverter; |
| 243 | + |
234 | 244 | /**
|
235 | 245 | * @param \Magento\Framework\ObjectManagerInterface $objectManager
|
236 | 246 | * @param \Magento\Framework\Event\ManagerInterface $eventManager
|
@@ -261,6 +271,7 @@ class Create extends \Magento\Framework\DataObject implements \Magento\Checkout\
|
261 | 271 | * @param \Magento\Quote\Model\QuoteFactory $quoteFactory
|
262 | 272 | * @param array $data
|
263 | 273 | * @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
|
| 274 | + * @param ExtensibleDataObjectConverter|null $dataObjectConverter |
264 | 275 | * @SuppressWarnings(PHPMD.ExcessiveParameterList)
|
265 | 276 | */
|
266 | 277 | public function __construct(
|
@@ -292,7 +303,8 @@ public function __construct(
|
292 | 303 | \Magento\Sales\Api\OrderManagementInterface $orderManagement,
|
293 | 304 | \Magento\Quote\Model\QuoteFactory $quoteFactory,
|
294 | 305 | array $data = [],
|
295 |
| - \Magento\Framework\Serialize\Serializer\Json $serializer = null |
| 306 | + \Magento\Framework\Serialize\Serializer\Json $serializer = null, |
| 307 | + ExtensibleDataObjectConverter $dataObjectConverter = null |
296 | 308 | ) {
|
297 | 309 | $this->_objectManager = $objectManager;
|
298 | 310 | $this->_eventManager = $eventManager;
|
@@ -324,6 +336,8 @@ public function __construct(
|
324 | 336 | $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
|
325 | 337 | ->get(\Magento\Framework\Serialize\Serializer\Json::class);
|
326 | 338 | parent::__construct($data);
|
| 339 | + $this->dataObjectConverter = $dataObjectConverter ?: ObjectManager::getInstance() |
| 340 | + ->get(ExtensibleDataObjectConverter::class); |
327 | 341 | }
|
328 | 342 |
|
329 | 343 | /**
|
@@ -510,9 +524,7 @@ public function initFromOrder(\Magento\Sales\Model\Order $order)
|
510 | 524 |
|
511 | 525 | $shippingAddress = $order->getShippingAddress();
|
512 | 526 | if ($shippingAddress) {
|
513 |
| - $addressDiff = array_diff_assoc($shippingAddress->getData(), $order->getBillingAddress()->getData()); |
514 |
| - unset($addressDiff['address_type'], $addressDiff['entity_id']); |
515 |
| - $shippingAddress->setSameAsBilling(empty($addressDiff)); |
| 527 | + $shippingAddress->setSameAsBilling($this->isAddressesAreEqual($order)); |
516 | 528 | }
|
517 | 529 |
|
518 | 530 | $this->_initBillingAddressFromOrder($order);
|
@@ -2010,4 +2022,26 @@ protected function _getNewCustomerEmail()
|
2010 | 2022 |
|
2011 | 2023 | return $email;
|
2012 | 2024 | }
|
| 2025 | + |
| 2026 | + /** |
| 2027 | + * Checks id shipping and billing addresses are equal. |
| 2028 | + * |
| 2029 | + * @param Order $order |
| 2030 | + * @return bool |
| 2031 | + */ |
| 2032 | + private function isAddressesAreEqual(Order $order) |
| 2033 | + { |
| 2034 | + $shippingAddress = $order->getShippingAddress(); |
| 2035 | + $billingAddress = $order->getBillingAddress(); |
| 2036 | + $shippingData = $this->dataObjectConverter->toFlatArray($shippingAddress, [], OrderAddressInterface::class); |
| 2037 | + $billingData = $this->dataObjectConverter->toFlatArray($billingAddress, [], OrderAddressInterface::class); |
| 2038 | + unset( |
| 2039 | + $shippingData['address_type'], |
| 2040 | + $shippingData['entity_id'], |
| 2041 | + $billingData['address_type'], |
| 2042 | + $billingData['entity_id'] |
| 2043 | + ); |
| 2044 | + |
| 2045 | + return $shippingData == $billingData; |
| 2046 | + } |
2013 | 2047 | }
|
0 commit comments