1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace GeminiLabs\SiteReviews\Integrations\SureCart\Controllers; |
4
|
|
|
|
5
|
|
|
use GeminiLabs\SiteReviews\Contracts\ControllerContract; |
6
|
|
|
use GeminiLabs\SiteReviews\HookProxy; |
7
|
|
|
use SureCart\Models\Model; |
|
|
|
|
8
|
|
|
|
9
|
|
|
class RestController implements ControllerContract |
10
|
|
|
{ |
11
|
|
|
use HookProxy; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @filter surecart/request/model |
15
|
|
|
*/ |
16
|
|
|
public function filterProductModel(Model $model, \WP_REST_Request $request): Model |
|
|
|
|
17
|
|
|
{ |
18
|
|
|
if (!is_a($model, 'SureCart\Models\Product')) { |
19
|
|
|
return $model; |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
// glsr_log($model); |
23
|
|
|
// glsr_log($request->get_param('id')); |
24
|
|
|
// $modelId = $request['id'] ?? ''; |
25
|
|
|
|
26
|
|
|
return $model; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param WP_REST_Request|null $request The WP_REST_Request object |
32
|
|
|
* @param string|null $method The method of the request |
33
|
|
|
* |
34
|
|
|
* @return WP_REST_Request|null |
35
|
|
|
* |
36
|
|
|
* @filter rest_products_request |
37
|
|
|
*/ |
38
|
|
|
public function filterProductsRequest($request = null, $method = null) |
|
|
|
|
39
|
|
|
{ |
40
|
|
|
// if (!$request instanceof WP_REST_Request || 'find' !== $method) { // methods can be create, edit, delete & find. |
41
|
|
|
if (!$request instanceof WP_REST_Request) { |
|
|
|
|
42
|
|
|
return $request; |
43
|
|
|
} |
44
|
|
|
// Add your custom logic here. |
45
|
|
|
// For example, you can modify the metadata param in the checkout request. |
46
|
|
|
$request_metadata = $request->get_param('metadata'); |
47
|
|
|
$metadata = (object) array_merge( |
48
|
|
|
$request_metadata, |
49
|
|
|
[ |
50
|
|
|
'key1' => 'value1', |
51
|
|
|
'key2' => 'value2', |
52
|
|
|
'key3' => 'value3', |
53
|
|
|
] |
54
|
|
|
); |
55
|
|
|
$request->set_param('metadata', $metadata); |
56
|
|
|
return $request; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @filter site-reviews/rest-api/summary/args |
61
|
|
|
*/ |
62
|
|
|
public function filterRestApiSummaryArgs(array $args, \WP_REST_Request $request): array |
63
|
|
|
{ |
64
|
|
|
if ('/site-reviews/v1/summary/stars' !== $request->get_route()) { |
65
|
|
|
return $args; |
66
|
|
|
} |
67
|
|
|
if (!str_contains((string) $request->get_param('_block'), 'surecart-product-rating')) { |
68
|
|
|
return $args; |
69
|
|
|
} |
70
|
|
|
$args['theme'] = glsr_get_option('integrations.surecart.style'); |
71
|
|
|
return $args; |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
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