StockRepositoryInterface.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\InventoryApi\Api;
  8. /**
  9. * In Magento 2 Repository considered as an implementation of Facade pattern which provides a simplified interface
  10. * to a larger body of code responsible for Domain Entity management
  11. *
  12. * The main intention is to make API more readable and reduce dependencies of business logic code on the inner workings
  13. * of a module, since most code uses the facade, thus allowing more flexibility in developing the system
  14. *
  15. * Along with this such approach helps to segregate two responsibilities:
  16. * 1. Repository now could be considered as an API - Interface for usage (calling) in the business logic
  17. * 2. Separate class-commands to which Repository proxies initial call (like, Get Save GetList Delete) could be
  18. * considered as SPI - Interfaces that you should extend and implement to customize current behaviour
  19. *
  20. * Used fully qualified namespaces in annotations for proper work of WebApi request parser
  21. *
  22. * @api
  23. */
  24. interface StockRepositoryInterface
  25. {
  26. /**
  27. * Save Stock data
  28. *
  29. * @param \Magento\InventoryApi\Api\Data\StockInterface $stock
  30. * @return int
  31. * @throws \Magento\Framework\Validation\ValidationException
  32. * @throws \Magento\Framework\Exception\CouldNotSaveException
  33. */
  34. public function save(\Magento\InventoryApi\Api\Data\StockInterface $stock): int;
  35. /**
  36. * Get Stock data by given stockId. If you want to create plugin on get method, also you need to create separate
  37. * plugin on getList method, because entity loading way is different for these methods
  38. *
  39. * @param int $stockId
  40. * @return \Magento\InventoryApi\Api\Data\StockInterface
  41. * @throws \Magento\Framework\Exception\NoSuchEntityException
  42. */
  43. public function get(int $stockId): \Magento\InventoryApi\Api\Data\StockInterface;
  44. /**
  45. * Find Stocks by given SearchCriteria
  46. * SearchCriteria is not required because load all stocks is useful case
  47. *
  48. * @param \Magento\Framework\Api\SearchCriteriaInterface|null $searchCriteria
  49. * @return \Magento\InventoryApi\Api\Data\StockSearchResultsInterface
  50. */
  51. public function getList(
  52. \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria = null
  53. ): \Magento\InventoryApi\Api\Data\StockSearchResultsInterface;
  54. /**
  55. * Delete the Stock data by stockId. If stock is not found do nothing
  56. *
  57. * @param int $stockId
  58. * @return void
  59. * @throws \Magento\Framework\Exception\NoSuchEntityException
  60. * @throws \Magento\Framework\Exception\CouldNotDeleteException
  61. */
  62. public function deleteById(int $stockId): void;
  63. }