/** * 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; }
/** * {@inheritdoc} * @SuppressWarnings(PHPMD.NPathComplexity) */ public function processOptions(CartItemInterface $cartItem) { if ($cartItem->getProductType() !== \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE) { return $cartItem; } $productOptions = []; $bundleOptions = $cartItem->getBuyRequest()->getBundleOption(); $bundleOptionsQty = $cartItem->getBuyRequest()->getBundleOptionQty(); foreach ($bundleOptions as $optionId => $optionSelections) { if (empty($optionSelections)) { continue; } $optionSelections = is_array($optionSelections) ? $optionSelections : [$optionSelections]; $optionQty = isset($bundleOptionsQty[$optionId]) ? $bundleOptionsQty[$optionId] : 1; /** @var \Magento\Bundle\Api\Data\BundleOptionInterface $productOption */ $productOption = $this->bundleOptionFactory->create(); $productOption->setOptionId($optionId); $productOption->setOptionSelections($optionSelections); $productOption->setOptionQty($optionQty); $productOptions[] = $productOption; } $extension = $this->productOptionExtensionFactory->create()->setBundleOptions($productOptions); if (!$cartItem->getProductOption()) { $cartItem->setProductOption($this->productOptionFactory->create()); } $cartItem->getProductOption()->setExtensionAttributes($extension); return $cartItem; }