Skip to content

Commit 2c03260

Browse files
committed
AC-6731: Validation fixes for WebAPI
1 parent 913cbf9 commit 2c03260

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66

77
namespace Magento\Quote\Model;
88

9+
use Magento\Framework\App\ObjectManager;
910
use Magento\Framework\Exception\InputException;
10-
use Magento\Quote\Model\Quote\Address\BillingAddressPersister;
11-
use Psr\Log\LoggerInterface as Logger;
1211
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;
1414

1515
/**
1616
* Quote billing address write service object.
@@ -72,10 +72,18 @@ public function __construct(
7272
* @inheritdoc
7373
* @SuppressWarnings(PHPMD.NPathComplexity)
7474
*/
75-
public function assign($cartId, \Magento\Quote\Api\Data\AddressInterface $address, $useForShipping = false)
75+
public function assign($cartId, AddressInterface $address, $useForShipping = false)
7676
{
7777
/** @var \Magento\Quote\Model\Quote $quote */
7878
$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+
7987
$address->setCustomerId($quote->getCustomerId());
8088
$quote->removeAddress($quote->getBillingAddress()->getId());
8189
$quote->setBillingAddress($address);

0 commit comments

Comments
 (0)