/** * @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; }
/** * {@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; }