12
12
use Magento \Quote \Api \CartRepositoryInterface ;
13
13
use Magento \Quote \Model \QuoteFactory ;
14
14
use Magento \Quote \Model \ResourceModel \Quote as QuoteResource ;
15
+ use Magento \Store \Model \StoreManagerInterface ;
15
16
use Magento \TestFramework \Fixture \Api \DataMerger ;
16
17
use Magento \TestFramework \Fixture \Api \ServiceFactory ;
17
18
use Magento \TestFramework \Fixture \Data \ProcessorInterface ;
18
19
use Magento \TestFramework \Fixture \RevertibleDataFixtureInterface ;
19
20
20
21
class CustomerCart implements RevertibleDataFixtureInterface
21
22
{
22
-
23
23
private const DEFAULT_DATA = [
24
24
'customer_id ' => null
25
25
];
@@ -59,8 +59,14 @@ class CustomerCart implements RevertibleDataFixtureInterface
59
59
*/
60
60
private $ dataMerger ;
61
61
62
+ /**
63
+ * @var StoreManagerInterface
64
+ */
65
+ private $ storeManager ;
66
+
62
67
/**
63
68
* @param ServiceFactory $serviceFactory
69
+ * @param StoreManagerInterface $storeManager
64
70
* @param CartRepositoryInterface $cartRepository
65
71
* @param CartManagementInterface $cartManagement
66
72
* @param QuoteResource $quoteResource
@@ -70,6 +76,7 @@ class CustomerCart implements RevertibleDataFixtureInterface
70
76
*/
71
77
public function __construct (
72
78
ServiceFactory $ serviceFactory ,
79
+ StoreManagerInterface $ storeManager ,
73
80
CartRepositoryInterface $ cartRepository ,
74
81
CartManagementInterface $ cartManagement ,
75
82
QuoteResource $ quoteResource ,
@@ -78,6 +85,7 @@ public function __construct(
78
85
DataMerger $ dataMerger ,
79
86
) {
80
87
$ this ->serviceFactory = $ serviceFactory ;
88
+ $ this ->storeManager = $ storeManager ;
81
89
$ this ->cartRepository = $ cartRepository ;
82
90
$ this ->cartManagement = $ cartManagement ;
83
91
$ this ->quoteResource = $ quoteResource ;
@@ -95,17 +103,14 @@ public function apply(array $data = []): ?DataObject
95
103
$ customerId = $ data ['customer_id ' ] ?? null ;
96
104
$ storeId = $ data ['store_id ' ] ?? null ;
97
105
if ($ storeId ) {
98
- $ cartService = $ this ->serviceFactory ->create (CartManagementInterface::class, 'createEmptyCart ' );
99
- } else {
100
- $ cartService = $ this ->serviceFactory ->create (CartManagementInterface::class, 'createEmptyCartForCustomer ' );
106
+ $ setCurrentStoreService = $ this ->serviceFactory ->create (StoreManagerInterface::class, 'setCurrentStore ' );
107
+ $ setCurrentStoreService ->execute (['store ' => $ storeId ]);
101
108
}
109
+ $ cartService = $ this ->serviceFactory ->create (CartManagementInterface::class, 'createEmptyCartForCustomer ' );
102
110
$ cartId = $ cartService ->execute (['customerId ' => $ customerId ]);
103
- if ($ storeId ) {
104
- $ cartService = $ this ->serviceFactory ->create (CartManagementInterface::class, 'assignCustomer ' );
105
- $ cartService ->execute (['cartId ' => $ cartId , 'customerId ' => $ customerId , 'storeId ' => $ storeId ]);
106
- }
107
111
$ cartRepositoryService = $ this ->serviceFactory ->create (CartRepositoryInterface::class, 'get ' );
108
- return $ cartRepositoryService ->execute (['cartId ' => $ cartId ]);
112
+ $ cart = $ cartRepositoryService ->execute (['cartId ' => $ cartId ]);
113
+ return $ cart ;
109
114
}
110
115
111
116
/**
0 commit comments