/** * @return array */ public function getCartItems() { if (!isset(self::$quoteItemsData)) { self::$quoteItemsData = []; $displayPriceWithTax = $this->rejoinerHelper->getTrackPriceWithTax(); if ($quote = $this->getQuote()) { $categories = []; /** @var \Magento\Quote\Model\Quote $quote */ /** @var \Magento\Quote\Model\Quote\Item $item */ foreach ($quote->getAllItems() as $item) { $categories = array_merge($categories, $item->getProduct()->getCategoryIds()); } /** @var \Magento\Catalog\Model\ResourceModel\Category\Collection $categoryCollection */ $categoryCollection = $this->categoryCollectionFactory->create(); $categoriesArray = $categoryCollection->addAttributeToSelect('name')->addFieldToFilter('entity_id', ['in' => $categories])->load()->getItems(); $imageWidth = $this->rejoinerHelper->getImageWidth(); $imageHeight = $this->rejoinerHelper->getImageHeight(); foreach ($quote->getAllVisibleItems() as $item) { $product = $item->getProduct(); $productCategories = $this->rejoinerHelper->getProductCategories($product, $categoriesArray); $imageUrl = $this->imageHelper->init($product, 'category_page_grid')->resize($imageWidth, $imageHeight)->getUrl(); if ($displayPriceWithTax) { $productPrice = $item->getPriceInclTax(); $rowTotal = $item->getRowTotalInclTax(); } else { $productPrice = $item->getPrice(); $rowTotal = $item->getRowTotal(); } $newItem = ['name' => $item->getName(), 'image_url' => $imageUrl, 'price' => (string) $this->rejoinerHelper->convertPriceToCents($productPrice), 'product_id' => (string) $item->getSku(), 'item_qty' => (string) $item->getQty(), 'qty_price' => (string) $this->rejoinerHelper->convertPriceToCents($rowTotal), 'product_url' => (string) $product->getProductUrl(), 'category' => $productCategories]; self::$quoteItemsData[] = $newItem; } } } return self::$quoteItemsData; }