Skip to content

Commit

Permalink
Merge pull request Smile-SA#38 from Elastic-Suite/feat-ESP-90-Columns
Browse files Browse the repository at this point in the history
[Campaign Optimizer] Add columns in optimizer grid #ESP-90
  • Loading branch information
romainruaud authored Apr 1, 2021
2 parents 095c255 + 6db52c6 commit be1576b
Show file tree
Hide file tree
Showing 7 changed files with 235 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
use Smile\ElasticsuiteAbCampaign\Api\Data\CampaignInterface;
use Smile\ElasticsuiteAbCampaign\Api\Data\CampaignOptimizerInterface;
use Smile\ElasticsuiteCatalogOptimizer\Api\Data\OptimizerInterface;
use Smile\ElasticsuiteCatalogOptimizer\Model\ResourceModel\Optimizer\Collection as OptimizerCollection;
use Zend_Db_Expr;

/**
Expand Down Expand Up @@ -141,6 +143,37 @@ public function saveCampaignOptimizer(int $campaignId, array $optimizerIds, stri
}
}

/**
* Add campaign data to optimizer collection.
*
* @param OptimizerCollection $optimizerCollection Optimizer collection
* @return OptimizerCollection
*/
public function addCampaignDataToOptimizerCollection(OptimizerCollection $optimizerCollection): OptimizerCollection
{
if (!$optimizerCollection->hasFlag('campaign_data')) {
$optimizerCollection->getSelect()
->joinLeft(
['campaign_optimizer' => $optimizerCollection->getTable(CampaignOptimizerInterface::TABLE_NAME)],
'main_table.' . OptimizerInterface::OPTIMIZER_ID
. ' = campaign_optimizer.' . CampaignOptimizerInterface::OPTIMIZER_ID,
[]
)
->joinLeft(
['campaign' => $optimizerCollection->getTable(CampaignInterface::TABLE_NAME)],
'campaign_optimizer.' . CampaignOptimizerInterface::CAMPAIGN_ID
. ' = campaign.' . CampaignInterface::CAMPAIGN_ID,
[
'campaign_name' => 'campaign.' . CampaignInterface::NAME,
'campaign_status' => 'campaign.' . CampaignInterface::STATUS,
]
);
$optimizerCollection->setFlag('campaign_data', true);
}

return $optimizerCollection;
}

/**
* @SuppressWarnings(PHPMD.CamelCaseMethodName)
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?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 Pierre LE MAGUER <[email protected]>
* @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\Ui\DataProvider\Optimizer;

use Magento\Framework\Data\Collection;
use Magento\Ui\DataProvider\AddFieldToCollectionInterface;
use Smile\ElasticsuiteCatalogOptimizer\Model\ResourceModel\Optimizer\Collection as OptimizerCollection;
use Smile\ElasticsuiteAbCampaign\Model\ResourceModel\Campaign\Optimizer as CampaignOptimizerResource;

/**
* Class AddCampaignDataToCollection
*
* @category Smile
* @package Smile\ElasticsuiteAbCampaign
* @author Pierre Le Maguer <[email protected]>
*/
class AddCampaignDataToCollection implements AddFieldToCollectionInterface
{
/**
* @var CampaignOptimizerResource
*/
private $campaignOptimizerResource;

/**
* AddCampaignDataToCollection constructor
*
* @param CampaignOptimizerResource $campaignOptimizerResource Campaign optimizer resource
*/
public function __construct(CampaignOptimizerResource $campaignOptimizerResource)
{
$this->campaignOptimizerResource = $campaignOptimizerResource;
}

/**
* {@inheritdoc}
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function addField(Collection $collection, $field, $condition = null)
{
/** @var OptimizerCollection $collection */
$this->campaignOptimizerResource->addCampaignDataToOptimizerCollection($collection);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?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 Pierre LE MAGUER <[email protected]>
* @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\Ui\DataProvider\Optimizer;

use Magento\Framework\Data\Collection;
use Magento\Ui\DataProvider\AddFilterToCollectionInterface;
use Smile\ElasticsuiteCatalogOptimizer\Model\ResourceModel\Optimizer\Collection as OptimizerCollection;
use Smile\ElasticsuiteAbCampaign\Model\ResourceModel\Campaign\Optimizer as CampaignOptimizerResource;

/**
* Class AddCampaignFilterToCollection
*
* @category Smile
* @package Smile\ElasticsuiteAbCampaign
* @author Pierre Le Maguer <[email protected]>
*/
class AddCampaignFilterToCollection implements AddFilterToCollectionInterface
{
/**
* @var CampaignOptimizerResource
*/
private $campaignOptimizerResource;

/**
* AddCampaignDataToCollection constructor
*
* @param CampaignOptimizerResource $campaignOptimizerResource Campaign optimizer resource
*/
public function __construct(CampaignOptimizerResource $campaignOptimizerResource)
{
$this->campaignOptimizerResource = $campaignOptimizerResource;
}

/**
* {@inheritdoc}
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function addFilter(Collection $collection, $field, $condition = null)
{
/** @var OptimizerCollection $collection */
$this->campaignOptimizerResource->addCampaignDataToOptimizerCollection($collection);
switch ($field) {
case 'campaign_name':
if (isset($condition['like'])) {
$collection->getSelect()->where('campaign.name like ?', $condition['like']);
}
break;
case 'campaign_status':
if (isset($condition['in'])) {
$collection->getSelect()->where('campaign.status in (?)', $condition['in']);
}
break;
}
}
}
14 changes: 14 additions & 0 deletions src/module-elasticsuite-ab-campaign/etc/adminhtml/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,18 @@
<type name="Smile\ElasticsuiteCatalogOptimizer\Ui\Component\Listing\Column\OptimizerActions">
<plugin name="restrain_optimizer_actions" type="Smile\ElasticsuiteAbCampaign\Plugin\Adminhtml\OptimizerUiListingActionsPlugin"/>
</type>

<!-- Add campaign data and filter to optimizer ui collection -->
<type name="Smile\ElasticsuiteCatalogOptimizer\Ui\Component\Optimizer\Listing\DataProvider">
<arguments>
<argument name="addFieldStrategies" xsi:type="array">
<item name="campaign_name" xsi:type="object">Smile\ElasticsuiteAbCampaign\Ui\DataProvider\Optimizer\AddCampaignDataToCollection</item>
<item name="campaign_status" xsi:type="object">Smile\ElasticsuiteAbCampaign\Ui\DataProvider\Optimizer\AddCampaignDataToCollection</item>
</argument>
<argument name="addFilterStrategies" xsi:type="array">
<item name="campaign_name" xsi:type="object">Smile\ElasticsuiteAbCampaign\Ui\DataProvider\Optimizer\AddCampaignFilterToCollection</item>
<item name="campaign_status" xsi:type="object">Smile\ElasticsuiteAbCampaign\Ui\DataProvider\Optimizer\AddCampaignFilterToCollection</item>
</argument>
</arguments>
</type>
</config>
2 changes: 2 additions & 0 deletions src/module-elasticsuite-ab-campaign/i18n/en_US.csv
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,5 @@
"Scenario B","Scenario B"
"You saved no optimizer linked to the campaign %1.","You saved no optimizer linked to the campaign %1."
"You can edit an optimizer linked to a running campaign only on the campaign page.","You can edit an optimizer linked to a running campaign only on the campaign page."
"Campaign Status","Campaign Status"
"Campaign Name","Campaign Name"
2 changes: 2 additions & 0 deletions src/module-elasticsuite-ab-campaign/i18n/fr_FR.csv
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,5 @@
"Scenario B","Scénario B"
"You saved no optimizer linked to the campaign %1.","Vous n'avez enregistré aucun optimiseur pour la campagne %1."
"You can edit an optimizer linked to a running campaign only on the campaign page.","Vous ne pouvez modifier un optimiseur lié à une campagne seulement sur la page d'édition de la campagne."
"Campaign Status","Statut de la campagne"
"Campaign Name","Nom de la campagne"
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* ElasticsuiteAbCampaign listing UI Component
*
* 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 Pierre Le Maguer <[email protected]>
* @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.
*/
-->
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<columns name="smile_elasticsuite_catalog_optimizer_columns">
<column name="campaign_name">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="filter" xsi:type="string">text</item>
<item name="add_field" xsi:type="boolean">true</item>
<item name="label" xsi:type="string" translate="true">Campaign Name</item>
<item name="sortOrder" xsi:type="number">55</item>
</item>
</argument>
</column>
<column name="campaign_status">
<argument name="data" xsi:type="array">
<item name="options" xsi:type="array">
<item name="draft" xsi:type="array">
<item name="value" xsi:type="string">draft</item>
<item name="label" xsi:type="string" translate="true">Draft</item>
</item>
<item name="published" xsi:type="array">
<item name="value" xsi:type="string">published</item>
<item name="label" xsi:type="string" translate="true">Published</item>
</item>
<item name="complete" xsi:type="array">
<item name="value" xsi:type="string">complete</item>
<item name="label" xsi:type="string" translate="true">Complete</item>
</item>
</item>
<item name="config" xsi:type="array">
<item name="filter" xsi:type="string">select</item>
<item name="component" xsi:type="string">Magento_Ui/js/grid/columns/select</item>
<item name="dataType" xsi:type="string">select</item>
<item name="add_field" xsi:type="boolean">true</item>
<item name="label" xsi:type="string" translate="true">Campaign Status</item>
<item name="sortOrder" xsi:type="number">56</item>
</item>
</argument>
</column>
</columns>
</listing>

0 comments on commit be1576b

Please sign in to comment.