Stock.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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\Inventory\Model;
  8. use Magento\Framework\Model\AbstractExtensibleModel;
  9. use Magento\Inventory\Model\ResourceModel\Stock as StockResourceModel;
  10. use Magento\InventoryApi\Api\Data\StockExtensionInterface;
  11. use Magento\InventoryApi\Api\Data\StockInterface;
  12. /**
  13. * {@inheritdoc}
  14. *
  15. * @codeCoverageIgnore
  16. */
  17. class Stock extends AbstractExtensibleModel implements StockInterface
  18. {
  19. /**
  20. * @inheritdoc
  21. */
  22. protected function _construct()
  23. {
  24. $this->_init(StockResourceModel::class);
  25. }
  26. /**
  27. * @inheritdoc
  28. */
  29. public function getStockId(): ?int
  30. {
  31. return $this->getData(self::STOCK_ID) === null ?
  32. null:
  33. (int)$this->getData(self::STOCK_ID);
  34. }
  35. /**
  36. * @inheritdoc
  37. */
  38. public function setStockId(?int $stockId): void
  39. {
  40. $this->setData(self::STOCK_ID, $stockId);
  41. }
  42. /**
  43. * @inheritdoc
  44. */
  45. public function getName(): ?string
  46. {
  47. return $this->getData(self::NAME);
  48. }
  49. /**
  50. * @inheritdoc
  51. */
  52. public function setName(?string $name): void
  53. {
  54. $this->setData(self::NAME, $name);
  55. }
  56. /**
  57. * @inheritdoc
  58. */
  59. public function getExtensionAttributes(): ?StockExtensionInterface
  60. {
  61. $extensionAttributes = $this->_getExtensionAttributes();
  62. if (null === $extensionAttributes) {
  63. $extensionAttributes = $this->extensionAttributesFactory->create(StockInterface::class);
  64. $this->setExtensionAttributes($extensionAttributes);
  65. }
  66. return $extensionAttributes;
  67. }
  68. /**
  69. * @inheritdoc
  70. */
  71. public function setExtensionAttributes(StockExtensionInterface $extensionAttributes): void
  72. {
  73. $this->_setExtensionAttributes($extensionAttributes);
  74. }
  75. }