|
6 | 6 |
|
7 | 7 | namespace Magento\Quote\Model;
|
8 | 8 |
|
| 9 | +use Magento\Framework\App\ObjectManager; |
9 | 10 | use Magento\Framework\Exception\InputException;
|
10 |
| -use Magento\Quote\Model\Quote\Address\BillingAddressPersister; |
11 |
| -use Psr\Log\LoggerInterface as Logger; |
12 | 11 | use Magento\Quote\Api\BillingAddressManagementInterface;
|
13 |
| -use Magento\Framework\App\ObjectManager; |
| 12 | +use Magento\Quote\Api\Data\AddressInterface; |
| 13 | +use Psr\Log\LoggerInterface as Logger; |
14 | 14 |
|
15 | 15 | /**
|
16 | 16 | * Quote billing address write service object.
|
@@ -72,10 +72,18 @@ public function __construct(
|
72 | 72 | * @inheritdoc
|
73 | 73 | * @SuppressWarnings(PHPMD.NPathComplexity)
|
74 | 74 | */
|
75 |
| - public function assign($cartId, \Magento\Quote\Api\Data\AddressInterface $address, $useForShipping = false) |
| 75 | + public function assign($cartId, AddressInterface $address, $useForShipping = false) |
76 | 76 | {
|
77 | 77 | /** @var \Magento\Quote\Model\Quote $quote */
|
78 | 78 | $quote = $this->quoteRepository->getActive($cartId);
|
| 79 | + |
| 80 | + // reset the address id, if it doesn't belong to quote. |
| 81 | + $old = $quote->getAddressesCollection()->getItemById($address->getId()) |
| 82 | + ?? $quote->getBillingAddress(); |
| 83 | + if ($old !== null) { |
| 84 | + $address->setId($old->getId()); |
| 85 | + } |
| 86 | + |
79 | 87 | $address->setCustomerId($quote->getCustomerId());
|
80 | 88 | $quote->removeAddress($quote->getBillingAddress()->getId());
|
81 | 89 | $quote->setBillingAddress($address);
|
|
0 commit comments