35
35
use ScandiPWA \Performance \Model \Resolver \Products \DataPostProcessor ;
36
36
use \Magento \Quote \Api \Data \AddressInterface ;
37
37
use Magento \Tax \Model \Config ;
38
+ use Magento \Downloadable \Model \LinkRepository ;
39
+ use Magento \Downloadable \Model \Link ;
38
40
39
41
class GetCartForCustomer extends CartResolver
40
42
{
@@ -62,6 +64,9 @@ class GetCartForCustomer extends CartResolver
62
64
/** @var Config */
63
65
private $ config ;
64
66
67
+ /** @var LinkRepository */
68
+ protected $ linkRepository ;
69
+
65
70
/**
66
71
* GetCartForCustomer constructor.
67
72
* @param ParamOverriderCustomerId $overriderCustomerId
@@ -73,6 +78,7 @@ class GetCartForCustomer extends CartResolver
73
78
* @param CustomizableOption $customizableOption
74
79
* @param BundleOptionDataProvider $bundleOptions
75
80
* @param Config $config
81
+ * @param LinkRepository $linkRepository
76
82
*/
77
83
public function __construct (
78
84
ParamOverriderCustomerId $ overriderCustomerId ,
@@ -84,7 +90,8 @@ public function __construct(
84
90
CustomizableOption $ customizableOption ,
85
91
BundleOptionDataProvider $ bundleOptions ,
86
92
Json $ serializer ,
87
- Config $ config
93
+ Config $ config ,
94
+ LinkRepository $ linkRepository
88
95
) {
89
96
parent ::__construct (
90
97
$ guestCartRepository ,
@@ -99,6 +106,7 @@ public function __construct(
99
106
$ this ->bundleOptions = $ bundleOptions ;
100
107
$ this ->serializer = $ serializer ;
101
108
$ this ->config = $ config ;
109
+ $ this ->linkRepository = $ linkRepository ;
102
110
}
103
111
104
112
/**
@@ -114,10 +122,42 @@ protected function mergeQuoteItemData(
114
122
return [
115
123
'product ' => $ this ->productsData [$ product ->getId ()],
116
124
'customizable_options ' => $ this ->getCustomizableOptions ($ item ),
117
- 'bundle_options ' => $ this ->bundleOptions ->getData ($ item )
125
+ 'bundle_options ' => $ this ->bundleOptions ->getData ($ item ),
126
+ 'downloadable_links ' => $ this ->getDownloadableLinks ($ item , $ product )
118
127
] + $ item ->getData ();
119
128
}
120
129
130
+ /**
131
+ * @param $item
132
+ * @param $product
133
+ * @return array
134
+ */
135
+ private function getDownloadableLinks ($ item , $ product ): array
136
+ {
137
+ $ quoteItemLinks = $ item ->getOptionByCode ('downloadable_link_ids ' );
138
+
139
+ if (null === $ quoteItemLinks ) {
140
+ return [];
141
+ }
142
+
143
+ $ downloadableLinks = [];
144
+ $ downloadableLinkIds = explode (', ' , $ quoteItemLinks ->getValue ());
145
+ $ productLinks = $ this ->linkRepository ->getLinksByProduct ($ product );
146
+
147
+ /** @var Link $productLink */
148
+ foreach ($ productLinks as $ productLink ) {
149
+ if (in_array ($ productLink ->getId (), $ downloadableLinkIds )){
150
+ $ downloadableLinks [] = [
151
+ 'label ' => $ productLink ->getTitle (),
152
+ 'id ' => $ productLink ->getId ()
153
+ ];
154
+ }
155
+ }
156
+
157
+ return $ downloadableLinks ;
158
+ }
159
+
160
+
121
161
/**
122
162
* @param $item
123
163
* @return array
0 commit comments