Qtyincrements.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\CatalogInventory\Block;
  7. use Magento\Framework\DataObject\IdentityInterface;
  8. use Magento\Framework\View\Element\Template;
  9. /**
  10. * Product qty increments block
  11. *
  12. * @api
  13. * @since 100.0.2
  14. *
  15. * @deprecated 100.3.0 Replaced with Multi Source Inventory
  16. * @link https://devdocs.magento.com/guides/v2.3/inventory/index.html
  17. * @link https://devdocs.magento.com/guides/v2.3/inventory/catalog-inventory-replacements.html
  18. */
  19. class Qtyincrements extends Template implements IdentityInterface
  20. {
  21. /**
  22. * Qty Increments cache
  23. *
  24. * @var float|false
  25. */
  26. protected $_qtyIncrements;
  27. /**
  28. * Core registry
  29. *
  30. * @var \Magento\Framework\Registry
  31. */
  32. protected $_coreRegistry;
  33. /**
  34. * @var \Magento\CatalogInventory\Api\StockRegistryInterface
  35. */
  36. protected $stockRegistry;
  37. /**
  38. * @param \Magento\Framework\View\Element\Template\Context $context
  39. * @param \Magento\Framework\Registry $registry
  40. * @param \Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry
  41. * @param array $data
  42. */
  43. public function __construct(
  44. \Magento\Framework\View\Element\Template\Context $context,
  45. \Magento\Framework\Registry $registry,
  46. \Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry,
  47. array $data = []
  48. ) {
  49. $this->_coreRegistry = $registry;
  50. $this->stockRegistry = $stockRegistry;
  51. parent::__construct($context, $data);
  52. }
  53. /**
  54. * Retrieve current product object
  55. *
  56. * @return \Magento\Catalog\Model\Product
  57. */
  58. public function getProduct()
  59. {
  60. return $this->_coreRegistry->registry('current_product');
  61. }
  62. /**
  63. * Retrieve current product name
  64. *
  65. * @return string
  66. */
  67. public function getProductName()
  68. {
  69. return $this->getProduct()->getName();
  70. }
  71. /**
  72. * Retrieve product qty increments
  73. *
  74. * @return float|false
  75. */
  76. public function getProductQtyIncrements()
  77. {
  78. if ($this->_qtyIncrements === null) {
  79. $stockItem = $this->stockRegistry->getStockItem(
  80. $this->getProduct()->getId(),
  81. $this->getProduct()->getStore()->getWebsiteId()
  82. );
  83. $this->_qtyIncrements = $stockItem->getQtyIncrements();
  84. if (!$this->getProduct()->isSaleable()) {
  85. $this->_qtyIncrements = false;
  86. }
  87. }
  88. return $this->_qtyIncrements;
  89. }
  90. /**
  91. * Return identifiers for produced content
  92. *
  93. * @return array
  94. */
  95. public function getIdentities()
  96. {
  97. return $this->getProduct()->getIdentities();
  98. }
  99. }