Interval.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\CatalogSearch\Model\Price;
  7. use Magento\Framework\Search\Dynamic\IntervalInterface;
  8. /**
  9. * Catalog search price interval.
  10. */
  11. class Interval implements IntervalInterface
  12. {
  13. /**
  14. * @var \Magento\Catalog\Model\ResourceModel\Layer\Filter\Price
  15. */
  16. private $resource;
  17. /**
  18. * @param \Magento\Catalog\Model\ResourceModel\Layer\Filter\Price $resource
  19. */
  20. public function __construct(\Magento\Catalog\Model\ResourceModel\Layer\Filter\Price $resource)
  21. {
  22. $this->resource = $resource;
  23. }
  24. /**
  25. * @inheritdoc
  26. */
  27. public function load($limit, $offset = null, $lower = null, $upper = null)
  28. {
  29. $prices = $this->resource->loadPrices($limit, $offset, $lower, $upper);
  30. return $this->arrayValuesToFloat($prices);
  31. }
  32. /**
  33. * @inheritdoc
  34. */
  35. public function loadPrevious($data, $index, $lower = null)
  36. {
  37. $prices = $this->resource->loadPreviousPrices($data, $index, $lower);
  38. return $this->arrayValuesToFloat($prices);
  39. }
  40. /**
  41. * @inheritdoc
  42. */
  43. public function loadNext($data, $rightIndex, $upper = null)
  44. {
  45. $prices = $this->resource->loadNextPrices($data, $rightIndex, $upper);
  46. return $this->arrayValuesToFloat($prices);
  47. }
  48. /**
  49. * Convert to float values.
  50. *
  51. * @param array $prices
  52. * @return array
  53. */
  54. private function arrayValuesToFloat($prices)
  55. {
  56. $returnPrices = [];
  57. if (is_array($prices) && !empty($prices)) {
  58. $returnPrices = array_map('floatval', $prices);
  59. }
  60. return $returnPrices;
  61. }
  62. }