/**
  * @inheritDoc
  */
 public function processOptions(CartItemInterface $cartItem)
 {
     $options = $this->getOptions($cartItem);
     if (!empty($options) && is_array($options)) {
         $this->updateOptionsValues($options);
         $productOption = $cartItem->getProductOption() ? $cartItem->getProductOption() : $this->productOptionFactory->create();
         /** @var  \Magento\Quote\Api\Data\ProductOptionExtensionInterface $extensibleAttribute */
         $extensibleAttribute = $productOption->getExtensionAttributes() ? $productOption->getExtensionAttributes() : $this->extensionFactory->create();
         $extensibleAttribute->setCustomOptions($options);
         $productOption->setExtensionAttributes($extensibleAttribute);
         $cartItem->setProductOption($productOption);
     }
     return $cartItem;
 }
 /**
  * Process cart item product options
  *
  * @param CartItemInterface $cartItem
  * @return CartItemInterface
  */
 public function processOptions(CartItemInterface $cartItem)
 {
     $downloadableLinkIds = [];
     $option = $cartItem->getOptionByCode('downloadable_link_ids');
     if (!empty($option)) {
         $downloadableLinkIds = explode(',', $option->getValue());
     }
     $downloadableOption = $this->downloadableOptionFactory->create();
     $this->dataObjectHelper->populateWithArray($downloadableOption, ['downloadable_links' => $downloadableLinkIds], 'Magento\\Downloadable\\Api\\Data\\DownloadableOptionInterface');
     $productOption = $cartItem->getProductOption() ? $cartItem->getProductOption() : $this->productOptionFactory->create();
     $extensibleAttribute = $productOption->getExtensionAttributes() ? $productOption->getExtensionAttributes() : $this->extensionFactory->create();
     $extensibleAttribute->setDownloadableOption($downloadableOption);
     $productOption->setExtensionAttributes($extensibleAttribute);
     $cartItem->setProductOption($productOption);
     return $cartItem;
 }
 public function testProcessCustomOptions()
 {
     $optionId = 23;
     $quoteItemOption = $this->getMockBuilder('Magento\\Quote\\Model\\Quote\\Item\\Option')->disableOriginalConstructor()->getMock();
     $this->cartItem->expects($this->atLeastOnce())->method('getOptionByCode')->with('info_buyRequest')->willReturn($quoteItemOption);
     $quoteItemOption->expects($this->once())->method('getValue')->willReturn('a:1:{s:7:"options";a:1:{i:' . $optionId . ';a:2:{i:0;s:1:"5";i:1;s:1:"6";}}} ');
     $this->customOptionFactory->expects($this->once())->method('create')->willReturn($this->customOption);
     $this->customOption->expects($this->once())->method('setOptionId')->with($optionId);
     $this->customOption->expects($this->once())->method('setOptionValue')->with('5,6');
     $this->cartItem->expects($this->atLeastOnce())->method('getProductOption')->willReturn(false);
     $this->productOptionFactory->expects($this->once())->method('create')->willReturn($this->productOption);
     $this->productOption->expects($this->once())->method('getExtensionAttributes')->willReturn(false);
     $this->extensionFactory->expects($this->once())->method('create')->willReturn($this->extensibleAttribute);
     $this->extensibleAttribute->expects($this->once())->method('setCustomOptions')->with([$optionId => $this->customOption]);
     $this->productOption->expects($this->once())->method('setExtensionAttributes')->with($this->extensibleAttribute);
     $this->cartItem->expects($this->once())->method('setProductOption')->with($this->productOption);
     $this->assertSame($this->cartItem, $this->processor->processOptions($this->cartItem));
 }
 /**
  * {@inheritdoc}
  */
 public function processOptions(CartItemInterface $cartItem)
 {
     $attributesOption = $cartItem->getProduct()->getCustomOption('attributes');
     $selectedConfigurableOptions = unserialize($attributesOption->getValue());
     if (is_array($selectedConfigurableOptions)) {
         $configurableOptions = [];
         foreach ($selectedConfigurableOptions as $optionId => $optionValue) {
             /** @var \Magento\ConfigurableProduct\Api\Data\ConfigurableItemOptionValueInterface $option */
             $option = $this->itemOptionValueFactory->create();
             $option->setOptionId($optionId);
             $option->setOptionValue($optionValue);
             $configurableOptions[] = $option;
         }
         $productOption = $cartItem->getProductOption() ? $cartItem->getProductOption() : $this->productOptionFactory->create();
         /** @var  \Magento\Quote\Api\Data\ProductOptionExtensionInterface $extensibleAttribute */
         $extensibleAttribute = $productOption->getExtensionAttributes() ? $productOption->getExtensionAttributes() : $this->extensionFactory->create();
         $extensibleAttribute->setConfigurableItemOptions($configurableOptions);
         $productOption->setExtensionAttributes($extensibleAttribute);
         $cartItem->setProductOption($productOption);
     }
     return $cartItem;
 }