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 = [];
@@ -82,13 +84,17 @@ public function convertToBuyRequest(CartItemInterface $cartItem)
8284 */
8385 public function processOptions (CartItemInterface $ cartItem )
8486 {
85- $ attributesOption = $ cartItem ->getProduct ()->getCustomOption ('attributes ' );
87+ $ attributesOption = $ cartItem ->getProduct ()
88+ ->getCustomOption ('attributes ' );
89+ if (!$ attributesOption ) {
90+ return $ cartItem ;
91+ }
8692 $ selectedConfigurableOptions = $ this ->serializer ->unserialize ($ attributesOption ->getValue ());
8793
8894 if (is_array ($ selectedConfigurableOptions )) {
8995 $ configurableOptions = [];
9096 foreach ($ selectedConfigurableOptions as $ optionId => $ optionValue ) {
91- /** @var \Magento\ConfigurableProduct\Api\Data\ ConfigurableItemOptionValueInterface $option */
97+ /** @var ConfigurableItemOptionValueInterface $option */
9298 $ option = $ this ->itemOptionValueFactory ->create ();
9399 $ option ->setOptionId ($ optionId );
94100 $ option ->setOptionValue ($ optionValue );
@@ -99,15 +105,16 @@ public function processOptions(CartItemInterface $cartItem)
99105 ? $ cartItem ->getProductOption ()
100106 : $ this ->productOptionFactory ->create ();
101107
102- /** @var \Magento\Quote\Api\Data\ ProductOptionExtensionInterface $extensibleAttribute */
103- $ extensibleAttribute = $ productOption ->getExtensionAttributes ()
108+ /** @var ProductOptionExtensionInterface $extensibleAttribute */
109+ $ extensibleAttribute = $ productOption ->getExtensionAttributes ()
104110 ? $ productOption ->getExtensionAttributes ()
105111 : $ this ->extensionFactory ->create ();
106112
107113 $ extensibleAttribute ->setConfigurableItemOptions ($ configurableOptions );
108114 $ productOption ->setExtensionAttributes ($ extensibleAttribute );
109115 $ cartItem ->setProductOption ($ productOption );
110116 }
117+
111118 return $ cartItem ;
112119 }
113120}
0 commit comments