示例#1
0
 /**
  * @param int $productId
  * @return \Magento\CatalogInventory\Model\Stock\Item
  */
 public function retrieve($productId)
 {
     if (empty($this->stockItemRegistry[$productId])) {
         /** @var \Magento\CatalogInventory\Model\Stock\Item $stockItem */
         $stockItem = $this->stockItemFactory->create();
         $this->stockItemResource->loadByProductId($stockItem, $productId);
         $this->stockItemRegistry[$productId] = $stockItem;
     }
     return $this->stockItemRegistry[$productId];
 }
示例#2
0
 public function testSave()
 {
     $this->item->setData('key', 'value');
     $this->eventManager->expects($this->at(0))->method('dispatch')->with('model_save_before', ['object' => $this->item]);
     $this->eventManager->expects($this->at(1))->method('dispatch')->with('cataloginventory_stock_item_save_before', ['data_object' => $this->item, 'item' => $this->item]);
     $this->resource->expects($this->once())->method('addCommitCallback')->will($this->returnValue($this->resource));
     $this->assertEquals($this->item, $this->item->save());
 }
 /**
  * @inheritdoc
  */
 public function delete(StockItemInterface $stockItem)
 {
     try {
         $this->resource->delete($stockItem);
     } catch (\Exception $exception) {
         throw new CouldNotDeleteException(__($exception->getMessage()));
     }
     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);
 }
示例#5
0
 /**
  * Retrieve CatalogInventory Stock Item Table Id field name
  *
  * @return string
  */
 protected function _getInventoryItemIdField()
 {
     return $this->_itemResource->getIdFieldName();
 }