18
18
use Closure ;
19
19
use Exception ;
20
20
use Magento \Quote \Model \QuoteManagement ;
21
+ use Magento \Framework \App \Config \ScopeConfigInterface ;
22
+ use Magento \Customer \Model \Config \Share ;
21
23
22
24
class CreateEmptyCartWithoutCountryValidation
23
25
{
@@ -26,12 +28,14 @@ class CreateEmptyCartWithoutCountryValidation
26
28
* @param CartRepositoryInterface $quoteRepository
27
29
* @param CustomerRepositoryInterface $customerRepository
28
30
* @param QuoteFactory $quoteFactory
31
+ * @param ScopeConfigInterface $scopeConfig
29
32
*/
30
33
public function __construct (
31
34
private readonly StoreManagerInterface $ storeManager ,
32
35
private readonly CartRepositoryInterface $ quoteRepository ,
33
36
private readonly CustomerRepositoryInterface $ customerRepository ,
34
- private readonly QuoteFactory $ quoteFactory
37
+ private readonly QuoteFactory $ quoteFactory ,
38
+ private readonly ScopeConfigInterface $ scopeConfig
35
39
) {
36
40
}
37
41
@@ -52,15 +56,23 @@ public function aroundCreateEmptyCartForCustomer(
52
56
Closure $ proceed ,
53
57
int $ customerId
54
58
): 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 );
57
66
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 );
62
75
}
63
- return (int )$ quote ->getId ();
64
76
}
65
77
66
78
/**
0 commit comments