Weight.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\CatalogSearch\Model\Source;
  7. /**
  8. * Attribute weight options
  9. * @api
  10. * @since 100.0.2
  11. */
  12. class Weight implements \Magento\Framework\Data\OptionSourceInterface
  13. {
  14. /**
  15. * Quick search weights
  16. *
  17. * @var int[]
  18. * @since 100.1.0
  19. */
  20. protected $weights = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'];
  21. /**
  22. * Retrieve search weights as options array
  23. *
  24. * @return array
  25. */
  26. public function getOptions()
  27. {
  28. $res = [];
  29. foreach ($this->getValues() as $value) {
  30. $res[] = ['value' => $value, 'label' => $value];
  31. }
  32. return $res;
  33. }
  34. /**
  35. * Retrieve search weights array
  36. *
  37. * @return int[]
  38. */
  39. public function getValues()
  40. {
  41. return $this->weights;
  42. }
  43. /**
  44. * Return array of options as value-label pairs
  45. *
  46. * @return array Format: array(array('value' => '<value>', 'label' => '<label>'), ...)
  47. * @since 100.1.0
  48. */
  49. public function toOptionArray()
  50. {
  51. return $this->getOptions();
  52. }
  53. }