Stock.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\CatalogInventory\Model;
  7. use Magento\CatalogInventory\Api\Data\StockInterface;
  8. use Magento\Framework\Model\AbstractExtensibleModel;
  9. /**
  10. * Class Stock
  11. *
  12. */
  13. class Stock extends AbstractExtensibleModel implements StockInterface
  14. {
  15. /**
  16. * Stock entity code
  17. */
  18. const ENTITY = 'cataloginventory_stock';
  19. /**
  20. * Prefix of model events names
  21. *
  22. * @var string
  23. */
  24. protected $_eventPrefix = 'cataloginventory_stock';
  25. /**
  26. * Parameter name in event
  27. * In observe method you can use $observer->getEvent()->getStock() in this case
  28. *
  29. * @var string
  30. */
  31. protected $_eventObject = 'stock';
  32. const BACKORDERS_NO = 0;
  33. const BACKORDERS_YES_NONOTIFY = 1;
  34. const BACKORDERS_YES_NOTIFY = 2;
  35. const STOCK_OUT_OF_STOCK = 0;
  36. const STOCK_IN_STOCK = 1;
  37. const WEBSITE_ID = 'website_id';
  38. /**
  39. * Default stock id
  40. */
  41. const DEFAULT_STOCK_ID = 1;
  42. /**
  43. * @return void
  44. */
  45. protected function _construct()
  46. {
  47. $this->_init(\Magento\CatalogInventory\Model\ResourceModel\Stock::class);
  48. }
  49. //@codeCoverageIgnoreStart
  50. /**
  51. * Retrieve stock identifier
  52. *
  53. * @return int|null
  54. */
  55. public function getStockId()
  56. {
  57. return $this->_getData(self::STOCK_ID);
  58. }
  59. /**
  60. * Retrieve website identifier
  61. *
  62. * @return int
  63. */
  64. public function getWebsiteId()
  65. {
  66. return $this->_getData(self::WEBSITE_ID);
  67. }
  68. /**
  69. * Retrieve Stock Name
  70. *
  71. * @return string
  72. */
  73. public function getStockName()
  74. {
  75. return $this->_getData(self::STOCK_NAME);
  76. }
  77. /**
  78. * Set stock identifier
  79. *
  80. * @param int $stockId
  81. * @return $this
  82. */
  83. public function setStockId($stockId)
  84. {
  85. return $this->setData(self::STOCK_ID, $stockId);
  86. }
  87. /**
  88. * Retrieve website identifier
  89. *
  90. * @param int $websiteId
  91. * @return $this
  92. */
  93. public function setWebsiteId($websiteId)
  94. {
  95. return $this->setData(self::WEBSITE_ID, $websiteId);
  96. }
  97. /**
  98. * Set stock name
  99. *
  100. * @param string $stockName
  101. * @return $this
  102. */
  103. public function setStockName($stockName)
  104. {
  105. return $this->setData(self::STOCK_NAME, $stockName);
  106. }
  107. /**
  108. * {@inheritdoc}
  109. *
  110. * @return \Magento\CatalogInventory\Api\Data\StockExtensionInterface|null
  111. */
  112. public function getExtensionAttributes()
  113. {
  114. return $this->_getExtensionAttributes();
  115. }
  116. /**
  117. * {@inheritdoc}
  118. *
  119. * @param \Magento\CatalogInventory\Api\Data\StockExtensionInterface $extensionAttributes
  120. * @return $this
  121. */
  122. public function setExtensionAttributes(
  123. \Magento\CatalogInventory\Api\Data\StockExtensionInterface $extensionAttributes
  124. ) {
  125. return $this->_setExtensionAttributes($extensionAttributes);
  126. }
  127. //@codeCoverageIgnoreEnd
  128. }