Skip to content

Commit b0dac64

Browse files
committed
ACP2E-3255: [GRAPHQL] model value should be specified when getting customerCart
- Fixed the issue.
1 parent 71432ae commit b0dac64

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

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

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
use Magento\Sales\Api\Data\OrderInterfaceFactory as OrderFactory;
4444
use Magento\Sales\Api\OrderManagementInterface as OrderManagement;
4545
use Magento\Store\Model\StoreManagerInterface;
46+
use Magento\Customer\Model\AddressRegistry;
4647

4748
/**
4849
* Class for managing quote
@@ -183,6 +184,11 @@ class QuoteManagement implements CartManagementInterface, ResetAfterRequestInter
183184
*/
184185
private $cartMutex;
185186

187+
/**
188+
* @var AddressRegistry
189+
*/
190+
private $addressRegistry;
191+
186192
/**
187193
* @param EventManager $eventManager
188194
* @param SubmitQuoteValidator $submitQuoteValidator
@@ -210,6 +216,7 @@ class QuoteManagement implements CartManagementInterface, ResetAfterRequestInter
210216
* @param RemoteAddress|null $remoteAddress
211217
* @param LockManagerInterface $lockManager
212218
* @param CartMutexInterface|null $cartMutex
219+
* @param AddressRegistry|null $addressRegistry
213220
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
214221
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
215222
*/
@@ -239,7 +246,8 @@ public function __construct(
239246
RequestInterface $request = null,
240247
RemoteAddress $remoteAddress = null,
241248
LockManagerInterface $lockManager = null,
242-
?CartMutexInterface $cartMutex = null
249+
?CartMutexInterface $cartMutex = null,
250+
?AddressRegistry $addressRegistry = null
243251
) {
244252
$this->eventManager = $eventManager;
245253
$this->submitQuoteValidator = $submitQuoteValidator;
@@ -271,6 +279,8 @@ public function __construct(
271279
->get(RemoteAddress::class);
272280
$this->cartMutex = $cartMutex
273281
?? ObjectManager::getInstance()->get(CartMutexInterface::class);
282+
$this->addressRegistry = $addressRegistry
283+
?? ObjectManager::getInstance()->get(AddressRegistry::class);
274284
}
275285

276286
/**
@@ -696,7 +706,9 @@ protected function _prepareCustomerQuote($quote)
696706
}
697707
//save here new customer address
698708
$shippingAddress->setCustomerId($quote->getCustomerId());
699-
$this->addressRepository->save($shippingAddress);
709+
if ($this->validateAddress((int) $shippingAddress->getId()) === true) {
710+
$this->addressRepository->save($shippingAddress);
711+
}
700712
$quote->addCustomerAddress($shippingAddress);
701713
$shipping->setCustomerAddressData($shippingAddress);
702714
$this->addressesToSync[] = $shippingAddress->getId();
@@ -728,7 +740,9 @@ protected function _prepareCustomerQuote($quote)
728740
$billingAddress->setIsDefaultBilling(true);
729741
}
730742
$billingAddress->setCustomerId($quote->getCustomerId());
731-
$this->addressRepository->save($billingAddress);
743+
if ($this->validateAddress((int) $billingAddress->getId()) === true) {
744+
$this->addressRepository->save($billingAddress);
745+
}
732746
$quote->addCustomerAddress($billingAddress);
733747
$billing->setCustomerAddressData($billingAddress);
734748
$this->addressesToSync[] = $billingAddress->getId();
@@ -791,4 +805,17 @@ public function _resetState(): void
791805
{
792806
$this->addressesToSync = [];
793807
}
808+
809+
/**
810+
* Validate address
811+
*
812+
* @param int|null $addressId
813+
* @return array|bool
814+
* @throws NoSuchEntityException
815+
*/
816+
private function validateAddress(?int $addressId): bool|array
817+
{
818+
$addressModel = $this->addressRegistry->retrieve($addressId);
819+
return $addressModel->validate();
820+
}
794821
}

0 commit comments

Comments
 (0)