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