/** * @inheritdoc */ public function delete(StockItemInterface $stockItem) { try { $this->resource->delete($stockItem); } catch (\Exception $exception) { throw new CouldNotDeleteException(__($exception->getMessage())); } return true; }
/** * @inheritdoc */ public function delete(StockItemInterface $stockItem) { try { $this->resource->delete($stockItem); $this->getStockRegistryStorage()->removeStockItem($stockItem->getProductId()); $this->getStockRegistryStorage()->removeStockStatus($stockItem->getProductId()); } catch (\Exception $exception) { throw new CouldNotDeleteException(__('Unable to remove Stock Item with id "%1"', $stockItem->getItemId()), $exception); } return true; }
/** * @expectedException \Magento\Framework\Exception\CouldNotSaveException */ public function testSaveException() { $productId = 1; $this->stockItemMock->expects($this->any())->method('getProductId')->willReturn($productId); $this->productMock->expects($this->once())->method('load')->with($productId)->willReturnSelf(); $this->productMock->expects($this->once())->method('getId')->willReturn($productId); $this->productMock->expects($this->once())->method('getTypeId')->willReturn('typeId'); $this->stockConfigurationMock->expects($this->once())->method('isQty')->with('typeId')->willReturn(false); $this->stockItemMock->expects($this->once())->method('setQty')->with(0)->willReturnSelf(); $this->stockItemMock->expects($this->once())->method('getWebsiteId')->willReturn(1); $this->stockItemMock->expects($this->once())->method('setWebsiteId')->with(1)->willReturnSelf(); $this->stockItemMock->expects($this->once())->method('getStockId')->willReturn(1); $this->stockItemMock->expects($this->once())->method('setStockId')->with(1)->willReturnSelf(); $this->stockItemResourceMock->expects($this->once())->method('save')->with($this->stockItemMock)->willThrowException(new \Exception()); $this->model->save($this->stockItemMock); }
/** * Retrieve CatalogInventory Stock Item Table Id field name * * @return string */ protected function _getInventoryItemIdField() { return $this->_itemResource->getIdFieldName(); }