Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SortFields.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
13 
17 class SortFields implements ResolverInterface
18 {
22  private $catalogConfig;
23 
27  private $storeManager;
28 
32  private $sortbyAttributeSource;
33 
39  public function __construct(
40  \Magento\Catalog\Model\Config $catalogConfig,
41  \Magento\Store\Model\StoreManagerInterface $storeManager,
42  \Magento\Catalog\Model\Category\Attribute\Source\Sortby $sortbyAttributeSource
43  ) {
44  $this->catalogConfig = $catalogConfig;
45  $this->storeManager = $storeManager;
46  $this->sortbyAttributeSource = $sortbyAttributeSource;
47  }
48 
52  public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
53  {
54  $sortFieldsOptions = $this->sortbyAttributeSource->getAllOptions();
55  array_walk(
56  $sortFieldsOptions,
57  function (&$option) {
58  $option['label'] = (string)$option['label'];
59  }
60  );
61  $data = [
62  'default' => $this->catalogConfig->getProductListDefaultSortBy($this->storeManager->getStore()->getId()),
63  'options' => $sortFieldsOptions,
64  ];
65 
66  return $data;
67  }
68 }
$storeManager
__construct(\Magento\Catalog\Model\Config $catalogConfig, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Catalog\Model\Category\Attribute\Source\Sortby $sortbyAttributeSource)
Definition: SortFields.php:39
$value
Definition: gender.phtml:16
resolve(Field $field, $context, ResolveInfo $info, array $value=null, array $args=null)
Definition: SortFields.php:52
foreach( $_productCollection as $_product)() ?>" class $info
Definition: listing.phtml:52