55 */
66namespace Magento \Catalog \Model ;
77
8- use Magento \Catalog \Api \Data \ProductOptionExtensionFactory ;
98use Magento \Catalog \Api \Data \ProductOptionInterface ;
109use Magento \Catalog \Model \CustomOptions \CustomOption ;
1110use Magento \Catalog \Model \CustomOptions \CustomOptionFactory ;
1211use Magento \Framework \DataObject ;
1312use Magento \Framework \DataObject \Factory as DataObjectFactory ;
13+ use Magento \Framework \Serialize \Serializer \Json ;
1414
15+ /**
16+ * Processor ofr product options
17+ */
1518class ProductOptionProcessor implements ProductOptionProcessorInterface
1619{
1720 /**
@@ -29,16 +32,27 @@ class ProductOptionProcessor implements ProductOptionProcessorInterface
2932 */
3033 private $ urlBuilder ;
3134
35+ /**
36+ * Serializer interface instance.
37+ *
38+ * @var Json
39+ */
40+ private $ serializer ;
41+
3242 /**
3343 * @param DataObjectFactory $objectFactory
3444 * @param CustomOptionFactory $customOptionFactory
45+ * @param Json|null $serializer
3546 */
3647 public function __construct (
3748 DataObjectFactory $ objectFactory ,
38- CustomOptionFactory $ customOptionFactory
49+ CustomOptionFactory $ customOptionFactory ,
50+ Json $ serializer = null
3951 ) {
4052 $ this ->objectFactory = $ objectFactory ;
4153 $ this ->customOptionFactory = $ customOptionFactory ;
54+ $ this ->serializer = $ serializer ?: \Magento \Framework \App \ObjectManager::getInstance ()
55+ ->get (\Magento \Framework \Serialize \Serializer \Json::class);
4256 }
4357
4458 /**
@@ -88,7 +102,8 @@ public function convertToProductOption(DataObject $request)
88102 if (!empty ($ options ) && is_array ($ options )) {
89103 $ data = [];
90104 foreach ($ options as $ optionId => $ optionValue ) {
91- if (is_array ($ optionValue )) {
105+
106+ if (is_array ($ optionValue ) && !$ this ->isDateWithDateInternal ($ optionValue )) {
92107 $ optionValue = $ this ->processFileOptionValue ($ optionValue );
93108 $ optionValue = implode (', ' , $ optionValue );
94109 }
@@ -126,6 +141,8 @@ private function processFileOptionValue(array $optionValue)
126141 }
127142
128143 /**
144+ * Get url builder
145+ *
129146 * @return \Magento\Catalog\Model\Product\Option\UrlBuilder
130147 *
131148 * @deprecated 101.0.0
@@ -138,4 +155,15 @@ private function getUrlBuilder()
138155 }
139156 return $ this ->urlBuilder ;
140157 }
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+ }
141169}
0 commit comments