Counter.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\NewRelicReporting\Model;
  7. use Magento\Catalog\Api\ProductManagementInterface;
  8. use Magento\Catalog\Model\Product\Attribute\Source\Status;
  9. use Magento\ConfigurableProduct\Api\ConfigurableProductManagementInterface;
  10. use Magento\Catalog\Api\CategoryManagementInterface;
  11. use Magento\Customer\Api\CustomerManagementInterface;
  12. use Magento\Store\Api\WebsiteManagementInterface;
  13. use Magento\Store\Api\StoreManagementInterface;
  14. class Counter
  15. {
  16. /**
  17. * @var ProductManagementInterface
  18. */
  19. protected $productManagement;
  20. /**
  21. * @var ConfigurableProductManagementInterface
  22. */
  23. protected $configurableManagement;
  24. /**
  25. * @var CategoryManagementInterface
  26. */
  27. protected $categoryManagement;
  28. /**
  29. * @var CustomerManagementInterface
  30. */
  31. protected $customerManagement;
  32. /**
  33. * @var WebsiteManagementInterface
  34. */
  35. protected $websiteManagement;
  36. /**
  37. * @var StoreManagementInterface
  38. */
  39. protected $storeManagement;
  40. /**
  41. * Constructor
  42. *
  43. * @param ProductManagementInterface $productManagement
  44. * @param ConfigurableProductManagementInterface $configurableManagement
  45. * @param CategoryManagementInterface $categoryManagement
  46. * @param CustomerManagementInterface $customerManagement
  47. * @param WebsiteManagementInterface $websiteManagement
  48. * @param StoreManagementInterface $storeManagement
  49. */
  50. public function __construct(
  51. ProductManagementInterface $productManagement,
  52. ConfigurableProductManagementInterface $configurableManagement,
  53. CategoryManagementInterface $categoryManagement,
  54. CustomerManagementInterface $customerManagement,
  55. WebsiteManagementInterface $websiteManagement,
  56. StoreManagementInterface $storeManagement
  57. ) {
  58. $this->productManagement = $productManagement;
  59. $this->configurableManagement = $configurableManagement;
  60. $this->categoryManagement = $categoryManagement;
  61. $this->customerManagement = $customerManagement;
  62. $this->websiteManagement = $websiteManagement;
  63. $this->storeManagement = $storeManagement;
  64. }
  65. /**
  66. * Get count of all products, no conditions
  67. *
  68. * @return int
  69. */
  70. public function getAllProductsCount()
  71. {
  72. $count = $this->productManagement->getCount();
  73. return (int)$count;
  74. }
  75. /**
  76. * Get count of configurable products
  77. *
  78. * @return int
  79. */
  80. public function getConfigurableCount()
  81. {
  82. $count = $this->configurableManagement->getCount();
  83. return (int)$count;
  84. }
  85. /**
  86. * Get count of products which are active
  87. *
  88. * @return int
  89. */
  90. public function getActiveCatalogSize()
  91. {
  92. $count = $this->productManagement->getCount(Status::STATUS_ENABLED);
  93. return (int)$count;
  94. }
  95. /**
  96. * Get count of categories, minus one which is the root category
  97. *
  98. * @return int
  99. */
  100. public function getCategoryCount()
  101. {
  102. $count = $this->categoryManagement->getCount();
  103. return (int)$count;
  104. }
  105. /**
  106. * Get customer count
  107. *
  108. * @return int
  109. */
  110. public function getCustomerCount()
  111. {
  112. $count = $this->customerManagement->getCount();
  113. return (int)$count;
  114. }
  115. /**
  116. * Get count of websites, minus one to exclude admin website
  117. *
  118. * @return int
  119. */
  120. public function getWebsiteCount()
  121. {
  122. $count = $this->websiteManagement->getCount();
  123. return (int)$count;
  124. }
  125. /**
  126. * Get count of store views
  127. *
  128. * @return int
  129. */
  130. public function getStoreViewsCount()
  131. {
  132. $count = $this->storeManagement->getCount();
  133. return (int)$count;
  134. }
  135. }