Data.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * Mageplaza
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Mageplaza.com license that is
  8. * available through the world-wide-web at this URL:
  9. * https://www.mageplaza.com/LICENSE.txt
  10. *
  11. * DISCLAIMER
  12. *
  13. * Do not edit or add to this file if you wish to upgrade this extension to newer
  14. * version in the future.
  15. *
  16. * @category Mageplaza
  17. * @package Mageplaza_LayeredNavigation
  18. * @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
  19. * @license https://www.mageplaza.com/LICENSE.txt
  20. */
  21. namespace Mageplaza\LayeredNavigation\Helper;
  22. /**
  23. * Class Data
  24. * @package Mageplaza\LayeredNavigation\Helper
  25. */
  26. class Data extends \Mageplaza\AjaxLayer\Helper\Data
  27. {
  28. const FILTER_TYPE_SLIDER = 'slider';
  29. const FILTER_TYPE_LIST = 'list';
  30. /** @var \Mageplaza\LayeredNavigation\Model\Layer\Filter */
  31. protected $filterModel;
  32. /**
  33. * @param null $storeId
  34. *
  35. * @return mixed
  36. */
  37. public function isEnabled($storeId = null)
  38. {
  39. return $this->getConfigGeneral('enable', $storeId) && $this->isModuleOutputEnabled();
  40. }
  41. /**
  42. * @param $filters
  43. * @return mixed
  44. */
  45. public function getLayerConfiguration($filters)
  46. {
  47. $filterParams = $this->_getRequest()->getParams();
  48. foreach ($filterParams as $key => $param) {
  49. $filterParams[$key] = htmlspecialchars($param);
  50. }
  51. $config = new \Magento\Framework\DataObject([
  52. 'active' => array_keys($filterParams),
  53. 'params' => $filterParams,
  54. 'isCustomerLoggedIn' => $this->objectManager->create('Magento\Customer\Model\Session')->isLoggedIn(),
  55. 'isAjax' => $this->ajaxEnabled()
  56. ]);
  57. $this->getFilterModel()->getLayerConfiguration($filters, $config);
  58. return self::jsonEncode($config->getData());
  59. }
  60. /**
  61. * @return \Mageplaza\LayeredNavigation\Model\Layer\Filter
  62. */
  63. public function getFilterModel()
  64. {
  65. if (!$this->filterModel) {
  66. $this->filterModel = $this->objectManager->create('Mageplaza\LayeredNavigation\Model\Layer\Filter');
  67. }
  68. return $this->filterModel;
  69. }
  70. /**
  71. * @return \Magento\Framework\ObjectManagerInterface
  72. */
  73. public function getObjectManager()
  74. {
  75. return $this->objectManager;
  76. }
  77. }