public function testDelete() { $productId = 1; $this->stockStatusMock->expects($this->atLeastOnce())->method('getProductId')->willReturn($productId); $this->stockRegistryStorage->expects($this->once())->method('removeStockStatus')->with($productId); $this->stockStatusResourceMock->expects($this->once())->method('delete')->with($this->stockStatusMock)->willReturnSelf(); $this->assertTrue($this->model->delete($this->stockStatusMock)); }
/** * Detect current stock and get appropriate stock item. * * @param \Magento\CatalogInventory\Model\StockRegistryProvider $subject * @param \Closure $proceed * @param int $productId * @param int $scopeId * @return \Magento\CatalogInventory\Api\Data\StockItemInterface */ public function aroundGetStockItem(\Magento\CatalogInventory\Model\StockRegistryProvider $subject, \Closure $proceed, $productId, $scopeId) { $result = $this->_storageStockRegistry->getStockItem($productId, $scopeId); if (null === $result) { $criteria = $this->_factoryStockItemCrit->create(); $criteria->setProductsFilter($productId); $stockId = $this->_toolStockManager->getCurrentStockId(); $criteria->setStockFilter($stockId); $collection = $this->_repoStockItem->getList($criteria); $result = current($collection->getItems()); if ($result && $result->getItemId()) { $this->_storageStockRegistry->setStockItem($productId, $scopeId, $result); } else { $result = $this->_factoryStockItem->create(); } } return $result; }
public function testSaveWithoutProductId() { $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(null); $this->stockRegistryStorage->expects($this->never())->method('removeStockItem'); $this->stockRegistryStorage->expects($this->never())->method('removeStockStatus'); $this->assertEquals($this->stockItemMock, $this->model->save($this->stockItemMock)); }
/** * @param StockInterface $stock * @return bool|true * @throws CouldNotDeleteException */ public function delete(StockInterface $stock) { try { $this->resource->delete($stock); $this->stockRegistryStorage->removeStock(); } catch (\Exception $exception) { throw new CouldNotDeleteException(__('Unable to remove Stock with id "%1"', $stock->getStockId()), $exception); } return true; }
/** * @param StockStatusInterface $stockStatus * @return bool|true * @throws CouldNotDeleteException */ public function delete(StockStatusInterface $stockStatus) { try { $this->resource->delete($stockStatus); $this->stockRegistryStorage->removeStockStatus($stockStatus->getProductId()); } catch (\Exception $exception) { throw new CouldNotDeleteException(__('Unable to remove Stock Status for product %1', $stockStatus->getProductId()), $exception); } return true; }
/** * @param int $productId * @param int $scopeId * @return \Magento\CatalogInventory\Api\Data\StockStatusInterface */ public function getStockStatus($productId, $scopeId) { $stockStatus = $this->stockRegistryStorage->getStockStatus($productId, $scopeId); if (null === $stockStatus) { $criteria = $this->stockStatusCriteriaFactory->create(); $criteria->setProductsFilter($productId); $criteria->setScopeFilter($scopeId); $collection = $this->stockStatusRepository->getList($criteria); $stockStatus = current($collection->getItems()); if ($stockStatus && $stockStatus->getProductId()) { $this->stockRegistryStorage->setStockStatus($productId, $scopeId, $stockStatus); } else { $stockStatus = $this->stockStatusFactory->create(); } } return $stockStatus; }
public function testDelete() { $this->stockRegistryStorage->expects($this->once())->method('removeStock'); $this->stockResourceMock->expects($this->once())->method('delete')->with($this->stockMock)->willReturnSelf(); $this->assertTrue($this->model->delete($this->stockMock)); }