55 */
66namespace Magento \ConfigurableProduct \Model \Quote \Item ;
77
8+ use Magento \ConfigurableProduct \Api \Data \ConfigurableItemOptionValueInterface ;
9+ use Magento \Quote \Api \Data \ProductOptionExtensionInterface ;
810use Magento \Quote \Model \Quote \Item \CartItemProcessorInterface ;
911use Magento \Quote \Api \Data \CartItemInterface ;
1012use Magento \Framework \Serialize \Serializer \Json ;
@@ -64,7 +66,7 @@ public function __construct(
6466 public function convertToBuyRequest (CartItemInterface $ cartItem )
6567 {
6668 if ($ cartItem ->getProductOption () && $ cartItem ->getProductOption ()->getExtensionAttributes ()) {
67- /** @var \Magento\ConfigurableProduct\Api\Data\ ConfigurableItemOptionValueInterface $options */
69+ /** @var ConfigurableItemOptionValueInterface $options */
6870 $ options = $ cartItem ->getProductOption ()->getExtensionAttributes ()->getConfigurableItemOptions ();
6971 if (is_array ($ options )) {
7072 $ requestData = [];
@@ -84,33 +86,35 @@ public function processOptions(CartItemInterface $cartItem)
8486 {
8587 $ attributesOption = $ cartItem ->getProduct ()
8688 ->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 ());
8993
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+ }
99103
100- $ productOption = $ cartItem ->getProductOption ()
101- ? $ cartItem ->getProductOption ()
102- : $ this ->productOptionFactory ->create ();
104+ $ productOption = $ cartItem ->getProductOption ()
105+ ? $ cartItem ->getProductOption ()
106+ : $ this ->productOptionFactory ->create ();
103107
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 ();
108112
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 );
113116 }
117+
114118 return $ cartItem ;
115119 }
116120}
0 commit comments