Preprocessor.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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\Plugin\Model\Adapter;
  22. use Magento\Framework\App\ProductMetadataInterface;
  23. /**
  24. * Class Preprocessor
  25. * @package Mageplaza\LayeredNavigation\Model\Plugin\Adapter
  26. */
  27. class Preprocessor
  28. {
  29. /**
  30. * @type \Mageplaza\LayeredNavigation\Helper\Data
  31. */
  32. protected $_moduleHelper;
  33. /**
  34. * @type \Magento\Framework\ObjectManagerInterface
  35. */
  36. protected $objectManager;
  37. /**
  38. * Preprocessor constructor.
  39. * @param \Mageplaza\LayeredNavigation\Helper\Data $moduleHelper
  40. * @param \Magento\Framework\ObjectManagerInterface $objectManager
  41. */
  42. public function __construct(
  43. \Mageplaza\LayeredNavigation\Helper\Data $moduleHelper,
  44. \Magento\Framework\ObjectManagerInterface $objectManager
  45. )
  46. {
  47. $this->_moduleHelper = $moduleHelper;
  48. $this->objectManager = $objectManager;
  49. }
  50. /**
  51. * @param \Magento\CatalogSearch\Model\Adapter\Mysql\Filter\Preprocessor $subject
  52. * @param \Closure $proceed
  53. * @param $filter
  54. * @param $isNegation
  55. * @param $query
  56. * @return string
  57. */
  58. public function aroundProcess(\Magento\CatalogSearch\Model\Adapter\Mysql\Filter\Preprocessor $subject, \Closure $proceed, $filter, $isNegation, $query)
  59. {
  60. $productMetadata = $this->objectManager->get(ProductMetadataInterface::class);
  61. $version = $productMetadata->getVersion(); //will return the magento version
  62. if ($this->_moduleHelper->isEnabled() && ($filter->getField() === 'category_ids')) {
  63. if (version_compare($version, '2.1.13', '>=') && version_compare($version, '2.1.15', '<=')) {
  64. return 'category_products_index.category_id IN (' . $filter->getValue() . ')';
  65. }
  66. return 'category_ids_index.category_id IN (' . $filter->getValue() . ')';
  67. }
  68. return $proceed($filter, $isNegation, $query);
  69. }
  70. }