@@ -679,32 +679,9 @@ public function initFromOrderItem(\Magento\Sales\Model\Order\Item $orderItem, $q
679679 $ buyRequest ->setQty ($ qty );
680680 }
681681 $ productOptions = $ orderItem ->getProductOptions ();
682- if ($ productOptions !== null && !empty ($ productOptions ['options ' ])) {
683- $ formattedOptions = [];
684- foreach ($ productOptions ['options ' ] as $ option ) {
685- if (in_array ($ option ['option_type ' ], ['date ' , 'date_time ' , 'time ' , 'file ' ])) {
686- $ product ->setSkipCheckRequiredOption (false );
687- if ($ option ['option_type ' ] === 'file ' ) {
688- try {
689- $ formattedOptions [$ option ['option_id ' ]] =
690- $ this ->serializer ->unserialize ($ option ['option_value ' ]);
691- continue ;
692- } catch (\InvalidArgumentException $ exception ) {
693- //log the exception as warning
694- $ this ->_logger ->warning ($ exception );
695- }
696- }
697- $ formattedOptions [$ option ['option_id ' ]] =
698- $ buyRequest ->getDataByKey ('options ' )[$ option ['option_id ' ]];
699- continue ;
700- }
701682
702- $ formattedOptions [$ option ['option_id ' ]] = $ option ['option_value ' ];
703- }
704- if (!empty ($ formattedOptions )) {
705- $ buyRequest ->setData ('options ' , $ formattedOptions );
706- }
707- }
683+ $ this ->formattedOptions ($ product , $ buyRequest , $ productOptions );
684+
708685 $ item = $ this ->getQuote ()->addProduct ($ product , $ buyRequest );
709686 if (is_string ($ item )) {
710687 return $ item ;
@@ -2181,4 +2158,42 @@ private function isAddressesAreEqual(Order $order)
21812158
21822159 return $ shippingData == $ billingData ;
21832160 }
2161+
2162+ /**
2163+ * Set $buyRequest with formatted product options.
2164+ *
2165+ * @param \Magento\Catalog\Model\Product $product
2166+ * @param $buyRequest
2167+ * @param $productOptions
2168+ *
2169+ */
2170+ private function formattedOptions (\Magento \Catalog \Model \Product $ product , $ buyRequest , $ productOptions ): void
2171+ {
2172+ if ($ productOptions !== null && !empty ($ productOptions ['options ' ])) {
2173+ $ formattedOptions = [];
2174+ foreach ($ productOptions ['options ' ] as $ option ) {
2175+ if (in_array ($ option ['option_type ' ], ['date ' , 'date_time ' , 'time ' , 'file ' ])) {
2176+ $ product ->setSkipCheckRequiredOption (false );
2177+ if ($ option ['option_type ' ] === 'file ' ) {
2178+ try {
2179+ $ formattedOptions [$ option ['option_id ' ]] =
2180+ $ this ->serializer ->unserialize ($ option ['option_value ' ]);
2181+ continue ;
2182+ } catch (\InvalidArgumentException $ exception ) {
2183+ //log the exception as warning
2184+ $ this ->_logger ->warning ($ exception );
2185+ }
2186+ }
2187+ $ formattedOptions [$ option ['option_id ' ]] =
2188+ $ buyRequest ->getDataByKey ('options ' )[$ option ['option_id ' ]];
2189+ continue ;
2190+ }
2191+
2192+ $ formattedOptions [$ option ['option_id ' ]] = $ option ['option_value ' ];
2193+ }
2194+ if (!empty ($ formattedOptions )) {
2195+ $ buyRequest ->setData ('options ' , $ formattedOptions );
2196+ }
2197+ }
2198+ }
21842199}
0 commit comments