Skip to content

Commit d3bbd3d

Browse files
committed
ACP2E-3255: [GRAPHQL] model value should be specified when getting customerCart
- Fixed the CR comments.
1 parent 7673b23 commit d3bbd3d

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

app/code/Magento/QuoteGraphQl/Plugin/Model/CreateEmptyCartWithoutCountryValidation.php

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
use Closure;
1919
use Exception;
2020
use Magento\Quote\Model\QuoteManagement;
21+
use Magento\Framework\App\Config\ScopeConfigInterface;
22+
use Magento\Customer\Model\Config\Share;
2123

2224
class CreateEmptyCartWithoutCountryValidation
2325
{
@@ -26,12 +28,14 @@ class CreateEmptyCartWithoutCountryValidation
2628
* @param CartRepositoryInterface $quoteRepository
2729
* @param CustomerRepositoryInterface $customerRepository
2830
* @param QuoteFactory $quoteFactory
31+
* @param ScopeConfigInterface $scopeConfig
2932
*/
3033
public function __construct(
3134
private readonly StoreManagerInterface $storeManager,
3235
private readonly CartRepositoryInterface $quoteRepository,
3336
private readonly CustomerRepositoryInterface $customerRepository,
34-
private readonly QuoteFactory $quoteFactory
37+
private readonly QuoteFactory $quoteFactory,
38+
private readonly ScopeConfigInterface $scopeConfig
3539
) {
3640
}
3741

@@ -52,15 +56,23 @@ public function aroundCreateEmptyCartForCustomer(
5256
Closure $proceed,
5357
int $customerId
5458
): bool|int {
55-
$storeId = (int) $this->storeManager->getStore()->getStoreId();
56-
$quote = $this->createCustomerCart($customerId, $storeId);
59+
$customerAccountShareScope = (int) $this->scopeConfig->getValue(
60+
Share::XML_PATH_CUSTOMER_ACCOUNT_SHARE,
61+
ScopeConfigInterface::SCOPE_TYPE_DEFAULT
62+
);
63+
if ($customerAccountShareScope === Share::SHARE_GLOBAL) {
64+
$storeId = (int) $this->storeManager->getStore()->getStoreId();
65+
$quote = $this->createCustomerCart($customerId, $storeId);
5766

58-
try {
59-
$this->quoteRepository->save($quote);
60-
} catch (Exception $e) {
61-
throw new CouldNotSaveException(__("The quote can't be created."));
67+
try {
68+
$this->quoteRepository->save($quote);
69+
} catch (Exception $e) {
70+
throw new CouldNotSaveException(__("The quote can't be created."));
71+
}
72+
return (int)$quote->getId();
73+
} else {
74+
return $proceed($customerId);
6275
}
63-
return (int)$quote->getId();
6476
}
6577

6678
/**

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Magento\QuoteGraphQl\Plugin\Model\CreateEmptyCartWithoutCountryValidation;
2020
use Magento\Store\Model\Store;
2121
use Magento\Customer\Api\Data\CustomerInterface as Customer;
22+
use Magento\Framework\App\Config\ScopeConfigInterface;
2223
use PHPUnit\Framework\MockObject\Exception;
2324
use PHPUnit\Framework\TestCase;
2425
use PHPUnit\Framework\MockObject\MockObject;
@@ -68,6 +69,11 @@ class CreateEmptyCartWithoutCountryValidationTest extends TestCase
6869
*/
6970
private MockObject|Quote $quote;
7071

72+
/**
73+
* @var MockObject|ScopeConfigInterface
74+
*/
75+
private MockObject|ScopeConfigInterface $scopeConfig;
76+
7177
/**
7278
* @throws Exception
7379
*/
@@ -83,12 +89,14 @@ protected function setUp(): void
8389
->disableOriginalConstructor()
8490
->getMock();
8591
$this->quote = $this->createMock(Quote::class);
92+
$this->scopeConfig = $this->createMock(ScopeConfigInterface::class);
8693

8794
$this->model = new CreateEmptyCartWithoutCountryValidation(
8895
$this->storeManager,
8996
$this->quoteRepository,
9097
$this->customerRepository,
91-
$this->quoteFactory
98+
$this->quoteFactory,
99+
$this->scopeConfig
92100
);
93101
}
94102

0 commit comments

Comments
 (0)