This repository has been archived by the owner on May 20, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENGCOM-1635: GraphQL - Added sort by options to Products GraphQL type #…
…12 - Merge Pull Request magento/graphql-ce#12 from zbigniewkuras/graphql-ce:issiue-3 - Merged commits: 1. dd3aa38 2. 02d6a22 3. 9035d29 4. d804bab 5. 9962c66 6. 1855062
- Loading branch information
Showing
5 changed files
with
113 additions
and
3 deletions.
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
app/code/Magento/CatalogGraphQl/Model/Resolver/Category/SortFields.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\CatalogGraphQl\Model\Resolver\Category; | ||
|
||
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; | ||
use Magento\Framework\GraphQl\Config\Element\Field; | ||
use Magento\Framework\GraphQl\Query\Resolver\Value; | ||
use Magento\Framework\GraphQl\Query\Resolver\ValueFactory; | ||
use Magento\Framework\GraphQl\Query\ResolverInterface; | ||
|
||
/** | ||
* Retrieves the sort fields data | ||
*/ | ||
class SortFields implements ResolverInterface | ||
{ | ||
/** | ||
* @var ValueFactory | ||
*/ | ||
private $valueFactory; | ||
|
||
/** | ||
* @var \Magento\Catalog\Model\Config | ||
*/ | ||
private $catalogConfig; | ||
|
||
/** | ||
* @var \Magento\Store\Model\StoreManagerInterface | ||
*/ | ||
private $storeManager; | ||
|
||
/** | ||
* @var \Magento\Catalog\Model\Category\Attribute\Source\Sortby | ||
*/ | ||
private $sortbyAttributeSource; | ||
|
||
/** | ||
* @param ValueFactory $valueFactory | ||
* @param \Magento\Catalog\Model\Config $catalogConfig | ||
* @param \Magento\Store\Model\StoreManagerInterface $storeManager | ||
* @oaram \Magento\Catalog\Model\Category\Attribute\Source\Sortby $sortbyAttributeSource | ||
*/ | ||
public function __construct( | ||
ValueFactory $valueFactory, | ||
\Magento\Catalog\Model\Config $catalogConfig, | ||
\Magento\Store\Model\StoreManagerInterface $storeManager, | ||
\Magento\Catalog\Model\Category\Attribute\Source\Sortby $sortbyAttributeSource | ||
) { | ||
$this->valueFactory = $valueFactory; | ||
$this->catalogConfig = $catalogConfig; | ||
$this->storeManager = $storeManager; | ||
$this->sortbyAttributeSource = $sortbyAttributeSource; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null) : Value | ||
{ | ||
$sortFieldsOptions = $this->sortbyAttributeSource->getAllOptions(); | ||
array_walk( | ||
$sortFieldsOptions, | ||
function (&$option) { | ||
$option['label'] = (string)$option['label']; | ||
} | ||
); | ||
$data = [ | ||
'default' => $this->catalogConfig->getProductListDefaultSortBy($this->storeManager->getStore()->getId()), | ||
'options' => $sortFieldsOptions, | ||
]; | ||
|
||
$result = function () use ($data) { | ||
return $data; | ||
}; | ||
|
||
return $this->valueFactory->create($result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters