objectFactory = $objectFactory; $this->dataObjectHelper = $dataObjectHelper; $this->downloadableOptionFactory = $downloadableOptionFactory; $this->productOptionFactory = $productOptionFactory; $this->extensionFactory = $extensionFactory; } /** * {@inheritdoc} */ public function convertToBuyRequest(CartItemInterface $cartItem) { if ($cartItem->getProductOption() && $cartItem->getProductOption()->getExtensionAttributes() && $cartItem->getProductOption()->getExtensionAttributes()->getDownloadableOption() ) { $downloadableLinks = $cartItem->getProductOption()->getExtensionAttributes()->getDownloadableOption() ->getDownloadableLinks(); if (!empty($downloadableLinks)) { return $this->objectFactory->create( ['links' => $downloadableLinks] ); } } return null; } /** * 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::class ); $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; } }