Exemple #1
0
 /**
  * {@inheritdoc}
  */
 public function getImages($cartId)
 {
     $itemData = [];
     /** @see code/Magento/Catalog/Helper/Product.php */
     $items = $this->itemRepository->getList($cartId);
     /** @var \Magento\Quote\Model\Quote\Item $cartItem */
     foreach ($items as $cartItem) {
         $allData = $this->itemPool->getItemData($cartItem);
         $itemData[$cartItem->getItemId()] = $allData['product_image'];
     }
     return $itemData;
 }
 /**
  * @return void
  */
 public function testDeleteById()
 {
     $cartId = 11;
     $itemId = 5;
     $this->quoteRepositoryMock->expects($this->once())->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock));
     $this->quoteMock->expects($this->once())->method('getItemById')->with($itemId)->will($this->returnValue($this->quoteItemMock));
     $this->quoteMock->expects($this->once())->method('removeItem');
     $this->quoteMock->expects($this->once())->method('collectTotals')->will($this->returnValue($this->quoteMock));
     $this->quoteRepositoryMock->expects($this->once())->method('save')->with($this->quoteMock);
     $this->assertTrue($this->repository->deleteById($cartId, $itemId));
 }
 /**
  * Retrieve quote item data
  *
  * @return array
  */
 private function getQuoteItemData()
 {
     $quoteItemData = [];
     $quoteId = $this->checkoutSession->getQuote()->getId();
     if ($quoteId) {
         $quoteItems = $this->quoteItemRepository->getList($quoteId);
         foreach ($quoteItems as $index => $quoteItem) {
             $quoteItemData[$index] = $quoteItem->toArray();
             $quoteItemData[$index]['options'] = $this->getFormattedOptionValue($quoteItem);
             $quoteItemData[$index]['thumbnail'] = $this->imageHelper->init($quoteItem->getProduct(), 'product_thumbnail_image')->getUrl();
         }
     }
     return $quoteItemData;
 }
 /**
  * Retrieve quote item data
  *
  * @return array
  */
 private function getQuoteItemData()
 {
     $quoteItemData = [];
     $quoteId = $this->checkoutSession->getQuote()->getId();
     if ($quoteId) {
         $quoteItems = $this->quoteItemRepository->getList($quoteId);
         foreach ($quoteItems as $index => $quoteItem) {
             $quoteItemData[$index] = $quoteItem->toArray();
             $quoteItemData[$index]['options'] = $this->getFormattedOptionValue($quoteItem);
             $thumbnailSize = $this->viewConfig->getViewConfig()->getVarValue('Magento_Catalog', 'product_thumbnail_image_size');
             $quoteItemData[$index]['thumbnail'] = (string) $this->imageHelper->init($quoteItem->getProduct(), 'thumbnail')->resize($thumbnailSize);
         }
     }
     return $quoteItemData;
 }
 /**
  * Get cart item
  *
  * @param int $cartId
  * @param int $itemId
  * @return CartItemInterface|null
  * @throws NoSuchEntityException
  */
 protected function getQuoteItem($cartId, $itemId)
 {
     $quoteItem = null;
     /** @var CartItemInterface[] $quoteItems */
     $quoteItems = $this->quoteItemRepository->getList($cartId);
     foreach ($quoteItems as $item) {
         if ($item->getItemId() == $itemId) {
             $quoteItem = $item;
             break;
         }
     }
     if (!$quoteItem) {
         throw new NoSuchEntityException(__('There is no item with provided id in the cart'));
     }
     return $quoteItem;
 }
 /**
  * {@inheritdoc}
  */
 public function deleteById($cartId, $itemId)
 {
     /** @var $quoteIdMask QuoteIdMask */
     $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
     return $this->repository->deleteById($quoteIdMask->getQuoteId(), $itemId);
 }