configurationPool = $configurationPool; $this->eventManager = $eventManager; $this->totalsItemFactory = $totalsItemFactory; $this->dataObjectHelper = $dataObjectHelper; $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance() ->get(\Magento\Framework\Serialize\Serializer\Json::class); } /** * Converts a specified rate model to a shipping method data object. * * @param \Magento\Quote\Model\Quote\Item $item * @return array * @throws \Exception */ public function modelToDataObject($item) { $this->eventManager->dispatch('items_additional_data', ['item' => $item]); $items = $item->toArray(); $items['options'] = $this->getFormattedOptionValue($item); unset($items[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]); $itemsData = $this->totalsItemFactory->create(); $this->dataObjectHelper->populateWithArray( $itemsData, $items, \Magento\Quote\Api\Data\TotalsItemInterface::class ); return $itemsData; } /** * Retrieve formatted item options view * * @param \Magento\Quote\Api\Data\CartItemInterface $item * @return string */ private function getFormattedOptionValue($item) { $optionsData = []; /* @var $helper \Magento\Catalog\Helper\Product\Configuration */ $helper = $this->configurationPool->getByProductType('default'); $options = $this->configurationPool->getByProductType($item->getProductType())->getOptions($item); foreach ($options as $index => $optionValue) { $params = [ 'max_length' => 55, 'cut_replacer' => ' ...' ]; $option = $helper->getFormattedOptionValue($optionValue, $params); $optionsData[$index] = $option; $optionsData[$index]['label'] = $optionValue['label']; } return $this->serializer->serialize($optionsData); } }