Skip to content

Commit 513e9f5

Browse files
author
Oleksii Korshenko
authored
Merge pull request #1738 from magento-engcom/2.2-develop-prs
Public Pull Requests #12003 #11691: Wrong return type for getAttributeText($attributeCode) by @p-bystritsky #12308 12261: Order confirmation email contains non functioning links #12261 by @RomaKis #11787 Fix #10438: Potential error on order edit page when address has extension attributes by @joni-jones Fixed Public Issues #11691 Wrong return type for getAttributeText($attributeCode) #12261 Order confirmation email contains non functioning links #10438 Potential error on order edit page when address has extension attributes
2 parents 2b78994 + 6cb8f62 commit 513e9f5

File tree

6 files changed

+421
-449
lines changed

6 files changed

+421
-449
lines changed

app/code/Magento/Catalog/Model/Product.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1712,7 +1712,7 @@ public function isInStock()
17121712
* Get attribute text by its code
17131713
*
17141714
* @param string $attributeCode Code of the attribute
1715-
* @return string
1715+
* @return string|array|null
17161716
*/
17171717
public function getAttributeText($attributeCode)
17181718
{

app/code/Magento/Sales/Model/AdminOrder/Create.php

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@
1010

1111
use Magento\Customer\Api\AddressMetadataInterface;
1212
use Magento\Customer\Model\Metadata\Form as CustomerForm;
13+
use Magento\Framework\Api\ExtensibleDataObjectConverter;
1314
use Magento\Framework\App\ObjectManager;
1415
use Magento\Quote\Model\Quote\Address;
1516
use Magento\Quote\Model\Quote\Item;
17+
use Magento\Sales\Api\Data\OrderAddressInterface;
18+
use Magento\Sales\Model\Order;
1619

1720
/**
1821
* Order create model
@@ -235,6 +238,11 @@ class Create extends \Magento\Framework\DataObject implements \Magento\Checkout\
235238
*/
236239
private $serializer;
237240

241+
/**
242+
* @var ExtensibleDataObjectConverter
243+
*/
244+
private $dataObjectConverter;
245+
238246
/**
239247
* @param \Magento\Framework\ObjectManagerInterface $objectManager
240248
* @param \Magento\Framework\Event\ManagerInterface $eventManager
@@ -265,6 +273,7 @@ class Create extends \Magento\Framework\DataObject implements \Magento\Checkout\
265273
* @param \Magento\Quote\Model\QuoteFactory $quoteFactory
266274
* @param array $data
267275
* @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
276+
* @param ExtensibleDataObjectConverter|null $dataObjectConverter
268277
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
269278
*/
270279
public function __construct(
@@ -296,7 +305,8 @@ public function __construct(
296305
\Magento\Sales\Api\OrderManagementInterface $orderManagement,
297306
\Magento\Quote\Model\QuoteFactory $quoteFactory,
298307
array $data = [],
299-
\Magento\Framework\Serialize\Serializer\Json $serializer = null
308+
\Magento\Framework\Serialize\Serializer\Json $serializer = null,
309+
ExtensibleDataObjectConverter $dataObjectConverter = null
300310
) {
301311
$this->_objectManager = $objectManager;
302312
$this->_eventManager = $eventManager;
@@ -328,6 +338,8 @@ public function __construct(
328338
$this->serializer = $serializer ?: ObjectManager::getInstance()
329339
->get(\Magento\Framework\Serialize\Serializer\Json::class);
330340
parent::__construct($data);
341+
$this->dataObjectConverter = $dataObjectConverter ?: ObjectManager::getInstance()
342+
->get(ExtensibleDataObjectConverter::class);
331343
}
332344

333345
/**
@@ -514,9 +526,7 @@ public function initFromOrder(\Magento\Sales\Model\Order $order)
514526

515527
$shippingAddress = $order->getShippingAddress();
516528
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));
520530
}
521531

522532
$this->_initBillingAddressFromOrder($order);
@@ -2010,4 +2020,26 @@ protected function _getNewCustomerEmail()
20102020

20112021
return $email;
20122022
}
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+
}
20132045
}

0 commit comments

Comments
 (0)