Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions Block/Adminhtml/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Clerk\Clerk\Model\Config;
use Magento\Backend\Block\Template;
use Magento\Backend\Block\Template\Context;
use Magento\Store\Api\StoreRepositoryInterface;
use Magento\Store\Model\ScopeInterface;

Expand All @@ -17,6 +18,11 @@ class Dashboard extends Template
*/
private $storeRepository;

/**
* @param Context $context
* @param StoreRepositoryInterface $storeRepository
* @param array $data
*/
public function __construct(Template\Context $context, StoreRepositoryInterface $storeRepository, array $data = [])
{
$this->storeRepository = $storeRepository;
Expand Down Expand Up @@ -52,7 +58,7 @@ public function getEmbedUrl()

$storePart = $this->getStorePart($publicKey);

return sprintf('https://my.clerk.io/#/store/%s/analytics/%s?key=%s&private_key=%s&embed=yes', $storePart, $this->type, $publicKey, $privateKey);
return sprintf("https://my.clerk.io/#/store/%s/analytics/%s?key=%s&private_key=%s&embed=yes", $storePart, $this->type, $publicKey, $privateKey);
}

/**
Expand All @@ -76,7 +82,7 @@ public function getStore()
/**
* Get first 8 characters of public key
*
* @param $publicKey
* @param string $publicKey
* @return string
*/
protected function getStorePart($publicKey)
Expand Down
4 changes: 4 additions & 0 deletions Block/Adminhtml/Insights/Audience.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,9 @@

class Audience extends Dashboard
{

/**
* @var string
*/
protected $type = 'audience';
}
3 changes: 3 additions & 0 deletions Block/Adminhtml/Insights/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@

class Email extends Dashboard
{
/**
* @var string
*/
protected $type = 'email';
}
3 changes: 3 additions & 0 deletions Block/Adminhtml/Insights/Recommendations.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@

class Recommendations extends Dashboard
{
/**
* @var string
*/
protected $type = 'recommendations';
}
3 changes: 3 additions & 0 deletions Block/Adminhtml/Insights/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@

class Search extends Dashboard
{
/**
* @var string
*/
protected $type = 'search';
}
66 changes: 25 additions & 41 deletions Block/Adminhtml/System/Config/Field/FacetTitles.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,75 +2,46 @@

namespace Clerk\Clerk\Block\Adminhtml\System\Config\Field;

use Clerk\Clerk\Helper\Config as ConfigHelper;
use Clerk\Clerk\Model\Config;
use Magento\Backend\Block\Template\Context;
use Magento\Config\Block\System\Config\Form\Field;
use Magento\Store\Model\ScopeInterface;
use Magento\Framework\Data\Form\Element\AbstractElement;
use Magento\Framework\Exception\NoSuchEntityException;

class FacetTitles extends Field
{
/**
* @var RequestInterface
*/
protected $requestInterface;

/**
* FacetTitles constructor.
* @param \Magento\Backend\Block\Template\Context $context
* @param ConfigHelper $configHelper
* @param Context $context
* @param array $data
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Framework\App\RequestInterface $requestInterface,
ConfigHelper $configHelper,
Context $context,
array $data = []
) {
$this->requestInterface = $requestInterface;
$this->configHelper = $configHelper;
$this->setTemplate('Clerk_Clerk::facettitles.phtml');
parent::__construct($context, $data);
}

/**
* Get html for element
*
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
* @return string
*/
protected function _getElementHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element)
{
$this->setElement($element);

$html = '';

$html .= $this->toHtml();

return $html;
}

/**
* Get configured facet attributes
*/
public function getConfiguredAttributes()
{
$_params = $this->requestInterface->getParams();
$scope_id = '0';
$scope = 'default';
if (array_key_exists('website', $_params)) {
$scope = 'website';
$scope_id = $_params[$scope];
}
if (array_key_exists('store', $_params)) {
$scope = 'store';
$scope_id = $_params[$scope];
}
$attributes = $this->_scopeConfig->getValue(Config::XML_PATH_FACETED_SEARCH_ATTRIBUTES, $scope, $scope_id);
$configuredAttributes = is_string($attributes) ? explode(',', $attributes) : [];

return $configuredAttributes;
$attributes = $this->configHelper->getValueAdmin(Config::XML_PATH_FACETED_SEARCH_ATTRIBUTES);
return is_string($attributes) ? explode(',', $attributes) : [];
}

/**
* Get label for current scope
*
* @return string
* @throws NoSuchEntityException
*/
public function getScopeLabel()
{
Expand All @@ -90,4 +61,17 @@ public function getStoreId()

return $this->getData('store_id');
}

/**
* Get html for element
*
* @param AbstractElement $element
* @return string
*/
protected function _getElementHtml(AbstractElement $element)
{
$this->setElement($element);

return $this->toHtml();
}
}
41 changes: 14 additions & 27 deletions Block/Adminhtml/System/Config/Field/MultiselectFacetAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,42 @@

namespace Clerk\Clerk\Block\Adminhtml\System\Config\Field;

use Clerk\Clerk\Helper\Config as ConfigHelper;
use Clerk\Clerk\Model\Config;
use Magento\Backend\Block\Template\Context;
use Magento\Config\Block\System\Config\Form\Field;
use Magento\Store\Model\ScopeInterface;
use Magento\Framework\Data\Form\Element\AbstractElement;

class MultiselectFacetAttributes extends Field
{

/**
* @var RequestInterface
*/
protected $requestInterface;

/**
* FacetTitles constructor.
* @param \Magento\Backend\Block\Template\Context $context
* @param ConfigHelper $configHelper
* @param Context $context
* @param array $data
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Framework\App\RequestInterface $requestInterface,
array $data = []
) {
$this->requestInterface = $requestInterface;
ConfigHelper $configHelper,
Context $context,
array $data = []
)
{
parent::__construct($context, $data);
$this->configHelper = $configHelper;
}

/**
* Get element html if facet attributes are configured
*
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
* @param AbstractElement $element
* @return string
*/
public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element)
public function render(AbstractElement $element)
{
$_params = $this->requestInterface->getParams();
$scope_id = '0';
$scope = 'default';
if (array_key_exists('website', $_params)) {
$scope = 'website';
$scope_id = $_params[$scope];
}
if (array_key_exists('store', $_params)) {
$scope = 'store';
$scope_id = $_params[$scope];
}
if ($this->_scopeConfig->getValue(Config::XML_PATH_FACETED_SEARCH_ATTRIBUTES, $scope, $scope_id)) {
if ($this->configHelper->getValueAdmin(Config::XML_PATH_FACETED_SEARCH_ATTRIBUTES)) {
return parent::render($element);
}

return '';
}
}
73 changes: 31 additions & 42 deletions Block/Adminhtml/System/Config/Fieldset/FacetedSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@

namespace Clerk\Clerk\Block\Adminhtml\System\Config\Fieldset;

use Clerk\Clerk\Helper\Config as ConfigHelper;
use Clerk\Clerk\Model\Api;
use Clerk\Clerk\Model\Config;
use Magento\Config\Model\ResourceModel\Config as SystemConfig;
use Exception;
use Magento\Backend\Block\Context;
use Magento\Backend\Model\Auth\Session;
use Magento\Config\Block\System\Config\Form\Fieldset;
use Magento\Config\Model\ResourceModel\Config as SystemConfig;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\Data\Form\Element\AbstractElement;
use Magento\Store\Model\ScopeInterface;
use Magento\Framework\View\Helper\Js;

class FacetedSearch extends Fieldset
{
Expand All @@ -29,26 +34,30 @@ class FacetedSearch extends Fieldset
/**
* FacetedSearch constructor.
*
* @param \Magento\Backend\Block\Context $context
* @param \Magento\Backend\Model\Auth\Session $authSession
* @param \Magento\Framework\View\Helper\Js $jsHelper
* @param \Magento\Framework\App\RequestInterface $requestInterface
* @param ConfigHelper $configHelper
* @param Context $context
* @param Session $authSession
* @param Js $jsHelper
* @param RequestInterface $requestInterface
* @param Api $api
* @param SystemConfig $systemConfig
* @param array $data
*/
public function __construct(
\Magento\Backend\Block\Context $context,
\Magento\Backend\Model\Auth\Session $authSession,
\Magento\Framework\View\Helper\Js $jsHelper,
\Magento\Framework\App\RequestInterface $requestInterface,
Api $api,
SystemConfig $systemConfig,
array $data = []
) {
ConfigHelper $configHelper,
Context $context,
Session $authSession,
Js $jsHelper,
RequestInterface $requestInterface,
Api $api,
SystemConfig $systemConfig,
array $data = []
)
{
$this->api = $api;
$this->systemConfig = $systemConfig;
$this->requestInterface = $requestInterface;

$this->configHelper = $configHelper;
parent::__construct($context, $authSession, $jsHelper, $data);
}

Expand All @@ -57,16 +66,17 @@ public function __construct(
*
* @param AbstractElement $element
* @return string
* @throws Exception
*/
public function render(AbstractElement $element)
{
$this->setElement($element);
$header = $this->_getHeaderHtml($element);

if (! $this->isConfigured()) {
if (!$this->isConfigured()) {
$elements = __('Public and private key must be set in order to enable faceted search');
} else {
if (! $this->keysValid()) {
if (!$this->keysValid()) {
$elements = __('Public or private key invalid');
} else {
$elements = $this->_getChildrenElementsHtml($element);
Expand All @@ -86,40 +96,19 @@ public function render(AbstractElement $element)
*/
private function isConfigured()
{
$_params = $this->requestInterface->getParams();
$scope_id = '0';
$scope = 'default';
if (array_key_exists('website', $_params)) {
$scope = 'website';
$scope_id = $_params[$scope];
}
if (array_key_exists('store', $_params)) {
$scope = 'store';
$scope_id = $_params[$scope];
}
return (bool) ($this->_scopeConfig->getValue(Config::XML_PATH_PUBLIC_KEY, $scope, $scope_id) && $this->_scopeConfig->getValue(Config::XML_PATH_PRIVATE_KEY, $scope, $scope_id));
return $this->configHelper->getValueAdmin(Config::XML_PATH_PUBLIC_KEY) && $this->configHelper->getValueAdmin(Config::XML_PATH_PRIVATE_KEY);
}

/**
* Determine if public & private keys are valid
*
* @return bool
* @throws Exception
*/
private function keysValid()
{
$_params = $this->requestInterface->getParams();
$scope_id = '0';
$scope = 'default';
if (array_key_exists('website', $_params)) {
$scope = 'website';
$scope_id = $_params[$scope];
}
if (array_key_exists('store', $_params)) {
$scope = 'store';
$scope_id = $_params[$scope];
}
$publicKey = $this->_scopeConfig->getValue(Config::XML_PATH_PUBLIC_KEY, $scope, $scope_id);
$privateKey = $this->_scopeConfig->getValue(Config::XML_PATH_PRIVATE_KEY, $scope, $scope_id);
$publicKey = $this->configHelper->getValueAdmin(Config::XML_PATH_PUBLIC_KEY);
$privateKey = $this->configHelper->getValueAdmin(Config::XML_PATH_PRIVATE_KEY);

$keysValid = json_decode($this->api->keysValid($publicKey, $privateKey));

Expand Down
Loading