forked from Smile-SA/elasticsuite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Smile-SA#47 from Elastic-Suite/feat-ES-19-ab-testi…
…ng-for-optimizers [Campaign] Apply the current scenario optimizers #ESP-95
- Loading branch information
Showing
29 changed files
with
1,704 additions
and
106 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
src/module-elasticsuite-ab-campaign/Api/CampaignCookieManagerInterface.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,29 @@ | ||
<?php | ||
/** | ||
* 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. | ||
*/ | ||
|
||
|
||
namespace Smile\ElasticsuiteAbCampaign\Api; | ||
|
||
/** | ||
* Interface CampaignCookieManagerInterface | ||
* | ||
* @category Smile | ||
* @package Smile\ElasticsuiteAbCampaign | ||
*/ | ||
|
||
interface CampaignCookieManagerInterface | ||
{ | ||
|
||
} |
52 changes: 52 additions & 0 deletions
52
src/module-elasticsuite-ab-campaign/Api/CampaignServiceInterface.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,52 @@ | ||
<?php | ||
/** | ||
* 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. | ||
*/ | ||
|
||
namespace Smile\ElasticsuiteAbCampaign\Api; | ||
|
||
use Smile\ElasticsuiteAbCampaign\Api\Data\CampaignInterface; | ||
|
||
/** | ||
* Campaign service interface. | ||
* | ||
* @category Smile | ||
* @package Smile\ElasticsuiteAbCampaign | ||
*/ | ||
interface CampaignServiceInterface | ||
{ | ||
const CONTEXT_AB_CAMPAIGN = 'es_ab_campaign'; | ||
|
||
const NO_SCENARIO = 'N'; | ||
|
||
/** | ||
* Returns true if there is any active campaign. | ||
* | ||
* @return bool | ||
*/ | ||
public function hasActiveCampaigns(): bool; | ||
|
||
/** | ||
* Returns the active campaigns if there are some. | ||
* | ||
* @return CampaignInterface[] | ||
*/ | ||
public function getActiveCampaigns(): array; | ||
|
||
/** | ||
* Returns randomized scenarios identifier for active campaigns. | ||
* | ||
* @return array | ||
*/ | ||
public function getCampaignScenarios(): array; | ||
} |
32 changes: 32 additions & 0 deletions
32
src/module-elasticsuite-ab-campaign/Api/CampaignUserContextInterface.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,32 @@ | ||
<?php | ||
/** | ||
* 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. | ||
*/ | ||
|
||
namespace Smile\ElasticsuiteAbCampaign\Api; | ||
|
||
/** | ||
* Interface CampaignUserInterface | ||
* | ||
* @category Smile | ||
* @package Smile\ElasticsuiteAbCampaign | ||
*/ | ||
interface CampaignUserContextInterface | ||
{ | ||
/** | ||
* Extract user scenarios context from environment. | ||
* | ||
* @return array | ||
*/ | ||
public function getUserScenarios(): array; | ||
} |
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,81 @@ | ||
<?php | ||
/** | ||
* 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. | ||
*/ | ||
|
||
namespace Smile\ElasticsuiteAbCampaign\Block; | ||
|
||
use Smile\ElasticsuiteTracker\Block\Config as TrackerConfig; | ||
use Magento\Framework\UrlInterface; | ||
|
||
/** | ||
* Class Config | ||
* | ||
* @category Smile | ||
* @package Smile\ElasticsuiteAbCampaign | ||
* @author Richard Bayet <richard.bayet@smile.fr> | ||
*/ | ||
class Config extends TrackerConfig | ||
{ | ||
/** @var string get/set Campaign Scenarios */ | ||
const BASE_BEACON_URL = 'elasticsuite/campaign/scenarios'; | ||
|
||
/** @var string Campaign(s) scenario cookie name */ | ||
const CAMPAIGNS_COOKIE_NAME = 'AB-CAMPAIGN'; | ||
|
||
/** @var UrlInterface */ | ||
private $urlBuilder; | ||
|
||
/** | ||
* Config constructor. | ||
* @param \Magento\Framework\View\Element\Template\Context $context Template context. | ||
* @param \Magento\Framework\Json\Helper\Data $jsonHelper Json helper. | ||
* @param \Smile\ElasticsuiteTracker\Helper\Data $trackerHelper Tracker helper. | ||
* @param \Magento\Framework\UrlInterface $urlBuilder URL Builder. | ||
* @param array $data Additional data. | ||
*/ | ||
public function __construct( | ||
\Magento\Framework\View\Element\Template\Context $context, | ||
\Magento\Framework\Json\Helper\Data $jsonHelper, | ||
\Smile\ElasticsuiteTracker\Helper\Data $trackerHelper, | ||
\Magento\Framework\UrlInterface $urlBuilder, | ||
array $data = [] | ||
) { | ||
parent::__construct($context, $jsonHelper, $trackerHelper, $data); | ||
$this->urlBuilder = $urlBuilder; | ||
} | ||
|
||
/** | ||
* Get generic tracker and specific campaigns cookie config. | ||
* | ||
* @return array | ||
*/ | ||
public function getCookieConfig() | ||
{ | ||
$config = parent::getCookieConfig(); | ||
|
||
$config['campaigns_cookie_name'] = self::CAMPAIGNS_COOKIE_NAME; | ||
|
||
return $config; | ||
} | ||
|
||
/** | ||
* Retrieve beacon Url | ||
* | ||
* @return string | ||
*/ | ||
public function getBeaconUrl() | ||
{ | ||
return $this->urlBuilder->getRouteUrl(self::BASE_BEACON_URL); | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
src/module-elasticsuite-ab-campaign/Block/Tracker/Variables/Page/Campaign.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,76 @@ | ||
<?php | ||
/** | ||
* 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 Botis <botis@smile.fr> | ||
* @copyright 2021 Smile | ||
* @license Open Software License ("OSL") v. 3.0 | ||
*/ | ||
|
||
namespace Smile\ElasticsuiteAbCampaign\Block\Tracker\Variables\Page; | ||
|
||
use Magento\Framework\App\Http\Context as HttpContext; | ||
use Magento\Framework\View\Element\Template; | ||
use Smile\ElasticsuiteAbCampaign\Api\CampaignServiceInterface; | ||
use Smile\ElasticsuiteTracker\Block\Variables\Page\AbstractBlock; | ||
|
||
/** | ||
* Campaign variables block for page tracking, exposes all campaign tracking variables. | ||
* | ||
* @category Smile | ||
* @package Smile\ElasticsuiteAbCampaign | ||
* @author Botis <botis@smile.fr> | ||
*/ | ||
class Campaign extends AbstractBlock | ||
{ | ||
/** @var HttpContext */ | ||
private $httpContext; | ||
|
||
/** | ||
* Set the default template for page variable blocks | ||
* | ||
* @param Template\Context $context The template context | ||
* @param \Magento\Framework\Json\Helper\Data $jsonHelper The Magento's JSON Helper | ||
* @param \Smile\ElasticsuiteTracker\Helper\Data $trackerHelper The Smile Tracker helper | ||
* @param \Magento\Framework\Registry $registry Magento Core Registry | ||
* @param HttpContext $httpContext HTTP context | ||
* @param array $data The block data | ||
*/ | ||
public function __construct( | ||
Template\Context $context, | ||
\Magento\Framework\Json\Helper\Data $jsonHelper, | ||
\Smile\ElasticsuiteTracker\Helper\Data $trackerHelper, | ||
\Magento\Framework\Registry $registry, | ||
HttpContext $httpContext, | ||
array $data = [] | ||
) { | ||
parent::__construct($context, $jsonHelper, $trackerHelper, $registry, $data); | ||
$this->httpContext = $httpContext; | ||
} | ||
|
||
/** | ||
* Append the campaign data to the tracked variables list. | ||
* | ||
* @return array | ||
*/ | ||
public function getVariables(): array | ||
{ | ||
$campaignVariables = []; | ||
|
||
$scenarios = $this->httpContext->getValue(CampaignServiceInterface::CONTEXT_AB_CAMPAIGN) ?? []; | ||
$itemId = 0; | ||
foreach ($scenarios as $scenario) { | ||
$prefix = 'ab_campaign.' . $itemId; | ||
$campaignVariables[$prefix . '.id'] = $scenario['campaign_id']; | ||
$campaignVariables[$prefix . '.scenario'] = $scenario['scenario_id']; | ||
$itemId++; | ||
} | ||
|
||
return $campaignVariables; | ||
} | ||
} |
43 changes: 0 additions & 43 deletions
43
src/module-elasticsuite-ab-campaign/Block/Variables/Page/Campaign.php
This file was deleted.
Oops, something went wrong.
63 changes: 63 additions & 0 deletions
63
src/module-elasticsuite-ab-campaign/Controller/Campaign/Scenarios.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,63 @@ | ||
<?php | ||
/** | ||
* 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. | ||
*/ | ||
|
||
namespace Smile\ElasticsuiteAbCampaign\Controller\Campaign; | ||
|
||
use Magento\Framework\App\Action\Action; | ||
use Magento\Framework\App\Action\Context; | ||
use Magento\Framework\App\Http\Context as HttpContext; | ||
use Magento\Framework\Controller\ResultFactory; | ||
use Smile\ElasticsuiteAbCampaign\Api\CampaignServiceInterface; | ||
|
||
/** | ||
* Class Scenarios | ||
* | ||
* @category Smile | ||
* @package Smile\ElasticsuiteAbCampaign | ||
* @author Richard Bayet <richard.bayet@smile.fr> | ||
*/ | ||
class Scenarios extends Action | ||
{ | ||
/** @var HttpContext */ | ||
private $httpContext; | ||
|
||
/** @var CampaignServiceInterface */ | ||
private $campaignService; | ||
|
||
/** | ||
* Scenarios constructor. | ||
* | ||
* @param Context $context Context. | ||
* @param HttpContext $httpContext Http context. | ||
* @param CampaignServiceInterface $campaignService Campaigns service. | ||
*/ | ||
public function __construct(Context $context, HttpContext $httpContext, CampaignServiceInterface $campaignService) | ||
{ | ||
parent::__construct($context); | ||
$this->httpContext = $httpContext; | ||
$this->campaignService = $campaignService; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function execute() | ||
{ | ||
$scenarios = $this->campaignService->getCampaignScenarios(); | ||
$this->httpContext->setValue(CampaignServiceInterface::CONTEXT_AB_CAMPAIGN, $scenarios, []); | ||
|
||
return $this->resultFactory->create(ResultFactory::TYPE_JSON)->setData(array_values($scenarios)); | ||
} | ||
} |
Oops, something went wrong.