Collection.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. /**
  3. * @copyright Vertex. All rights reserved. https://www.vertexinc.com/
  4. * @author Mediotype https://www.mediotype.com/
  5. */
  6. namespace Vertex\Tax\Model\ResourceModel\Country;
  7. use Magento\Directory\Model\ResourceModel\Country\Collection as CountryCollection;
  8. /**
  9. * Country Resource Collection
  10. */
  11. class Collection extends CountryCollection
  12. {
  13. /**
  14. * Convert collection items to select options array
  15. *
  16. * @return array
  17. */
  18. public function toOptionArrayISO3()
  19. {
  20. $options = $this->_toOptionArray('country_id', 'name', ['title' => 'iso3_code']);
  21. $sort = [];
  22. foreach ($options as $data) {
  23. $name = (string)$this->_localeLists->getCountryTranslation($data['value']);
  24. if (!empty($name)) {
  25. $sort[$name] = $data['title'];
  26. }
  27. }
  28. $this->_arrayUtils->ksortMultibyte($sort, $this->_localeResolver->getLocale());
  29. $sort = array_flip($sort);
  30. $options = [];
  31. foreach ($sort as $value => $label) {
  32. $options[] = ['value' => $value, 'label' => $label];
  33. }
  34. return $options;
  35. }
  36. }