checkoutSession = $checkoutSession; $this->quoteItem = $quoteItem; $this->salespersonRepository = $salespersonRepository; $this->labRepository = $labRepository; } protected function addAdditionalItemsData(Item $item) { $data = []; $quoteItem = $this->quoteItem->create()->load($item->getItemId()); $data['sku'] = $quoteItem->getSku(); if ($quoteItem->getSalesPersonId()) { $salesperson = $this->salespersonRepository->get($quoteItem->getSalesPersonId()); $data['salesperson_name'] = $salesperson->getName(); } if ($quoteItem->getLabCode()) { $lab = $this->labRepository->getByLabCode($quoteItem->getLabCode()); $data['booking_account'] = $lab->getBookingAccount(); } $data['cd_code'] = $quoteItem->getCd(); $data['quote_code'] = $quoteItem->getData('quote'); $data['pi_sap_id'] = $quoteItem->getData('pi_sap_id'); return $data; } protected function getTotalsData() { /** @var \Magento\Quote\Api\Data\TotalsInterface $totals */ $totals = $this->cartTotalRepository->get($this->checkoutSession->getQuote()->getId()); $items = []; /** @var Item $item */ foreach ($totals->getItems() as $item) { $items[] = array_merge($item->__toArray(), $this->addAdditionalItemsData($item)); } $totalSegmentsData = []; /** @var \Magento\Quote\Model\Cart\TotalSegment $totalSegment */ foreach ($totals->getTotalSegments() as $totalSegment) { $totalSegmentArray = $totalSegment->toArray(); if (is_object($totalSegment->getExtensionAttributes())) { $totalSegmentArray['extension_attributes'] = $totalSegment->getExtensionAttributes()->__toArray(); } $totalSegmentsData[] = $totalSegmentArray; } $totals->setItems($items); $totals->setTotalSegments($totalSegmentsData); $totalsArray = $totals->toArray(); if (is_object($totals->getExtensionAttributes())) { $totalsArray['extension_attributes'] = $totals->getExtensionAttributes()->__toArray(); } return $totalsArray; } }