Config.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Wishlist\Model;
  7. /**
  8. * @api
  9. * @since 100.0.2
  10. */
  11. class Config
  12. {
  13. const XML_PATH_SHARING_EMAIL_LIMIT = 'wishlist/email/number_limit';
  14. const XML_PATH_SHARING_TEXT_LIMIT = 'wishlist/email/text_limit';
  15. const SHARING_EMAIL_LIMIT = 10;
  16. const SHARING_TEXT_LIMIT = 255;
  17. /**
  18. * @var \Magento\Catalog\Model\Config
  19. */
  20. private $catalogConfig;
  21. /**
  22. * @var \Magento\Catalog\Model\Attribute\Config
  23. */
  24. private $attributeConfig;
  25. /**
  26. * Number of emails allowed for sharing wishlist
  27. *
  28. * @var int
  29. */
  30. private $sharingEmailLimit;
  31. /**
  32. * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
  33. * @param \Magento\Catalog\Model\Config $catalogConfig
  34. * @param \Magento\Catalog\Model\Attribute\Config $attributeConfig
  35. */
  36. public function __construct(
  37. \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
  38. \Magento\Catalog\Model\Config $catalogConfig,
  39. \Magento\Catalog\Model\Attribute\Config $attributeConfig
  40. ) {
  41. $emailLimitInConfig = (int)$scopeConfig->getValue(
  42. self::XML_PATH_SHARING_EMAIL_LIMIT,
  43. \Magento\Store\Model\ScopeInterface::SCOPE_STORE
  44. );
  45. $textLimitInConfig = (int)$scopeConfig->getValue(
  46. self::XML_PATH_SHARING_TEXT_LIMIT,
  47. \Magento\Store\Model\ScopeInterface::SCOPE_STORE
  48. );
  49. $this->sharingEmailLimit = $emailLimitInConfig ?: self::SHARING_EMAIL_LIMIT;
  50. $this->_sharignTextLimit = $textLimitInConfig ?: self::SHARING_TEXT_LIMIT;
  51. $this->catalogConfig = $catalogConfig;
  52. $this->attributeConfig = $attributeConfig;
  53. }
  54. /**
  55. * Get product attributes that need in wishlist
  56. *
  57. * @return array
  58. */
  59. public function getProductAttributes()
  60. {
  61. $catalogAttributes = $this->catalogConfig->getProductAttributes();
  62. $wishlistAttributes = $this->attributeConfig->getAttributeNames('wishlist_item');
  63. return array_merge($catalogAttributes, $wishlistAttributes);
  64. }
  65. /**
  66. * Retrieve number of emails allowed for sharing wishlist
  67. *
  68. * @return int
  69. */
  70. public function getSharingEmailLimit()
  71. {
  72. return $this->sharingEmailLimit;
  73. }
  74. /**
  75. * Retrieve maximum length of sharing email text
  76. *
  77. * @return int
  78. */
  79. public function getSharingTextLimit()
  80. {
  81. return $this->_sharignTextLimit;
  82. }
  83. }