1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright (c) 2019 Lars Roettig |
4
|
|
|
* |
5
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
6
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
7
|
|
|
* in the Software without restriction, including without limitation the rights |
8
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
9
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
10
|
|
|
* furnished to do so, subject to the following conditions: |
11
|
|
|
* |
12
|
|
|
* The above copyright notice and this permission notice shall be included in all |
13
|
|
|
* copies or substantial portions of the Software. |
14
|
|
|
* |
15
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
16
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
17
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
18
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
19
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
20
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
21
|
|
|
* SOFTWARE. |
22
|
|
|
*/ |
23
|
|
|
declare(strict_types=1); |
24
|
|
|
|
25
|
|
|
namespace LarsRoettig\GraphQLStorePickup\Model\Resolver; |
26
|
|
|
|
27
|
|
|
use LarsRoettig\GraphQLStorePickup\Api\StoreRepositoryInterface; |
28
|
|
|
use LarsRoettig\GraphQLStorePickup\Model\Store\GetList; |
29
|
|
|
use Magento\Framework\GraphQl\Config\Element\Field; |
30
|
|
|
use Magento\Framework\GraphQl\Exception\GraphQlInputException; |
31
|
|
|
use Magento\Framework\GraphQl\Query\Resolver\Argument\SearchCriteria\Builder as SearchCriteriaBuilder; |
32
|
|
|
use Magento\Framework\GraphQl\Query\ResolverInterface; |
33
|
|
|
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; |
34
|
|
|
|
35
|
|
|
class PickUpStores implements ResolverInterface |
36
|
|
|
{ |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var GetListInterface |
|
|
|
|
40
|
|
|
*/ |
41
|
|
|
private $storeRepository; |
42
|
|
|
/** |
43
|
|
|
* @var SearchCriteriaBuilder |
44
|
|
|
*/ |
45
|
|
|
private $searchCriteriaBuilder; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* PickUpStoresList constructor. |
49
|
|
|
* @param GetList $storeRepository |
50
|
|
|
* @param SearchCriteriaBuilder $searchCriteriaBuilder |
51
|
|
|
*/ |
52
|
|
|
public function __construct(StoreRepositoryInterface $storeRepository, SearchCriteriaBuilder $searchCriteriaBuilder) |
53
|
|
|
{ |
54
|
|
|
$this->storeRepository = $storeRepository; |
|
|
|
|
55
|
|
|
$this->searchCriteriaBuilder = $searchCriteriaBuilder; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @inheritdoc |
60
|
|
|
*/ |
61
|
|
|
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null) |
62
|
|
|
{ |
63
|
|
|
|
64
|
|
|
$this->vaildateArgs($args); |
|
|
|
|
65
|
|
|
|
66
|
|
|
$searchCriteria = $this->searchCriteriaBuilder->build('pickup_stores', $args); |
67
|
|
|
$searchCriteria->setCurrentPage($args['currentPage']); |
68
|
|
|
$searchCriteria->setPageSize($args['pageSize']); |
69
|
|
|
$searchResult = $this->storeRepository->getList($searchCriteria); |
70
|
|
|
|
71
|
|
|
return [ |
72
|
|
|
'total_count' => $searchResult->getTotalCount(), |
73
|
|
|
'items' => $searchResult->getItems(), |
74
|
|
|
]; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @param array $args |
79
|
|
|
* @throws GraphQlInputException |
80
|
|
|
*/ |
81
|
|
|
private function vaildateArgs(array $args): void |
82
|
|
|
{ |
83
|
|
|
if (isset($args['currentPage']) && $args['currentPage'] < 1) { |
84
|
|
|
throw new GraphQlInputException(__('currentPage value must be greater than 0.')); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
if (isset($args['pageSize']) && $args['pageSize'] < 1) { |
88
|
|
|
throw new GraphQlInputException(__('pageSize value must be greater than 0.')); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths