Example #1
0
 /**
  * {@inheritdoc}
  */
 public function addItem($cartId, \Magento\Checkout\Service\V1\Data\Cart\Item $data)
 {
     $qty = $data->getQty();
     if (!is_numeric($qty) || $qty <= 0) {
         throw InputException::invalidFieldValue('qty', $qty);
     }
     /** @var \Magento\Sales\Model\Quote $quote */
     $quote = $this->quoteRepository->get($cartId);
     $product = $this->productLoader->load($data->getSku());
     try {
         $quote->addProduct($product, $qty);
         $quote->collectTotals()->save();
     } catch (\Exception $e) {
         throw new CouldNotSaveException('Could not add item to quote');
     }
     return $quote->getItemByProduct($product)->getId();
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function getLinkedProducts($productSku, $type)
 {
     $output = [];
     $product = $this->productLoader->load($productSku);
     $collection = $this->entityCollectionProvider->getCollection($product, $type);
     foreach ($collection as $item) {
         $output[] = $this->productEntityBuilder->populateWithArray($item)->create();
     }
     return $output;
 }
Example #3
0
 /**
  * @param string $productSku
  * @param \Magento\CatalogInventory\Service\V1\Data\StockItemDetails $stockItemDetailsDo
  * @return string
  * @throws \Magento\Framework\Exception\NoSuchEntityException
  */
 public function saveStockItemBySku($productSku, Data\StockItemDetails $stockItemDetailsDo)
 {
     $product = $this->productLoader->load($productSku);
     if (!$product->getId()) {
         throw new NoSuchEntityException("Product with SKU \"{$productSku}\" does not exist");
     }
     $stockItem = $this->stockItemRegistry->retrieve($product->getId());
     $stockItemDo = $this->stockItemBuilder->populateWithArray($stockItem->getData())->create();
     $dataToSave = $this->stockItemBuilder->mergeDataObjectWithArray($stockItemDo, $stockItemDetailsDo->__toArray())->__toArray();
     return $stockItem->setData($dataToSave)->save()->getId();
 }
Example #4
0
 /**
  * {@inheritdoc}
  */
 public function delete($productSku, $entryId)
 {
     $product = $this->productLoader->load($productSku);
     /** @var $productMediaGallery \Magento\Catalog\Model\Product\Attribute\Backend\Media */
     $productMediaGallery = $this->getGalleryAttributeBackend($product);
     $filePath = $this->entryResolver->getEntryFilePathById($product, $entryId);
     if (is_null($filePath)) {
         throw new NoSuchEntityException('There is no image with provided ID.');
     }
     $productMediaGallery->removeImage($product, $filePath);
     $product->save();
     return true;
 }
Example #5
0
 /**
  * {inheritdoc}
  */
 public function getProductStockStatusBySku($sku)
 {
     $product = $this->productLoader->load($sku);
     $productId = $product->getId();
     if (!$productId) {
         throw new NoSuchEntityException("Product with SKU \"{$sku}\" does not exist");
     }
     $data = $this->stockStatus->getProductStockStatus([$productId], $this->scopeResolver->getScope()->getId());
     $stockStatus = (bool) $data[$productId];
     $result = [Data\StockStatus::STOCK_STATUS => $stockStatus, Data\StockStatus::STOCK_QTY => $this->stockItemService->getStockQty($productId)];
     $this->stockStatusBuilder->populateWithArray($result);
     return $this->stockStatusBuilder->create();
 }
Example #6
0
 /**
  * {@inheritdoc}
  */
 public function remove($productSku, $linkedProductSku, $type)
 {
     $linkedProduct = $this->productLoader->load($linkedProductSku);
     $product = $this->productLoader->load($productSku);
     $links = $this->entityCollectionProvider->getCollection($product, $type);
     if (!isset($links[$linkedProduct->getId()])) {
         throw new NoSuchEntityException(sprintf('Product with SKU %s is not linked to product with SKU %s', $linkedProductSku, $productSku));
     }
     //Remove product from the linked product list
     unset($links[$linkedProduct->getId()]);
     $this->saveLinks($product, [$type => $links]);
     return true;
 }
Example #7
0
 /**
  * {@inheritdoc}
  */
 public function get($id)
 {
     return $this->converter->createProductDataFromModel($this->productLoader->load($id));
 }
 /**
  * {@inheritdoc}
  */
 public function get($id)
 {
     $productBuilder = $this->converter->createProductBuilderFromModel($this->productLoader->load($id));
     $this->productLoadProcessor->load($id, $productBuilder);
     return $productBuilder->create();
 }