5
5
*/
6
6
namespace Magento \Catalog \Model ;
7
7
8
- use Magento \Catalog \Api \Data \ProductOptionExtensionFactory ;
9
8
use Magento \Catalog \Api \Data \ProductOptionInterface ;
10
9
use Magento \Catalog \Model \CustomOptions \CustomOption ;
11
10
use Magento \Catalog \Model \CustomOptions \CustomOptionFactory ;
12
11
use Magento \Framework \DataObject ;
13
12
use Magento \Framework \DataObject \Factory as DataObjectFactory ;
13
+ use Magento \Framework \Serialize \Serializer \Json ;
14
14
15
+ /**
16
+ * Processor ofr product options
17
+ */
15
18
class ProductOptionProcessor implements ProductOptionProcessorInterface
16
19
{
17
20
/**
@@ -29,16 +32,27 @@ class ProductOptionProcessor implements ProductOptionProcessorInterface
29
32
*/
30
33
private $ urlBuilder ;
31
34
35
+ /**
36
+ * Serializer interface instance.
37
+ *
38
+ * @var Json
39
+ */
40
+ private $ serializer ;
41
+
32
42
/**
33
43
* @param DataObjectFactory $objectFactory
34
44
* @param CustomOptionFactory $customOptionFactory
45
+ * @param Json|null $serializer
35
46
*/
36
47
public function __construct (
37
48
DataObjectFactory $ objectFactory ,
38
- CustomOptionFactory $ customOptionFactory
49
+ CustomOptionFactory $ customOptionFactory ,
50
+ Json $ serializer = null
39
51
) {
40
52
$ this ->objectFactory = $ objectFactory ;
41
53
$ this ->customOptionFactory = $ customOptionFactory ;
54
+ $ this ->serializer = $ serializer ?: \Magento \Framework \App \ObjectManager::getInstance ()
55
+ ->get (\Magento \Framework \Serialize \Serializer \Json::class);
42
56
}
43
57
44
58
/**
@@ -88,7 +102,8 @@ public function convertToProductOption(DataObject $request)
88
102
if (!empty ($ options ) && is_array ($ options )) {
89
103
$ data = [];
90
104
foreach ($ options as $ optionId => $ optionValue ) {
91
- if (is_array ($ optionValue )) {
105
+
106
+ if (is_array ($ optionValue ) && !$ this ->isDateWithDateInternal ($ optionValue )) {
92
107
$ optionValue = $ this ->processFileOptionValue ($ optionValue );
93
108
$ optionValue = implode (', ' , $ optionValue );
94
109
}
@@ -126,6 +141,8 @@ private function processFileOptionValue(array $optionValue)
126
141
}
127
142
128
143
/**
144
+ * Get url builder
145
+ *
129
146
* @return \Magento\Catalog\Model\Product\Option\UrlBuilder
130
147
*
131
148
* @deprecated 101.0.0
@@ -138,4 +155,15 @@ private function getUrlBuilder()
138
155
}
139
156
return $ this ->urlBuilder ;
140
157
}
158
+
159
+ /**
160
+ * Returns date option value only with 'date_internal data
161
+ *
162
+ * @param array $optionValue
163
+ * @return bool
164
+ */
165
+ private function isDateWithDateInternal (array $ optionValue ): bool
166
+ {
167
+ return array_key_exists ('date_internal ' , $ optionValue ) && array_key_exists ('date ' , $ optionValue );
168
+ }
141
169
}
0 commit comments