Skip to content

Commit

Permalink
Merge pull request Smile-SA#68 from Elastic-Suite/feat-ESP-19-ab-test…
Browse files Browse the repository at this point in the history
…ing-rest-graphql

[Campaign][Headless] Retrieve/Apply current scenario #ESP-94 #ESP-103
  • Loading branch information
rbayet authored Sep 23, 2021
2 parents b273c29 + cbb4ba9 commit 783c986
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/module-elasticsuite-ab-campaign/Block/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Config extends TrackerConfig
const BASE_BEACON_URL = 'elasticsuite/campaign/scenarios';

/** @var string Campaign(s) scenario cookie name */
const CAMPAIGNS_COOKIE_NAME = 'AB_CAMPAIGN';
const CAMPAIGNS_COOKIE_NAME = 'AB-CAMPAIGN';

/** @var UrlInterface */
private $urlBuilder;
Expand Down
58 changes: 58 additions & 0 deletions src/module-elasticsuite-ab-campaign/Model/Resolver/Campaigns.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php
/**
* DISCLAIMER
* Do not edit or add to this file if you wish to upgrade Smile Elastic Suite to newer
* versions in the future.
*
* @category Smile
* @package Smile\ElasticsuiteAbCampaign
* @author Botis <botis@smile.fr>
* @copyright 2021 Smile
* @license Licensed to Smile-SA. All rights reserved. No warranty, explicit or implicit, provided.
* Unauthorized copying of this file, via any medium, is strictly prohibited.
*/

namespace Smile\ElasticsuiteAbCampaign\Model\Resolver;

use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Query\ResolverInterface;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Smile\ElasticsuiteAbCampaign\Api\CampaignServiceInterface;

/**
* ElasticSuite campaigns resolver.
*
* @category Smile
* @package Smile\ElasticsuiteAbCampaign
* @author Botis <botis@smile.fr>
*/
class Campaigns implements ResolverInterface
{
/**
* @var CampaignServiceInterface
*/
private $campaignService;

/**
* Recommendations constructor.
*
* @param CampaignServiceInterface $campaignService Campaign service.
*/
public function __construct(CampaignServiceInterface $campaignService)
{
$this->campaignService = $campaignService;
}

/**
* {@inheritDoc}
*/
public function resolve(
Field $field,
$context,
ResolveInfo $info,
array $value = null,
array $args = null
) {
return $this->campaignService->getCampaignScenarios();
}
}
2 changes: 1 addition & 1 deletion src/module-elasticsuite-ab-campaign/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
<!-- User context configuration -->
<type name="Smile\ElasticsuiteAbCampaign\Model\CampaignUserContext">
<arguments>
<argument name="headerName" xsi:type="string">AB_CAMPAIGN</argument>
<argument name="headerName" xsi:type="const">Smile\ElasticsuiteAbCampaign\Block\Config::CAMPAIGNS_COOKIE_NAME</argument>
</arguments>
</type>

Expand Down
25 changes: 25 additions & 0 deletions src/module-elasticsuite-ab-campaign/etc/graphql/di.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0"?>
<!--
/**
* Smile\ElasticsuiteAbCampaign frontend dependency injection configuration.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Smile ElasticSuite to newer
* versions in the future.
*
* @category Smile
* @package Smile\ElasticsuiteAbCampaign
* @author Richard BAYET <richard.bayet@smile.fr>
* @copyright 2021 Smile
* @license Licensed to Smile-SA. All rights reserved. No warranty, explicit or implicit, provided.
* Unauthorized copying of this file, via any medium, is strictly prohibited.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<!-- Plugins -->
<type name="Magento\Framework\App\FrontControllerInterface">
<plugin name="elasticsuite-ab-campaign-front-controller-context-dispatch"
type="Smile\ElasticsuiteAbCampaign\Plugin\Framework\App\FrontControllerInterfacePlugin" />
</type>
</config>
8 changes: 8 additions & 0 deletions src/module-elasticsuite-ab-campaign/etc/schema.graphqls
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
type Query {
elasticsuiteAbCampaigns: [AbCampaign] @resolver(class: "Smile\\ElasticsuiteAbCampaign\\Model\\Resolver\\Campaigns") @doc(description: "AB campaigns applied for the current customer.") @cache(cacheable: false)
}

type AbCampaign {
campaign_id: String @doc(description: "Campaign id.")
scenario_id: String @doc(description: "Scenario id.")
}

0 comments on commit 783c986

Please sign in to comment.