Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 63b549b

Browse files
committed
Sync billing with shipping address on Admin Order Page
- Added validation for empty applied taxes to avoid exceptions during json decoding
1 parent d1e6f82 commit 63b549b

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

app/code/Magento/Quote/Model/Quote/Address.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1170,7 +1170,8 @@ public function validateMinimumAmount()
11701170
*/
11711171
public function getAppliedTaxes()
11721172
{
1173-
return $this->serializer->unserialize($this->getData('applied_taxes'));
1173+
$taxes = $this->getData('applied_taxes');
1174+
return $taxes ? $this->serializer->unserialize($taxes) : [];
11741175
}
11751176

11761177
/**

app/code/Magento/Quote/Test/Unit/Model/Quote/AddressTest.php

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
namespace Magento\Quote\Test\Unit\Model\Quote;
1010

1111
use Magento\Directory\Model\Currency;
12-
use \Magento\Quote\Model\Quote\Address;
12+
use Magento\Quote\Model\Quote\Address;
1313
use Magento\Quote\Model\Quote\Address\Rate;
1414
use Magento\Quote\Model\ResourceModel\Quote\Address\Rate\CollectionFactory as RateCollectionFactory;
1515
use Magento\Quote\Model\ResourceModel\Quote\Address\Rate\Collection as RatesCollection;
@@ -28,6 +28,7 @@
2828
use Magento\Store\Api\Data\StoreInterface;
2929
use Magento\Store\Api\Data\WebsiteInterface;
3030
use Magento\Quote\Model\Quote\Address\RateResult\AbstractResult;
31+
use Magento\Framework\Serialize\Serializer\Json;
3132

3233
/**
3334
* Test class for sales quote address model
@@ -117,7 +118,7 @@ protected function setUp()
117118
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
118119

119120
$this->scopeConfig = $this->createMock(\Magento\Framework\App\Config::class);
120-
$this->serializer = $this->createMock(\Magento\Framework\Serialize\Serializer\Json::class);
121+
$this->serializer = new Json();
121122

122123
$this->requestFactory = $this->getMockBuilder(RateRequestFactory::class)
123124
->disableOriginalConstructor()
@@ -273,20 +274,17 @@ public function testValidateMiniumumAmountNegative()
273274
public function testSetAndGetAppliedTaxes()
274275
{
275276
$data = ['data'];
276-
$result = json_encode($data);
277-
278-
$this->serializer->expects($this->once())
279-
->method('serialize')
280-
->with($data)
281-
->willReturn($result);
282-
283-
$this->serializer->expects($this->once())
284-
->method('unserialize')
285-
->with($result)
286-
->willReturn($data);
277+
self::assertInstanceOf(Address::class, $this->address->setAppliedTaxes($data));
278+
self::assertEquals($data, $this->address->getAppliedTaxes());
279+
}
287280

288-
$this->assertInstanceOf(\Magento\Quote\Model\Quote\Address::class, $this->address->setAppliedTaxes($data));
289-
$this->assertEquals($data, $this->address->getAppliedTaxes());
281+
/**
282+
* Checks a case, when applied taxes are not provided.
283+
*/
284+
public function testGetAppliedTaxesWithEmptyValue()
285+
{
286+
$this->address->setData('applied_taxes', null);
287+
self::assertEquals([], $this->address->getAppliedTaxes());
290288
}
291289

292290
/**

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
use Magento\Customer\Api\AddressMetadataInterface;
1212
use Magento\Customer\Model\Metadata\Form as CustomerForm;
13+
use Magento\Framework\App\ObjectManager;
1314
use Magento\Quote\Model\Quote\Address;
1415
use Magento\Quote\Model\Quote\Item;
1516

@@ -324,7 +325,7 @@ public function __construct(
324325
$this->dataObjectHelper = $dataObjectHelper;
325326
$this->orderManagement = $orderManagement;
326327
$this->quoteFactory = $quoteFactory;
327-
$this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
328+
$this->serializer = $serializer ?: ObjectManager::getInstance()
328329
->get(\Magento\Framework\Serialize\Serializer\Json::class);
329330
parent::__construct($data);
330331
}
@@ -1476,8 +1477,8 @@ public function setBillingAddress($address)
14761477
// not assigned billing address should be saved as new
14771478
// but if quote already has the billing address it won't be overridden
14781479
if (empty($billingAddress->getCustomerAddressId())) {
1479-
$quote->removeAddress($quote->getBillingAddress()->getId());
14801480
$billingAddress->setCustomerAddressId(null);
1481+
$quote->getBillingAddress()->setCustomerAddressId(null);
14811482
}
14821483
$quote->setBillingAddress($billingAddress);
14831484

0 commit comments

Comments
 (0)