Skip to content

Commit

Permalink
Prevent plugin to handle suggest query
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreGauthier committed Jun 9, 2023
1 parent dc01197 commit c1e09b2
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/Api/AbstractClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,20 @@ class AbstractClient
protected AuthenticationTokenProvider $tokenProvider;
protected Configuration $configuration;
protected LoggerInterface $logger;
protected string $kernelEnv;
protected ?string $token = null;
protected bool $debug;

public function __construct(
AuthenticationTokenProvider $tokenProvider,
Configuration $configuration,
LoggerInterface $logger
LoggerInterface $logger,
string $kernelEnv
){
$this->tokenProvider = $tokenProvider;
$this->configuration = $configuration;
$this->logger = $logger;
$this->kernelEnv = $kernelEnv;
$this->debug = false;
}

Expand Down
3 changes: 1 addition & 2 deletions src/Api/GraphQlClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ class GraphQlClient extends AbstractClient
{
public function query(string $query, array $variables): ?ResponseInterface
{
// TODO add verify false only for dev env.
$client = new Client(['verify' => false,]);
$client = new Client($this->kernelEnv !== 'prod' ? ['verify' => false] : []);

try {
if ($this->debug === true) {
Expand Down
3 changes: 1 addition & 2 deletions src/Api/RestClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ public function query($endpoint, $operation, ...$input)
->setApiKeyPrefix('Authorization', 'Bearer')
->setHost($this->configuration->getBaseUrl());

// TODO add verify false only for dev env.
$apiInstance = new $endpoint(new Client(['verify' => false]), $config);
$apiInstance = new $endpoint(new Client($this->kernelEnv !== 'prod' ? ['verify' => false] : []), $config);

try {
if ($this->debug === true) {
Expand Down
1 change: 1 addition & 0 deletions src/Resources/config/services/api.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<argument type="service" id="Gally\ShopwarePlugin\Api\AuthenticationTokenProvider" />
<argument type="service" id="Gally\ShopwarePlugin\Service\Configuration" />
<argument type="service" id="logger"/>
<argument>%kernel.environment%</argument>
</service>
<service id="Gally\ShopwarePlugin\Api\RestClient" parent="Gally\ShopwarePlugin\Api\AbstractClient"/>
<service id="Gally\ShopwarePlugin\Api\GraphQlClient" parent="Gally\ShopwarePlugin\Api\AbstractClient"/>
Expand Down
4 changes: 3 additions & 1 deletion src/Search/ProductSearchBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ public function __construct(

public function build(Request $request, Criteria $criteria, SalesChannelContext $context): void
{
if (!$this->configuration->isActive($context->getSalesChannelId())) {
if (!$this->configuration->isActive($context->getSalesChannelId())
|| $request->getPathInfo() === '/suggest' // Gally does not handle suggest request yet
) {
$this->decorated->build($request, $criteria, $context);
}

Expand Down

0 comments on commit c1e09b2

Please sign in to comment.