Skip to content

Commit 73bf5a9

Browse files
committed
ACP2E-3255: [GRAPHQL] model value should be specified when getting customerCart
- Fixed the CR comments.
1 parent 6a14377 commit 73bf5a9

File tree

4 files changed

+30
-272
lines changed

4 files changed

+30
-272
lines changed

app/code/Magento/Quote/Model/Cart/CustomerCartResolver.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Magento\Quote\Model\QuoteIdMaskFactory;
1515
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
1616
use Magento\Quote\Model\ResourceModel\Quote\QuoteIdMask as QuoteIdMaskResourceModel;
17+
use Magento\Quote\Model\CreateEmptyCartForCustomerWithoutCountryValidation;
1718

1819
/**
1920
* Get customer cart or create empty cart. Ensure mask_id is created
@@ -40,22 +41,30 @@ class CustomerCartResolver
4041
*/
4142
private $quoteIdToMaskedQuoteId;
4243

44+
/**
45+
* @var CreateEmptyCartForCustomerWithoutCountryValidation
46+
*/
47+
private $createEmptyCartForCustomerWithoutCountryValidation;
48+
4349
/**
4450
* @param CartManagementInterface $cartManagement
4551
* @param QuoteIdMaskFactory $quoteIdMaskFactory
4652
* @param QuoteIdMaskResourceModel $quoteIdMaskResourceModel
4753
* @param QuoteIdToMaskedQuoteIdInterface $quoteIdToMaskedQuoteId
54+
* @param CreateEmptyCartForCustomerWithoutCountryValidation $createEmptyCartForCustomerWithoutCountryValidation
4855
*/
4956
public function __construct(
5057
CartManagementInterface $cartManagement,
5158
QuoteIdMaskFactory $quoteIdMaskFactory,
5259
QuoteIdMaskResourceModel $quoteIdMaskResourceModel,
53-
QuoteIdToMaskedQuoteIdInterface $quoteIdToMaskedQuoteId
60+
QuoteIdToMaskedQuoteIdInterface $quoteIdToMaskedQuoteId,
61+
CreateEmptyCartForCustomerWithoutCountryValidation $createEmptyCartForCustomerWithoutCountryValidation
5462
) {
5563
$this->cartManagement = $cartManagement;
5664
$this->quoteIdMaskFactory = $quoteIdMaskFactory;
5765
$this->quoteIdMaskResourceModel = $quoteIdMaskResourceModel;
5866
$this->quoteIdToMaskedQuoteId = $quoteIdToMaskedQuoteId;
67+
$this->createEmptyCartForCustomerWithoutCountryValidation = $createEmptyCartForCustomerWithoutCountryValidation;
5968
}
6069

6170
/**
@@ -73,7 +82,8 @@ public function resolve(int $customerId, string $predefinedMaskedQuoteId = null)
7382
/** @var Quote $cart */
7483
$cart = $this->cartManagement->getCartForCustomer($customerId);
7584
} catch (NoSuchEntityException $e) {
76-
$this->cartManagement->createEmptyCartForCustomer($customerId);
85+
$this->createEmptyCartForCustomerWithoutCountryValidation
86+
->createEmptyCartForCustomerWithoutCountryValidation($customerId);
7787
$cart = $this->cartManagement->getCartForCustomer($customerId);
7888
}
7989
try {

app/code/Magento/QuoteGraphQl/Plugin/Model/CreateEmptyCartWithoutCountryValidation.php renamed to app/code/Magento/Quote/Model/CreateEmptyCartForCustomerWithoutCountryValidation.php

Lines changed: 18 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,23 @@
11
<?php
22
/**
3-
* Copyright 2024 Adobe
4-
* All Rights Reserved.
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
55
*/
66
declare(strict_types=1);
77

8-
namespace Magento\QuoteGraphQl\Plugin\Model;
8+
namespace Magento\Quote\Model;
99

10-
use Magento\Framework\Exception\CouldNotSaveException;
10+
use Magento\Customer\Api\CustomerRepositoryInterface;
11+
use Magento\Framework\App\Config\ScopeConfigInterface;
1112
use Magento\Framework\Exception\LocalizedException;
1213
use Magento\Framework\Exception\NoSuchEntityException;
13-
use Magento\Quote\Model\Quote;
14-
use Magento\Quote\Model\QuoteFactory;
15-
use Magento\Store\Model\StoreManagerInterface;
1614
use Magento\Quote\Api\CartRepositoryInterface;
17-
use Magento\Customer\Api\CustomerRepositoryInterface;
18-
use Closure;
19-
use Exception;
20-
use Magento\Quote\Model\QuoteManagement;
21-
use Magento\Framework\App\Config\ScopeConfigInterface;
22-
use Magento\Customer\Model\Config\Share;
15+
use Magento\Store\Model\StoreManagerInterface;
2316

2417
/**
25-
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
18+
* Class for creating empty cart for customer without country validation
2619
*/
27-
class CreateEmptyCartWithoutCountryValidation
20+
class CreateEmptyCartForCustomerWithoutCountryValidation
2821
{
2922
/**
3023
* @param StoreManagerInterface $storeManager
@@ -45,37 +38,22 @@ public function __construct(
4538
/**
4639
* Create empty cart for customer without country validation
4740
*
48-
* @param QuoteManagement $subject
49-
* @param Closure $proceed
5041
* @param int $customerId
5142
* @return bool|int
52-
* @throws CouldNotSaveException
53-
* @throws NoSuchEntityException
5443
* @throws LocalizedException
55-
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
44+
* @throws NoSuchEntityException
5645
*/
57-
public function aroundCreateEmptyCartForCustomer(
58-
QuoteManagement $subject,
59-
Closure $proceed,
60-
int $customerId
61-
): bool|int {
62-
$customerAccountShareScope = (int) $this->scopeConfig->getValue(
63-
Share::XML_PATH_CUSTOMER_ACCOUNT_SHARE,
64-
ScopeConfigInterface::SCOPE_TYPE_DEFAULT
65-
);
66-
if ($customerAccountShareScope === Share::SHARE_GLOBAL) {
67-
$storeId = (int) $this->storeManager->getStore()->getStoreId();
68-
$quote = $this->createCustomerCart($customerId, $storeId);
46+
public function createEmptyCartForCustomerWithoutCountryValidation(int $customerId): bool|int
47+
{
48+
$storeId = (int) $this->storeManager->getStore()->getStoreId();
49+
$quote = $this->createCustomerCart($customerId, $storeId);
6950

70-
try {
71-
$this->quoteRepository->save($quote);
72-
} catch (Exception $e) {
73-
throw new CouldNotSaveException(__("The quote can't be created."));
74-
}
75-
return (int)$quote->getId();
76-
} else {
77-
return $proceed($customerId);
51+
try {
52+
$this->quoteRepository->save($quote);
53+
} catch (Exception $e) {
54+
throw new CouldNotSaveException(__("The quote can't be created."));
7855
}
56+
return (int)$quote->getId();
7957
}
8058

8159
/**

app/code/Magento/QuoteGraphQl/Test/Unit/Plugin/Model/CreateEmptyCartWithoutCountryValidationTest.php

Lines changed: 0 additions & 228 deletions
This file was deleted.

app/code/Magento/QuoteGraphQl/etc/graphql/di.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,5 @@
7878
<type name="Magento\Quote\Model\QuoteManagement">
7979
<plugin name="merge_guest_orders_with_customer_after_place"
8080
type="Magento\QuoteGraphQl\Plugin\Model\MergeGuestOrder" />
81-
<plugin name="create_empty_cart_without_country_validation"
82-
type="Magento\QuoteGraphQl\Plugin\Model\CreateEmptyCartWithoutCountryValidation" />
8381
</type>
8482
</config>

0 commit comments

Comments
 (0)