5
5
*/
6
6
namespace Magento \ConfigurableProduct \Model \Quote \Item ;
7
7
8
+ use Magento \ConfigurableProduct \Api \Data \ConfigurableItemOptionValueInterface ;
9
+ use Magento \Quote \Api \Data \ProductOptionExtensionInterface ;
8
10
use Magento \Quote \Model \Quote \Item \CartItemProcessorInterface ;
9
11
use Magento \Quote \Api \Data \CartItemInterface ;
10
12
use Magento \Framework \Serialize \Serializer \Json ;
@@ -64,7 +66,7 @@ public function __construct(
64
66
public function convertToBuyRequest (CartItemInterface $ cartItem )
65
67
{
66
68
if ($ cartItem ->getProductOption () && $ cartItem ->getProductOption ()->getExtensionAttributes ()) {
67
- /** @var \Magento\ConfigurableProduct\Api\Data\ ConfigurableItemOptionValueInterface $options */
69
+ /** @var ConfigurableItemOptionValueInterface $options */
68
70
$ options = $ cartItem ->getProductOption ()->getExtensionAttributes ()->getConfigurableItemOptions ();
69
71
if (is_array ($ options )) {
70
72
$ requestData = [];
@@ -84,33 +86,35 @@ public function processOptions(CartItemInterface $cartItem)
84
86
{
85
87
$ attributesOption = $ cartItem ->getProduct ()
86
88
->getCustomOption ('attributes ' );
87
- if ($ attributesOption ) {
88
- $ selectedConfigurableOptions = $ this ->serializer ->unserialize ($ attributesOption ->getValue ());
89
+ if (!$ attributesOption ) {
90
+ return $ cartItem ;
91
+ }
92
+ $ selectedConfigurableOptions = $ this ->serializer ->unserialize ($ attributesOption ->getValue ());
89
93
90
- if (is_array ($ selectedConfigurableOptions )) {
91
- $ configurableOptions = [];
92
- foreach ($ selectedConfigurableOptions as $ optionId => $ optionValue ) {
93
- /** @var \Magento\ConfigurableProduct\Api\Data\ ConfigurableItemOptionValueInterface $option */
94
- $ option = $ this ->itemOptionValueFactory ->create ();
95
- $ option ->setOptionId ($ optionId );
96
- $ option ->setOptionValue ($ optionValue );
97
- $ configurableOptions [] = $ option ;
98
- }
94
+ if (is_array ($ selectedConfigurableOptions )) {
95
+ $ configurableOptions = [];
96
+ foreach ($ selectedConfigurableOptions as $ optionId => $ optionValue ) {
97
+ /** @var ConfigurableItemOptionValueInterface $option */
98
+ $ option = $ this ->itemOptionValueFactory ->create ();
99
+ $ option ->setOptionId ($ optionId );
100
+ $ option ->setOptionValue ($ optionValue );
101
+ $ configurableOptions [] = $ option ;
102
+ }
99
103
100
- $ productOption = $ cartItem ->getProductOption ()
101
- ? $ cartItem ->getProductOption ()
102
- : $ this ->productOptionFactory ->create ();
104
+ $ productOption = $ cartItem ->getProductOption ()
105
+ ? $ cartItem ->getProductOption ()
106
+ : $ this ->productOptionFactory ->create ();
103
107
104
- /** @var \Magento\Quote\Api\Data\ ProductOptionExtensionInterface $extensibleAttribute */
105
- $ extensibleAttribute = $ productOption ->getExtensionAttributes ()
106
- ? $ productOption ->getExtensionAttributes ()
107
- : $ this ->extensionFactory ->create ();
108
+ /** @var ProductOptionExtensionInterface $extensibleAttribute */
109
+ $ extensibleAttribute = $ productOption ->getExtensionAttributes ()
110
+ ? $ productOption ->getExtensionAttributes ()
111
+ : $ this ->extensionFactory ->create ();
108
112
109
- $ extensibleAttribute ->setConfigurableItemOptions ($ configurableOptions );
110
- $ productOption ->setExtensionAttributes ($ extensibleAttribute );
111
- $ cartItem ->setProductOption ($ productOption );
112
- }
113
+ $ extensibleAttribute ->setConfigurableItemOptions ($ configurableOptions );
114
+ $ productOption ->setExtensionAttributes ($ extensibleAttribute );
115
+ $ cartItem ->setProductOption ($ productOption );
113
116
}
117
+
114
118
return $ cartItem ;
115
119
}
116
120
}
0 commit comments