Skip to content

Commit

Permalink
Merge pull request #1738 from magento-engcom/2.2-develop-prs
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Oleksii Korshenko authored Nov 21, 2017
2 parents 2b78994 + 6cb8f62 commit 513e9f5
Show file tree
Hide file tree
Showing 6 changed files with 421 additions and 449 deletions.
2 changes: 1 addition & 1 deletion app/code/Magento/Catalog/Model/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -1712,7 +1712,7 @@ public function isInStock()
* Get attribute text by its code
*
* @param string $attributeCode Code of the attribute
* @return string
* @return string|array|null
*/
public function getAttributeText($attributeCode)
{
Expand Down
40 changes: 36 additions & 4 deletions app/code/Magento/Sales/Model/AdminOrder/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@

use Magento\Customer\Api\AddressMetadataInterface;
use Magento\Customer\Model\Metadata\Form as CustomerForm;
use Magento\Framework\Api\ExtensibleDataObjectConverter;
use Magento\Framework\App\ObjectManager;
use Magento\Quote\Model\Quote\Address;
use Magento\Quote\Model\Quote\Item;
use Magento\Sales\Api\Data\OrderAddressInterface;
use Magento\Sales\Model\Order;

/**
* Order create model
Expand Down Expand Up @@ -235,6 +238,11 @@ class Create extends \Magento\Framework\DataObject implements \Magento\Checkout\
*/
private $serializer;

/**
* @var ExtensibleDataObjectConverter
*/
private $dataObjectConverter;

/**
* @param \Magento\Framework\ObjectManagerInterface $objectManager
* @param \Magento\Framework\Event\ManagerInterface $eventManager
Expand Down Expand Up @@ -265,6 +273,7 @@ class Create extends \Magento\Framework\DataObject implements \Magento\Checkout\
* @param \Magento\Quote\Model\QuoteFactory $quoteFactory
* @param array $data
* @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
* @param ExtensibleDataObjectConverter|null $dataObjectConverter
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
Expand Down Expand Up @@ -296,7 +305,8 @@ public function __construct(
\Magento\Sales\Api\OrderManagementInterface $orderManagement,
\Magento\Quote\Model\QuoteFactory $quoteFactory,
array $data = [],
\Magento\Framework\Serialize\Serializer\Json $serializer = null
\Magento\Framework\Serialize\Serializer\Json $serializer = null,
ExtensibleDataObjectConverter $dataObjectConverter = null
) {
$this->_objectManager = $objectManager;
$this->_eventManager = $eventManager;
Expand Down Expand Up @@ -328,6 +338,8 @@ public function __construct(
$this->serializer = $serializer ?: ObjectManager::getInstance()
->get(\Magento\Framework\Serialize\Serializer\Json::class);
parent::__construct($data);
$this->dataObjectConverter = $dataObjectConverter ?: ObjectManager::getInstance()
->get(ExtensibleDataObjectConverter::class);
}

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

$shippingAddress = $order->getShippingAddress();
if ($shippingAddress) {
$addressDiff = array_diff_assoc($shippingAddress->getData(), $order->getBillingAddress()->getData());
unset($addressDiff['address_type'], $addressDiff['entity_id']);
$shippingAddress->setSameAsBilling(empty($addressDiff));
$shippingAddress->setSameAsBilling($this->isAddressesAreEqual($order));
}

$this->_initBillingAddressFromOrder($order);
Expand Down Expand Up @@ -2010,4 +2020,26 @@ protected function _getNewCustomerEmail()

return $email;
}

/**
* Checks id shipping and billing addresses are equal.
*
* @param Order $order
* @return bool
*/
private function isAddressesAreEqual(Order $order)
{
$shippingAddress = $order->getShippingAddress();
$billingAddress = $order->getBillingAddress();
$shippingData = $this->dataObjectConverter->toFlatArray($shippingAddress, [], OrderAddressInterface::class);
$billingData = $this->dataObjectConverter->toFlatArray($billingAddress, [], OrderAddressInterface::class);
unset(
$shippingData['address_type'],
$shippingData['entity_id'],
$billingData['address_type'],
$billingData['entity_id']
);

return $shippingData == $billingData;
}
}
Loading

0 comments on commit 513e9f5

Please sign in to comment.