StockItemConfiguration.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  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\InventoryConfiguration\Model;
  8. use Magento\CatalogInventory\Api\Data\StockItemInterface;
  9. use Magento\Framework\Api\AttributeValueFactory;
  10. use Magento\Framework\Api\ExtensionAttributesFactory;
  11. use Magento\Framework\App\Config\ScopeConfigInterface;
  12. use Magento\Framework\Data\Collection\AbstractDb;
  13. use Magento\Framework\Model\AbstractExtensibleModel;
  14. use Magento\Framework\Model\Context;
  15. use Magento\Framework\Model\ResourceModel\AbstractResource;
  16. use Magento\Framework\Registry;
  17. use Magento\InventoryConfigurationApi\Api\Data\StockItemConfigurationInterface;
  18. use Magento\InventoryConfigurationApi\Api\Data\StockItemConfigurationExtensionInterface;
  19. /**
  20. * @SuppressWarnings(PHPMD.ExcessivePublicCount)
  21. * @inheritdoc
  22. */
  23. class StockItemConfiguration extends AbstractExtensibleModel implements StockItemConfigurationInterface
  24. {
  25. /**
  26. * @var StockItemInterface
  27. */
  28. private $stockItem;
  29. /**
  30. * @var ScopeConfigInterface
  31. */
  32. private $scopeConfig;
  33. /**
  34. * @param Context $context
  35. * @param Registry $registry
  36. * @param ExtensionAttributesFactory $extensionFactory
  37. * @param AttributeValueFactory $customAttributeFactory
  38. * @param StockItemInterface $stockItem
  39. * @param ScopeConfigInterface $scopeConfig
  40. * @param AbstractResource|null $resource
  41. * @param AbstractDb|null $resourceCollection
  42. * @param array $data
  43. */
  44. public function __construct(
  45. Context $context,
  46. Registry $registry,
  47. ExtensionAttributesFactory $extensionFactory,
  48. AttributeValueFactory $customAttributeFactory,
  49. StockItemInterface $stockItem,
  50. ScopeConfigInterface $scopeConfig,
  51. AbstractResource $resource = null,
  52. AbstractDb $resourceCollection = null,
  53. array $data = []
  54. ) {
  55. parent::__construct(
  56. $context,
  57. $registry,
  58. $extensionFactory,
  59. $customAttributeFactory,
  60. $resource,
  61. $resourceCollection,
  62. $data
  63. );
  64. $this->stockItem = $stockItem;
  65. $this->scopeConfig = $scopeConfig;
  66. }
  67. /**
  68. * @inheritdoc
  69. */
  70. public function isQtyDecimal(): bool
  71. {
  72. return (bool)$this->stockItem->getIsQtyDecimal();
  73. }
  74. /**
  75. * @inheritdoc
  76. */
  77. public function setIsQtyDecimal(bool $isQtyDecimal): void
  78. {
  79. $this->stockItem->setIsQtyDecimal($isQtyDecimal);
  80. }
  81. /**
  82. * @inheritdoc
  83. */
  84. public function isShowDefaultNotificationMessage(): bool
  85. {
  86. return $this->stockItem->getShowDefaultNotificationMessage();
  87. }
  88. /**
  89. * @inheritdoc
  90. */
  91. public function isUseConfigMinQty(): bool
  92. {
  93. return (bool)$this->stockItem->getUseConfigMinQty();
  94. }
  95. /**
  96. * @inheritdoc
  97. */
  98. public function setUseConfigMinQty(bool $useConfigMinQty): void
  99. {
  100. $this->stockItem = $this->stockItem->setUseConfigMinQty($useConfigMinQty);
  101. }
  102. /**
  103. * @inheritdoc
  104. */
  105. public function getMinQty(): float
  106. {
  107. return $this->stockItem->getMinQty();
  108. }
  109. /**
  110. * @inheritdoc
  111. */
  112. public function setMinQty(float $minQty): void
  113. {
  114. $this->stockItem->setMinQty($minQty);
  115. }
  116. /**
  117. * @inheritdoc
  118. */
  119. public function isUseConfigMinSaleQty(): bool
  120. {
  121. return (bool)$this->stockItem->getUseConfigMinSaleQty();
  122. }
  123. /**
  124. * @inheritdoc
  125. */
  126. public function setUseConfigMinSaleQty(bool $useConfigMinSaleQty): void
  127. {
  128. $this->stockItem->setUseConfigMinSaleQty($useConfigMinSaleQty);
  129. }
  130. /**
  131. * @inheritdoc
  132. */
  133. public function getMinSaleQty(): float
  134. {
  135. return $this->stockItem->getMinSaleQty();
  136. }
  137. /**
  138. * @inheritdoc
  139. */
  140. public function setMinSaleQty(float $minSaleQty): void
  141. {
  142. $this->stockItem->setMinSaleQty($minSaleQty);
  143. }
  144. /**
  145. * @inheritdoc
  146. */
  147. public function isUseConfigMaxSaleQty(): bool
  148. {
  149. return (bool)$this->stockItem->getUseConfigMaxSaleQty();
  150. }
  151. /**
  152. * @inheritdoc
  153. */
  154. public function setUseConfigMaxSaleQty(bool $useConfigMaxSaleQty): void
  155. {
  156. $this->stockItem->setUseConfigMaxSaleQty($useConfigMaxSaleQty);
  157. }
  158. /**
  159. * @inheritdoc
  160. */
  161. public function getMaxSaleQty(): float
  162. {
  163. return $this->stockItem->getMaxSaleQty();
  164. }
  165. /**
  166. * @inheritdoc
  167. */
  168. public function setMaxSaleQty(float $maxSaleQty): void
  169. {
  170. $this->stockItem->setMaxSaleQty($maxSaleQty);
  171. }
  172. /**
  173. * @inheritdoc
  174. */
  175. public function isUseConfigBackorders(): bool
  176. {
  177. return (bool)$this->stockItem->getUseConfigBackorders();
  178. }
  179. /**
  180. * @inheritdoc
  181. */
  182. public function setUseConfigBackorders(bool $useConfigBackorders): void
  183. {
  184. $this->stockItem->setUseConfigBackorders($useConfigBackorders);
  185. }
  186. /**
  187. * @inheritdoc
  188. */
  189. public function getBackorders(): int
  190. {
  191. return $this->stockItem->getBackorders();
  192. }
  193. /**
  194. * @inheritdoc
  195. */
  196. public function setBackorders(int $backOrders): void
  197. {
  198. $this->stockItem->setBackorders($backOrders);
  199. }
  200. /**
  201. * @inheritdoc
  202. */
  203. public function isUseConfigNotifyStockQty(): bool
  204. {
  205. return (bool)$this->stockItem->getUseConfigNotifyStockQty();
  206. }
  207. /**
  208. * @inheritdoc
  209. */
  210. public function setUseConfigNotifyStockQty(bool $useConfigNotifyStockQty): void
  211. {
  212. $this->stockItem->setUseConfigNotifyStockQty($useConfigNotifyStockQty);
  213. }
  214. /**
  215. * @inheritdoc
  216. */
  217. public function getNotifyStockQty(): float
  218. {
  219. return $this->stockItem->getNotifyStockQty();
  220. }
  221. /**
  222. * @inheritdoc
  223. */
  224. public function setNotifyStockQty(float $notifyStockQty): void
  225. {
  226. $this->stockItem->setNotifyStockQty($notifyStockQty);
  227. }
  228. /**
  229. * @inheritdoc
  230. */
  231. public function isUseConfigQtyIncrements(): bool
  232. {
  233. return (bool)$this->stockItem->getUseConfigQtyIncrements();
  234. }
  235. /**
  236. * @inheritdoc
  237. */
  238. public function setUseConfigQtyIncrements(bool $useConfigQtyIncrements): void
  239. {
  240. $this->stockItem->setUseConfigQtyIncrements($useConfigQtyIncrements);
  241. }
  242. /**
  243. * @inheritdoc
  244. */
  245. public function getQtyIncrements(): float
  246. {
  247. $qtyIncrements = $this->stockItem->getQtyIncrements();
  248. if (false === $qtyIncrements) {
  249. return 0;
  250. }
  251. return $qtyIncrements;
  252. }
  253. /**
  254. * @inheritdoc
  255. */
  256. public function setQtyIncrements(float $qtyIncrements): void
  257. {
  258. $this->stockItem->setQtyIncrements($qtyIncrements);
  259. }
  260. /**
  261. * @inheritdoc
  262. */
  263. public function isUseConfigEnableQtyInc(): bool
  264. {
  265. return (bool)$this->stockItem->getUseConfigEnableQtyInc();
  266. }
  267. /**
  268. * @inheritdoc
  269. */
  270. public function setUseConfigEnableQtyInc(bool $useConfigEnableQtyInc): void
  271. {
  272. $this->stockItem->setUseConfigEnableQtyInc($useConfigEnableQtyInc);
  273. }
  274. /**
  275. * @inheritdoc
  276. */
  277. public function isEnableQtyIncrements(): bool
  278. {
  279. return (bool)$this->stockItem->getEnableQtyIncrements();
  280. }
  281. /**
  282. * @inheritdoc
  283. */
  284. public function setEnableQtyIncrements(bool $enableQtyIncrements): void
  285. {
  286. $this->stockItem->setEnableQtyIncrements($enableQtyIncrements);
  287. }
  288. /**
  289. * @inheritdoc
  290. */
  291. public function isUseConfigManageStock(): bool
  292. {
  293. return (bool)$this->stockItem->getUseConfigManageStock();
  294. }
  295. /**
  296. * @inheritdoc
  297. */
  298. public function setUseConfigManageStock(bool $useConfigManageStock): void
  299. {
  300. $this->stockItem->setUseConfigManageStock($useConfigManageStock);
  301. }
  302. /**
  303. * @inheritdoc
  304. */
  305. public function isManageStock(): bool
  306. {
  307. return (bool)$this->stockItem->getManageStock();
  308. }
  309. /**
  310. * @inheritdoc
  311. */
  312. public function setManageStock(bool $manageStock): void
  313. {
  314. $this->stockItem->setManageStock($manageStock);
  315. }
  316. /**
  317. * @inheritdoc
  318. */
  319. public function getLowStockDate(): string
  320. {
  321. $lowStockDate = $this->stockItem->getLowStockDate();
  322. return null === $lowStockDate ? '' : $lowStockDate;
  323. }
  324. /**
  325. * @inheritdoc
  326. */
  327. public function setLowStockDate(string $lowStockDate): void
  328. {
  329. $this->stockItem->setLowStockDate($lowStockDate);
  330. }
  331. /**
  332. * @inheritdoc
  333. */
  334. public function isDecimalDivided(): bool
  335. {
  336. return (bool)$this->stockItem->getIsDecimalDivided();
  337. }
  338. /**
  339. * @inheritdoc
  340. */
  341. public function setIsDecimalDivided(bool $isDecimalDivided): void
  342. {
  343. $this->stockItem->setIsDecimalDivided($isDecimalDivided);
  344. }
  345. /**
  346. * @inheritdoc
  347. */
  348. public function getStockStatusChangedAuto(): bool
  349. {
  350. return (bool)$this->stockItem->getStockStatusChangedAuto();
  351. }
  352. /**
  353. * @inheritdoc
  354. */
  355. public function setStockStatusChangedAuto(int $stockStatusChangedAuto): void
  356. {
  357. $this->stockItem->setStockStatusChangedAuto($stockStatusChangedAuto);
  358. }
  359. /**
  360. * @inheritdoc
  361. */
  362. public function getStockThresholdQty(): float
  363. {
  364. return (float)$this->scopeConfig->getValue(
  365. \Magento\CatalogInventory\Model\Configuration::XML_PATH_STOCK_THRESHOLD_QTY,
  366. \Magento\Store\Model\ScopeInterface::SCOPE_STORE
  367. );
  368. }
  369. /**
  370. * @inheritdoc
  371. */
  372. public function getExtensionAttributes(): ?StockItemConfigurationExtensionInterface
  373. {
  374. $extensionAttributes = $this->_getExtensionAttributes();
  375. if (null === $extensionAttributes) {
  376. $extensionAttributes = $this->extensionAttributesFactory->create(StockItemConfigurationInterface::class);
  377. $this->setExtensionAttributes($extensionAttributes);
  378. }
  379. return $extensionAttributes;
  380. }
  381. /**
  382. * @inheritdoc
  383. */
  384. public function setExtensionAttributes(StockItemConfigurationExtensionInterface $extensionAttributes): void
  385. {
  386. $this->_setExtensionAttributes($extensionAttributes);
  387. }
  388. }