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 = [];
@@ -82,13 +84,17 @@ public function convertToBuyRequest(CartItemInterface $cartItem)
82
84
*/
83
85
public function processOptions (CartItemInterface $ cartItem )
84
86
{
85
- $ attributesOption = $ cartItem ->getProduct ()->getCustomOption ('attributes ' );
87
+ $ attributesOption = $ cartItem ->getProduct ()
88
+ ->getCustomOption ('attributes ' );
89
+ if (!$ attributesOption ) {
90
+ return $ cartItem ;
91
+ }
86
92
$ selectedConfigurableOptions = $ this ->serializer ->unserialize ($ attributesOption ->getValue ());
87
93
88
94
if (is_array ($ selectedConfigurableOptions )) {
89
95
$ configurableOptions = [];
90
96
foreach ($ selectedConfigurableOptions as $ optionId => $ optionValue ) {
91
- /** @var \Magento\ConfigurableProduct\Api\Data\ ConfigurableItemOptionValueInterface $option */
97
+ /** @var ConfigurableItemOptionValueInterface $option */
92
98
$ option = $ this ->itemOptionValueFactory ->create ();
93
99
$ option ->setOptionId ($ optionId );
94
100
$ option ->setOptionValue ($ optionValue );
@@ -99,15 +105,16 @@ public function processOptions(CartItemInterface $cartItem)
99
105
? $ cartItem ->getProductOption ()
100
106
: $ this ->productOptionFactory ->create ();
101
107
102
- /** @var \Magento\Quote\Api\Data\ ProductOptionExtensionInterface $extensibleAttribute */
103
- $ extensibleAttribute = $ productOption ->getExtensionAttributes ()
108
+ /** @var ProductOptionExtensionInterface $extensibleAttribute */
109
+ $ extensibleAttribute = $ productOption ->getExtensionAttributes ()
104
110
? $ productOption ->getExtensionAttributes ()
105
111
: $ this ->extensionFactory ->create ();
106
112
107
113
$ extensibleAttribute ->setConfigurableItemOptions ($ configurableOptions );
108
114
$ productOption ->setExtensionAttributes ($ extensibleAttribute );
109
115
$ cartItem ->setProductOption ($ productOption );
110
116
}
117
+
111
118
return $ cartItem ;
112
119
}
113
120
}
0 commit comments