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 \TestFramework \Fixture \Api \DataMerger ;
15
16
use Magento \TestFramework \Fixture \Api \ServiceFactory ;
17
+ use Magento \TestFramework \Fixture \Data \ProcessorInterface ;
16
18
use Magento \TestFramework \Fixture \RevertibleDataFixtureInterface ;
17
19
18
20
class CustomerCart implements RevertibleDataFixtureInterface
19
21
{
20
22
23
+ private const DEFAULT_DATA = [
24
+ 'customer_id ' => null
25
+ ];
26
+
21
27
/**
22
28
* @var ServiceFactory
23
29
*/
@@ -43,32 +49,49 @@ class CustomerCart implements RevertibleDataFixtureInterface
43
49
*/
44
50
private $ quoteFactory ;
45
51
52
+ /**
53
+ * @var ProcessorInterface
54
+ */
55
+ private $ dataProcessor ;
56
+
57
+ /**
58
+ * @var DataMerger
59
+ */
60
+ private $ dataMerger ;
61
+
46
62
/**
47
63
* @param ServiceFactory $serviceFactory
48
64
* @param CartRepositoryInterface $cartRepository
49
65
* @param CartManagementInterface $cartManagement
50
66
* @param QuoteResource $quoteResource
51
67
* @param QuoteFactory $quoteFactory
68
+ * @param ProcessorInterface $dataProcessor
69
+ * @param DataMerger $dataMerger
52
70
*/
53
71
public function __construct (
54
72
ServiceFactory $ serviceFactory ,
55
73
CartRepositoryInterface $ cartRepository ,
56
74
CartManagementInterface $ cartManagement ,
57
75
QuoteResource $ quoteResource ,
58
- QuoteFactory $ quoteFactory
76
+ QuoteFactory $ quoteFactory ,
77
+ ProcessorInterface $ dataProcessor ,
78
+ DataMerger $ dataMerger ,
59
79
) {
60
80
$ this ->serviceFactory = $ serviceFactory ;
61
81
$ this ->cartRepository = $ cartRepository ;
62
82
$ this ->cartManagement = $ cartManagement ;
63
83
$ this ->quoteResource = $ quoteResource ;
64
84
$ this ->quoteFactory = $ quoteFactory ;
85
+ $ this ->dataProcessor = $ dataProcessor ;
86
+ $ this ->dataMerger = $ dataMerger ;
65
87
}
66
88
67
89
/**
68
90
* @inheritdoc
69
91
*/
70
92
public function apply (array $ data = []): ?DataObject
71
93
{
94
+ $ data = $ this ->prepareData ($ data );
72
95
$ customerId = $ data ['customer_id ' ] ?? null ;
73
96
$ cartService = $ this ->serviceFactory ->create (CartManagementInterface::class, 'createEmptyCartForCustomer ' );
74
97
$ cartId = $ cartService ->execute (['customerId ' => $ customerId ]);
@@ -84,4 +107,16 @@ public function revert(DataObject $data): void
84
107
$ cartRepositoryService = $ this ->serviceFactory ->create (CartRepositoryInterface::class, 'delete ' );
85
108
$ cartRepositoryService ->execute (['quote ' => $ data ]);
86
109
}
110
+
111
+ /**
112
+ * Prepare quote data
113
+ *
114
+ * @param array $data
115
+ * @return array
116
+ */
117
+ private function prepareData (array $ data ): array
118
+ {
119
+ $ data = $ this ->dataMerger ->merge (self ::DEFAULT_DATA , $ data , false );
120
+ return $ this ->dataProcessor ->process ($ this , $ data );
121
+ }
87
122
}
0 commit comments