diff --git a/.circleci/config.yml b/.circleci/config.yml index 50bfa1b24..a9932ff96 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -41,16 +41,18 @@ shared: &shared name: Before setup command: | echo 'memory_limit = 256M' | sudo tee /usr/local/etc/php/php.ini - wget https://alg.li/algolia-keys && chmod +x algolia-keys + + - run: + name: Get keys from dealer + command: | + if [ "$CIRCLE_PR_REPONAME" ]; then + curl -s https://algoliasearch-client-keygen.herokuapp.com | sh >> $BASH_ENV + fi - run: name: Run tests command: | cd ~/magento_directory/dev/tests/integration - export CI_BUILD_NUM=$CIRCLE_BUILD_NUM - export CI_PROJ_USERNAME=$CIRCLE_PROJECT_USERNAME - export CI_PROJ_REPONAME=$CIRCLE_PROJECT_REPONAME - eval $(~/build_directory/algoliasearch-magento-2/algolia-keys export) sudo service elasticsearch start # for some reasons has to be launched with the step sleep 10 php -dmemory_limit=-1 ../../../vendor/bin/phpunit --debug ../../../vendor/algolia/algoliasearch-magento-2/Test diff --git a/Block/Adminhtml/Category/Merchandising.php b/Block/Adminhtml/Category/Merchandising.php index 45534ad95..5630b36fb 100644 --- a/Block/Adminhtml/Category/Merchandising.php +++ b/Block/Adminhtml/Category/Merchandising.php @@ -4,7 +4,6 @@ use Algolia\AlgoliaSearch\Helper\ConfigHelper; use Algolia\AlgoliaSearch\Helper\Data; -use Algolia\AlgoliaSearch\Helper\ProxyHelper; use Magento\Backend\Block\Template\Context; use Magento\Catalog\Model\Category; use Magento\Framework\Registry; @@ -23,9 +22,6 @@ class Merchandising extends \Magento\Backend\Block\Template /** @var Data */ private $coreHelper; - /** @var ProxyHelper */ - private $proxyHelper; - /** @var \Magento\Store\Model\StoreManagerInterface */ private $storeManager; @@ -34,7 +30,6 @@ class Merchandising extends \Magento\Backend\Block\Template * @param Registry $registry * @param ConfigHelper $configHelper * @param Data $coreHelper - * @param ProxyHelper $proxyHelper * @param array $data */ public function __construct( @@ -42,13 +37,11 @@ public function __construct( Registry $registry, ConfigHelper $configHelper, Data $coreHelper, - ProxyHelper $proxyHelper, array $data = [] ) { $this->registry = $registry; $this->configHelper = $configHelper; $this->coreHelper = $coreHelper; - $this->proxyHelper = $proxyHelper; $this->storeManager = $context->getStoreManager(); parent::__construct($context, $data); @@ -89,20 +82,6 @@ public function getCoreHelper() return $this->coreHelper; } - /** @return bool */ - public function isQueryRulesEnabled() - { - $info = $this->proxyHelper->getInfo(ProxyHelper::INFO_TYPE_QUERY_RULES); - - // In case the call to API proxy fails, - // be "nice" and return true - if ($info && array_key_exists('query_rules', $info)) { - return $info['query_rules']; - } - - return true; - } - /** * @throws \Magento\Framework\Exception\NoSuchEntityException * diff --git a/Block/Adminhtml/LandingPage/SearchConfiguration.php b/Block/Adminhtml/LandingPage/SearchConfiguration.php index 2c3055958..edb1584c0 100644 --- a/Block/Adminhtml/LandingPage/SearchConfiguration.php +++ b/Block/Adminhtml/LandingPage/SearchConfiguration.php @@ -4,7 +4,6 @@ use Algolia\AlgoliaSearch\Helper\ConfigHelper; use Algolia\AlgoliaSearch\Helper\Data; -use Algolia\AlgoliaSearch\Helper\ProxyHelper; use Algolia\AlgoliaSearch\Model\LandingPage; use Magento\Backend\Block\Template\Context; use Magento\Framework\Registry; @@ -23,9 +22,6 @@ class SearchConfiguration extends \Magento\Backend\Block\Template /** @var Data */ private $coreHelper; - /** @var ProxyHelper */ - protected $proxyHelper; - /** @var int */ protected $planLevel; @@ -34,7 +30,6 @@ class SearchConfiguration extends \Magento\Backend\Block\Template * @param Registry $registry * @param ConfigHelper $configHelper * @param Data $coreHelper - * @param ProxyHelper $proxyHelper * @param array $data */ public function __construct( @@ -42,13 +37,11 @@ public function __construct( Registry $registry, ConfigHelper $configHelper, Data $coreHelper, - ProxyHelper $proxyHelper, array $data = [] ) { $this->registry = $registry; $this->configHelper = $configHelper; $this->coreHelper = $coreHelper; - $this->proxyHelper = $proxyHelper; parent::__construct($context, $data); } @@ -70,20 +63,4 @@ public function getCoreHelper() { return $this->coreHelper; } - - /** @return int */ - public function getPlanLevel() - { - if ($this->planLevel == null) { - $planLevel = 1; - $planLevelInfo = $this->proxyHelper->getInfo(ProxyHelper::INFO_TYPE_PLAN_LEVEL); - - if (isset($planLevelInfo['plan_level'])) { - $planLevel = (int) $planLevelInfo['plan_level']; - } - $this->planLevel = $planLevel; - } - - return $this->planLevel; - } } diff --git a/Block/Adminhtml/Query/Merchandising.php b/Block/Adminhtml/Query/Merchandising.php index 9fa45ddc8..c4d378831 100644 --- a/Block/Adminhtml/Query/Merchandising.php +++ b/Block/Adminhtml/Query/Merchandising.php @@ -4,7 +4,6 @@ use Algolia\AlgoliaSearch\Helper\ConfigHelper; use Algolia\AlgoliaSearch\Helper\Data; -use Algolia\AlgoliaSearch\Helper\ProxyHelper; use Algolia\AlgoliaSearch\Model\Query; use Magento\Backend\Block\Template\Context; use Magento\Framework\Registry; @@ -23,9 +22,6 @@ class Merchandising extends \Magento\Backend\Block\Template /** @var Data */ private $coreHelper; - /** @var ProxyHelper */ - private $proxyHelper; - /** @var \Magento\Store\Model\StoreManagerInterface */ private $storeManager; @@ -34,7 +30,6 @@ class Merchandising extends \Magento\Backend\Block\Template * @param Registry $registry * @param ConfigHelper $configHelper * @param Data $coreHelper - * @param ProxyHelper $proxyHelper * @param array $data */ public function __construct( @@ -42,13 +37,11 @@ public function __construct( Registry $registry, ConfigHelper $configHelper, Data $coreHelper, - ProxyHelper $proxyHelper, array $data = [] ) { $this->registry = $registry; $this->configHelper = $configHelper; $this->coreHelper = $coreHelper; - $this->proxyHelper = $proxyHelper; $this->storeManager = $context->getStoreManager(); parent::__construct($context, $data); @@ -72,20 +65,6 @@ public function getCoreHelper() return $this->coreHelper; } - /** @return bool */ - public function isQueryRulesEnabled() - { - $info = $this->proxyHelper->getInfo(ProxyHelper::INFO_TYPE_QUERY_RULES); - - // In case the call to API proxy fails, - // be "nice" and return true - if ($info && array_key_exists('query_rules', $info)) { - return $info['query_rules']; - } - - return true; - } - /** * @throws \Magento\Framework\Exception\NoSuchEntityException * diff --git a/Block/Configuration.php b/Block/Configuration.php index c43ce4572..468382e56 100755 --- a/Block/Configuration.php +++ b/Block/Configuration.php @@ -286,13 +286,7 @@ public function getConfiguration() private function areCategoriesInFacets($facets) { - foreach ($facets as $facet) { - if ($facet['attribute'] === 'categories') { - return true; - } - } - - return false; + return in_array('categories', array_column($facets, 'attribute')); } private function getUrlTrackedParameters() @@ -336,28 +330,16 @@ private function isLandingPage() private function getLandingPageId() { - if (!$this->isLandingPage()) { - return ''; - } - - return $this->getCurrentLandingPage()->getId(); + return $this->isLandingPage() ? $this->getCurrentLandingPage()->getId() : ''; } private function getLandingPageQuery() { - if (!$this->isLandingPage()) { - return ''; - } - - return $this->getCurrentLandingPage()->getQuery(); + return $this->isLandingPage() ? $this->getCurrentLandingPage()->getQuery() : ''; } private function getLandingPageConfiguration() { - if (!$this->isLandingPage()) { - return json_encode([]); - } - - return $this->getCurrentLandingPage()->getConfiguration(); + return $this->isLandingPage() ? $this->getCurrentLandingPage()->getConfiguration() : json_encode([]); } } diff --git a/Block/System/Form/Field/Logo.php b/Block/System/Form/Field/Logo.php deleted file mode 100644 index 6c6f7a278..000000000 --- a/Block/System/Form/Field/Logo.php +++ /dev/null @@ -1,46 +0,0 @@ -proxyHelper = $proxyHelper; - } - - protected function _getElementHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element) - { - if ($this->showLogo()) { - $element->setDisabled(true); - $element->setValue(0); - - $comment = __('Do you want to remove Algolia logo from autocomplete menu?') - . '
' - . __('Only paid customers are allowed to remove the logo.'); - - $element->setComment($comment); - } - - return parent::_getElementHtml($element); - } - - /** - * @return bool - */ - public function showLogo() - { - $info = $this->proxyHelper->getClientConfigurationData(); - - return isset($info['require_logo']) && $info['require_logo'] == 1; - } -} diff --git a/CHANGELOG.md b/CHANGELOG.md index f383f0023..668b77b69 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,37 @@ # CHANGE LOG +## 3.2.0 + +### UPDATES +- Update module sequence and indexers (#1132) +- Add additional attributes for customer groups (#1144) +- Add priceRanges back to uistate (#1151) +- Set visibility of getTaxPrice() to public in ProductWithoutChildren (#1159) (@JeroenVanLeusden) +- Improve check: and try to handle URL by URL rewrites if request path is NULL. (#1149) (@vmalyk) +- Unfilter getCoreCategories() from private getCategoryById() (#1154) +- Add ability to change region for Analytics call (#1131) (@bchatard) + +### FIXES +- Add missing indexName for autocomplete sections (#1133) +- Add check if color object is defined for adaptive images (#1135) +- Add small change on category indexing for Enterprise Edition (#1136) +- Refactor loops and fix analytics overview issues (#1137) +- Fix missing 'out of' translation on search results page (#1139) (@NickdeK) +- Restore query value in custom instant search box (#1142) (@vmalyk) +- Fix instantsearch rangeInput labels (#1148) +- Recalculate special price if zero default pricing (#1160) +- Add missing label for queue method rebuildCategoryIndex (#1152) (@tezlopchan) +- Fix max original price for product with children (#1155) (@valeriish) +- Store scope category merchandising based on store_id param (#1156) +- Fix Subproduct Image Data (#1157) +- Add try/catch to add to cart push events (#1158) +- Fix for BE side renderting and caching 2 types of content (#1161) (@sudma) +- Fix: categories not included filtering on product listing (#1163) +- Fix: removing old feature checking for C&C that triggers deprecated endpoint (#1164) + +### TOOLING +- Update CI testing (#1140) + ## 3.1.0 ### UPDATES diff --git a/Controller/Adminhtml/Landingpage/AbstractAction.php b/Controller/Adminhtml/Landingpage/AbstractAction.php index 70b92482a..05d7c8559 100644 --- a/Controller/Adminhtml/Landingpage/AbstractAction.php +++ b/Controller/Adminhtml/Landingpage/AbstractAction.php @@ -3,7 +3,6 @@ namespace Algolia\AlgoliaSearch\Controller\Adminhtml\Landingpage; use Algolia\AlgoliaSearch\Helper\MerchandisingHelper; -use Algolia\AlgoliaSearch\Helper\ProxyHelper; use Algolia\AlgoliaSearch\Model\LandingPageFactory; use Magento\Backend\App\Action\Context; use Magento\Framework\Registry; @@ -20,9 +19,6 @@ abstract class AbstractAction extends \Magento\Backend\App\Action /** @var MerchandisingHelper */ protected $merchandisingHelper; - /** @var ProxyHelper */ - protected $proxyHelper; - /** @var StoreManagerInterface */ protected $storeManager; @@ -31,7 +27,6 @@ abstract class AbstractAction extends \Magento\Backend\App\Action * @param Registry $coreRegistry * @param LandingPageFactory $landingPageFactory * @param MerchandisingHelper $merchandisingHelper - * @param ProxyHelper $proxyHelper * @param StoreManagerInterface $storeManager */ public function __construct( @@ -39,7 +34,6 @@ public function __construct( Registry $coreRegistry, LandingPageFactory $landingPageFactory, MerchandisingHelper $merchandisingHelper, - ProxyHelper $proxyHelper, StoreManagerInterface $storeManager ) { parent::__construct($context); @@ -47,7 +41,6 @@ public function __construct( $this->coreRegistry = $coreRegistry; $this->landingPageFactory = $landingPageFactory; $this->merchandisingHelper = $merchandisingHelper; - $this->proxyHelper = $proxyHelper; $this->storeManager = $storeManager; } @@ -57,35 +50,6 @@ protected function _isAllowed() return $this->_authorization->isAllowed('Algolia_AlgoliaSearch::manage'); } - /** - * {@inheritdoc} - */ - public function dispatch(\Magento\Framework\App\RequestInterface $request) - { - $planLevelInfo = $this->proxyHelper->getClientConfigurationData(); - $planLevel = isset($planLevelInfo['plan_level']) ? (int) $planLevelInfo['plan_level'] : 1; - - if ($planLevel <= 1) { - $this->_response->setStatusHeader(403, '1.1', 'Forbidden'); - if (!$this->_auth->isLoggedIn()) { - return $this->_redirect('*/auth/login'); - } - $this->_view->loadLayout( - ['default', 'algolia_algoliasearch_handle_access_denied'], - true, - true, - false - ); - $this->_view->getLayout(); - $this->_view->renderLayout(); - $this->_request->setDispatched(true); - - return $this->_response; - } - - return parent::dispatch($request); - } - /** @return \Algolia\AlgoliaSearch\Model\LandingPage */ protected function initLandingPage() { diff --git a/Controller/Adminhtml/Landingpage/Save.php b/Controller/Adminhtml/Landingpage/Save.php index b88e55a4b..b3eb9f132 100644 --- a/Controller/Adminhtml/Landingpage/Save.php +++ b/Controller/Adminhtml/Landingpage/Save.php @@ -3,7 +3,6 @@ namespace Algolia\AlgoliaSearch\Controller\Adminhtml\Landingpage; use Algolia\AlgoliaSearch\Helper\MerchandisingHelper; -use Algolia\AlgoliaSearch\Helper\ProxyHelper; use Algolia\AlgoliaSearch\Model\LandingPageFactory; use Magento\Framework\App\Request\DataPersistorInterface; use Magento\Framework\Controller\ResultFactory; @@ -24,7 +23,6 @@ class Save extends AbstractAction * @param \Magento\Framework\Registry $coreRegistry * @param LandingPageFactory $landingPageFactory * @param MerchandisingHelper $merchandisingHelper - * @param ProxyHelper $proxyHelper * @param StoreManagerInterface $storeManager * @param DataPersistorInterface $dataPersistor * @@ -35,7 +33,6 @@ public function __construct( \Magento\Framework\Registry $coreRegistry, LandingPageFactory $landingPageFactory, MerchandisingHelper $merchandisingHelper, - ProxyHelper $proxyHelper, StoreManagerInterface $storeManager, DataPersistorInterface $dataPersistor ) { @@ -46,7 +43,6 @@ public function __construct( $coreRegistry, $landingPageFactory, $merchandisingHelper, - $proxyHelper, $storeManager ); } diff --git a/Controller/Adminhtml/Query/AbstractAction.php b/Controller/Adminhtml/Query/AbstractAction.php index 07d678e24..1ccba4d82 100644 --- a/Controller/Adminhtml/Query/AbstractAction.php +++ b/Controller/Adminhtml/Query/AbstractAction.php @@ -3,7 +3,6 @@ namespace Algolia\AlgoliaSearch\Controller\Adminhtml\Query; use Algolia\AlgoliaSearch\Helper\MerchandisingHelper; -use Algolia\AlgoliaSearch\Helper\ProxyHelper; use Algolia\AlgoliaSearch\Model\QueryFactory; use Magento\Backend\App\Action\Context; use Magento\Framework\Registry; @@ -20,9 +19,6 @@ abstract class AbstractAction extends \Magento\Backend\App\Action /** @var MerchandisingHelper */ protected $merchandisingHelper; - /** @var ProxyHelper */ - protected $proxyHelper; - /** @var StoreManagerInterface */ protected $storeManager; @@ -31,7 +27,6 @@ abstract class AbstractAction extends \Magento\Backend\App\Action * @param Registry $coreRegistry * @param QueryFactory $queryFactory * @param MerchandisingHelper $merchandisingHelper - * @param ProxyHelper $proxyHelper * @param StoreManagerInterface $storeManager */ public function __construct( @@ -39,7 +34,6 @@ public function __construct( Registry $coreRegistry, QueryFactory $queryFactory, MerchandisingHelper $merchandisingHelper, - ProxyHelper $proxyHelper, StoreManagerInterface $storeManager ) { parent::__construct($context); @@ -47,7 +41,6 @@ public function __construct( $this->coreRegistry = $coreRegistry; $this->queryFactory = $queryFactory; $this->merchandisingHelper = $merchandisingHelper; - $this->proxyHelper = $proxyHelper; $this->storeManager = $storeManager; } @@ -57,35 +50,6 @@ protected function _isAllowed() return $this->_authorization->isAllowed('Algolia_AlgoliaSearch::manage'); } - /** - * {@inheritdoc} - */ - public function dispatch(\Magento\Framework\App\RequestInterface $request) - { - $planLevelInfo = $this->proxyHelper->getClientConfigurationData(); - $planLevel = isset($planLevelInfo['plan_level']) ? (int) $planLevelInfo['plan_level'] : 1; - - if ($planLevel < 3) { - $this->_response->setStatusHeader(403, '1.1', 'Forbidden'); - if (!$this->_auth->isLoggedIn()) { - return $this->_redirect('*/auth/login'); - } - $this->_view->loadLayout( - ['default', 'algolia_algoliasearch_handle_query_access_denied'], - true, - true, - false - ); - $this->_view->getLayout(); - $this->_view->renderLayout(); - $this->_request->setDispatched(true); - - return $this->_response; - } - - return parent::dispatch($request); - } - /** @return \Algolia\AlgoliaSearch\Model\Query */ protected function initQuery() { diff --git a/Controller/Adminhtml/Query/Save.php b/Controller/Adminhtml/Query/Save.php index 75c1366fa..fa3f61408 100644 --- a/Controller/Adminhtml/Query/Save.php +++ b/Controller/Adminhtml/Query/Save.php @@ -4,7 +4,6 @@ use Algolia\AlgoliaSearch\Helper\ConfigHelper; use Algolia\AlgoliaSearch\Helper\MerchandisingHelper; -use Algolia\AlgoliaSearch\Helper\ProxyHelper; use Algolia\AlgoliaSearch\Model\ImageUploader; use Algolia\AlgoliaSearch\Model\QueryFactory; use Magento\Framework\App\Request\DataPersistorInterface; @@ -36,7 +35,6 @@ class Save extends AbstractAction * @param \Magento\Framework\Registry $coreRegistry * @param QueryFactory $queryFactory * @param MerchandisingHelper $merchandisingHelper - * @param ProxyHelper $proxyHelper * @param StoreManagerInterface $storeManager * @param DataPersistorInterface $dataPersistor * @param ConfigHelper $configHelper @@ -49,7 +47,6 @@ public function __construct( \Magento\Framework\Registry $coreRegistry, QueryFactory $queryFactory, MerchandisingHelper $merchandisingHelper, - ProxyHelper $proxyHelper, StoreManagerInterface $storeManager, DataPersistorInterface $dataPersistor, ConfigHelper $configHelper, @@ -64,7 +61,6 @@ public function __construct( $coreRegistry, $queryFactory, $merchandisingHelper, - $proxyHelper, $storeManager ); } @@ -114,10 +110,6 @@ public function execute() $storeId = isset($data['store_id']) && $data['store_id'] != 0 ? $data['store_id'] : null; - $this->trackQueryMerchandisingData($query, 'banner_image', 'Uploaded Banner', $storeId); - $this->trackQueryMerchandisingData($query, 'banner_alt', 'Add Alt Text', $storeId); - $this->trackQueryMerchandisingData($query, 'banner_url', 'Add Banner URL', $storeId); - try { $query->getResource()->save($query); @@ -209,22 +201,4 @@ private function prepareBannerContent($data) return $content; } - - /** - * @param string $query - * @param string $attributeCode - * @param string $eventName - * @param int|null $storeId - */ - private function trackQueryMerchandisingData($query, $attributeCode, $eventName, $storeId = null) - { - if (($query->isObjectNew() && $query->getData($attributeCode)) - || $query->getOrigData($attributeCode) !== $query->getData($attributeCode)) { - $this->proxyHelper->trackEvent( - $this->configHelper->getApplicationID($storeId), - $eventName, - ['source' => 'magento2.querymerch.edit'] - ); - } - } } diff --git a/Controller/Adminhtml/Support/AbstractAction.php b/Controller/Adminhtml/Support/AbstractAction.php deleted file mode 100644 index 736a2b3a1..000000000 --- a/Controller/Adminhtml/Support/AbstractAction.php +++ /dev/null @@ -1,28 +0,0 @@ -resultFactory = $context->getResultFactory(); - } - - /** @return bool */ - protected function _isAllowed() - { - return $this->_authorization->isAllowed('Algolia_AlgoliaSearch::manage'); - } -} diff --git a/Controller/Adminhtml/Support/Contact.php b/Controller/Adminhtml/Support/Contact.php deleted file mode 100644 index 0d65267d2..000000000 --- a/Controller/Adminhtml/Support/Contact.php +++ /dev/null @@ -1,145 +0,0 @@ -supportHelper = $supportHelper; - } - - /** - * @throws \Zend_Db_Statement_Exception - * @throws LocalizedException - * - * @return Redirect | Page - */ - public function execute() - { - if ($this->supportHelper->isExtensionSupportEnabled() === false) { - $this->messageManager->addErrorMessage('Your Algolia app is not eligible for e-mail support.'); - - $resultRedirect = $this->resultRedirectFactory->create(); - $resultRedirect->setPath('*/*/index'); - - return $resultRedirect; - } - - $params = $this->getRequest()->getParams(); - if ($this->isFormSubmitted($params) && $data = $this->validateForm($params)) { - $processed = $this->supportHelper->processContactForm($data); - if ($processed === true) { - $this->messageManager->addSuccessMessage('You ticket was successfully sent to Algolia support team.'); - - $resultRedirect = $this->resultRedirectFactory->create(); - $resultRedirect->setPath('*/*/index'); - - return $resultRedirect; - } - - $this->messageManager->addErrorMessage('There was an error while sending your ticket. Please, try it again.'); - } - - $breadMain = __('Algolia | Contact Us'); - - /** @var Page $resultPage */ - $resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE); - $resultPage->getConfig()->getTitle()->prepend($breadMain); - - return $resultPage; - } - - /** - * @param array $data - * - * @return bool - */ - private function isFormSubmitted($data) - { - return array_key_exists('sent', $data) && $data['sent'] === 'sent'; - } - - /** - * @param array $data - * - * @return array|bool - */ - private function validateForm($data) - { - $attributes = [ - 'name' => 'Name', - 'email' => 'E-mail', - 'subject' => 'Subject', - 'message' => 'Message', - ]; - - $cleanData = []; - $isValid = true; - - foreach ($attributes as $attribute => $caption) { - $value = trim($data[$attribute]); - - if ($value === '') { - $isValid = false; - $this->messageManager->addErrorMessage('Please, fill in your "' . $caption . '".'); - - continue; - } - - if ($attribute === 'email' && $this->validateEmail($value) === false) { - $isValid = false; - $this->messageManager->addErrorMessage('Please enter a valid e-mail address (Ex: johndoe@domain.com).'); - - continue; - } - - $cleanData[$attribute] = $value; - } - - if ($isValid === false) { - return false; - } - - $cleanData['send_additional_info'] = false; - if (array_key_exists('send_additional_info', $data) && $data['send_additional_info'] === '1') { - $cleanData['send_additional_info'] = true; - } - - return $cleanData; - } - - /** - * @param string $email - * - * @return bool - */ - private function validateEmail($email) - { - $atom = "[-a-z0-9!#$%&'*+/=?^_`{|}~]"; - $alpha = "a-z\x80-\xFF"; - - $isValid = (bool) preg_match("(^ - (\"([ !#-[\\]-~]*|\\\\[ -~])+\"|$atom+(\\.$atom+)*) - @ - ([0-9$alpha]([-0-9$alpha]{0,61}[0-9$alpha])?\\.)+ - [$alpha]([-0-9$alpha]{0,17}[$alpha])?\\z)ix", $email); - - return $isValid; - } -} diff --git a/Controller/Adminhtml/Support/Index.php b/Controller/Adminhtml/Support/Index.php index e7f119277..9850d1d31 100644 --- a/Controller/Adminhtml/Support/Index.php +++ b/Controller/Adminhtml/Support/Index.php @@ -2,10 +2,30 @@ namespace Algolia\AlgoliaSearch\Controller\Adminhtml\Support; +use Magento\Backend\App\Action\Context; use Magento\Framework\Controller\ResultFactory; -class Index extends AbstractAction +class Index extends \Magento\Backend\App\Action { + /** @var ResultFactory */ + protected $resultFactory; + + /** + * @param Context $context + */ + public function __construct(Context $context) + { + parent::__construct($context); + + $this->resultFactory = $context->getResultFactory(); + } + + /** @return bool */ + protected function _isAllowed() + { + return $this->_authorization->isAllowed('Algolia_AlgoliaSearch::manage'); + } + /** * @return \Magento\Framework\View\Result\Page */ diff --git a/Helper/AnalyticsHelper.php b/Helper/AnalyticsHelper.php index be010d5b9..36eeeb843 100644 --- a/Helper/AnalyticsHelper.php +++ b/Helper/AnalyticsHelper.php @@ -23,9 +23,6 @@ class AnalyticsHelper /** @var IndexEntityDataProvider */ private $entityHelper; - /** @var ProxyHelper */ - private $proxyHelper; - /** @var Logger */ private $logger; @@ -53,27 +50,34 @@ class AnalyticsHelper */ private $analyticsConfig; + /** + * Can be changed through DI + * + * @var string + */ + private $region; + /** * @param AlgoliaHelper $algoliaHelper * @param ConfigHelper $configHelper * @param IndexEntityDataProvider $entityHelper - * @param ProxyHelper $proxyHelper * @param Logger $logger + * @param string $region */ public function __construct( AlgoliaHelper $algoliaHelper, ConfigHelper $configHelper, IndexEntityDataProvider $entityHelper, - ProxyHelper $proxyHelper, - Logger $logger + Logger $logger, + string $region = 'us' ) { $this->algoliaHelper = $algoliaHelper; $this->configHelper = $configHelper; $this->entityHelper = $entityHelper; - $this->proxyHelper = $proxyHelper; $this->logger = $logger; + $this->region = $region; } private function setupAnalyticsClient() @@ -84,12 +88,14 @@ private function setupAnalyticsClient() $this->analyticsClient = AnalyticsClient::create( $this->configHelper->getApplicationID(), - $this->configHelper->getAPIKey() + $this->configHelper->getAPIKey(), + $this->region ); $this->analyticsConfig = AnalyticsConfig::create( $this->configHelper->getApplicationID(), - $this->configHelper->getAPIKey() + $this->configHelper->getAPIKey(), + $this->region ); } @@ -305,25 +311,9 @@ public function getConversionRateByDates(array $params) return $conversion && isset($conversion['dates']) ? $conversion['dates'] : []; } - /** - * Client Data Check - * - * @return mixed - */ - public function getClientData() - { - if (!$this->clientData) { - $this->clientData = $this->proxyHelper->getInfo(ProxyHelper::INFO_TYPE_ANALYTICS); - } - - return $this->clientData; - } - public function isAnalyticsApiEnabled() { - $clientData = $this->getClientData(); - - return (bool) $clientData && isset($clientData['analytics_api']) ? $clientData['analytics_api'] : 0; + return true; } public function isClickAnalyticsEnabled() @@ -332,9 +322,7 @@ public function isClickAnalyticsEnabled() return false; } - $clientData = $this->getClientData(); - - return (bool) $clientData && isset($clientData['click_analytics']) ? $clientData['click_analytics'] : 0; + return true; } /** diff --git a/Helper/ConfigHelper.php b/Helper/ConfigHelper.php index beb5a5d00..9ce26de1c 100755 --- a/Helper/ConfigHelper.php +++ b/Helper/ConfigHelper.php @@ -120,7 +120,6 @@ class ConfigHelper private $eventManager; private $currencyManager; private $serializer; - private $maxRecordSize; public function __construct( Magento\Framework\App\Config\ScopeConfigInterface $configInterface, @@ -889,6 +888,8 @@ public function getAttributesToRetrieve($groupId) 'in_stock', 'type_id', 'value', + 'query', # suggestions + 'path', # categories ]); $currencies = $this->dirCurrency->getConfigAllowCurrencies(); @@ -1098,29 +1099,7 @@ public function getDefaultMaxRecordSize() public function getMaxRecordSizeLimit($storeId = null) { - if ($this->maxRecordSize) { - return $this->maxRecordSize; - } - - $configValue = $this->configInterface->getValue(self::MAX_RECORD_SIZE_LIMIT, ScopeInterface::SCOPE_STORE, $storeId); - if ($configValue) { - $this->maxRecordSize = $configValue; - - return $this->maxRecordSize; - } - /** @var \Algolia\AlgoliaSearch\Helper\ProxyHelper $proxyHelper */ - $proxyHelper = $this->objectManager->create('Algolia\AlgoliaSearch\Helper\ProxyHelper'); - $clientData = $proxyHelper->getClientConfigurationData(); - if ($clientData && isset($clientData['max_record_size'])) { - /** @var \Magento\Framework\App\Config\Storage\Writer $configWriter */ - $configWriter = $this->objectManager->create('Magento\Framework\App\Config\Storage\Writer'); - $configWriter->save(self::MAX_RECORD_SIZE_LIMIT, $clientData['max_record_size']); - $this->maxRecordSize = $clientData['max_record_size']; - } else { - $this->maxRecordSize = self::getDefaultMaxRecordSize(); - } - - return $this->maxRecordSize; + return self::getDefaultMaxRecordSize(); } public function getArchiveLogClearLimit($storeId = null) diff --git a/Helper/Configuration/NoticeHelper.php b/Helper/Configuration/NoticeHelper.php index 0b4e2b411..a154ed33d 100644 --- a/Helper/Configuration/NoticeHelper.php +++ b/Helper/Configuration/NoticeHelper.php @@ -3,7 +3,6 @@ namespace Algolia\AlgoliaSearch\Helper\Configuration; use Algolia\AlgoliaSearch\Helper\ConfigHelper; -use Algolia\AlgoliaSearch\Helper\ProxyHelper; use Algolia\AlgoliaSearch\Model\ExtensionNotification; use Algolia\AlgoliaSearch\Model\ResourceModel\Job\CollectionFactory as JobCollectionFactory; use Magento\Framework\Module\Manager as ModuleManager; @@ -16,9 +15,6 @@ class NoticeHelper extends \Magento\Framework\App\Helper\AbstractHelper /** @var ConfigHelper */ private $configHelper; - /** @var ProxyHelper */ - private $proxyHelper; - /** @var PersonalizationHelper */ private $personalizationHelper; @@ -46,7 +42,6 @@ class NoticeHelper extends \Magento\Framework\App\Helper\AbstractHelper 'getMsiNotice', 'getVersionNotice', 'getClickAnalyticsNotice', - 'getQueryRulesNotice', 'getPersonalizationNotice', ]; @@ -65,7 +60,6 @@ class NoticeHelper extends \Magento\Framework\App\Helper\AbstractHelper public function __construct( \Magento\Framework\App\Helper\Context $context, ConfigHelper $configHelper, - ProxyHelper $proxyHelper, PersonalizationHelper $personalizationHelper, ModuleManager $moduleManager, ObjectManagerInterface $objectManager, @@ -75,7 +69,6 @@ public function __construct( AssetRepository $assetRepository ) { $this->configHelper = $configHelper; - $this->proxyHelper = $proxyHelper; $this->personalizationHelper = $personalizationHelper; $this->moduleManager = $moduleManager; $this->objectManager = $objectManager; @@ -184,7 +177,7 @@ protected function getVersionNotice() protected function getClickAnalyticsNotice() { // If the feature is enabled both in Magento Admin and Algolia dashboard, no need to display a notice - if ($this->isClickAnalyticsEnabled() && $this->configHelper->isClickConversionAnalyticsEnabled()) { + if ($this->configHelper->isClickConversionAnalyticsEnabled()) { return; } @@ -192,33 +185,20 @@ protected function getClickAnalyticsNotice() $selector = ''; $method = 'before'; - // If the feature is not enabled in the Algolia dashboard - if (! $this->isClickAnalyticsEnabled()) { - $noticeContent = '
-
- To get access to this Algolia feature, - please consider upgrading to a higher plan. -
'; - $selector = '#algoliasearch_cc_analytics_cc_analytics_group .comment'; - $method = 'after'; - } - // If the feature is enabled in the Algolia dashboard but not activated on the Magento Admin - if ($this->isClickAnalyticsEnabled() && ! $this->configHelper->isClickConversionAnalyticsEnabled()) { - $noticeContent = ' - -
- Enhance your Analytics with Algolia Click Analytics that provide you even more insights - like Click-through Rate, Conversion Rate from searches and average click position. - Click Analytics are only available for higher plans and require only minor additional settings. -

- Find more information in documentation. -
- - '; - $selector = '#row_algoliasearch_cc_analytics_cc_analytics_group_enable'; - $method = 'before'; - } + $noticeContent = ' + +
+ Enhance your Analytics with Algolia Click Analytics that provide you even more insights + like Click-through Rate, Conversion Rate from searches and average click position. + Click Analytics are only available for higher plans and require only minor additional settings. +

+ Find more information in documentation. +
+ + '; + $selector = '#row_algoliasearch_cc_analytics_cc_analytics_group_enable'; + $method = 'before'; $this->notices[] = [ 'selector' => $selector, @@ -227,25 +207,6 @@ protected function getClickAnalyticsNotice() ]; } - protected function getQueryRulesNotice() - { - if ($this->isQueryRulesEnabled()) { - return; - } - - $noticeContent = '
-
- To be able to create Query rules for facets, - please consider upgrading to a higher plan. -
'; - - $this->notices[] = [ - 'selector' => '#row_algoliasearch_instant_instant_facets .algolia_block.blue', - 'method' => 'after', - 'message' => $noticeContent, - ]; - } - protected function getPersonalizationNotice() { if (! preg_match('/algoliasearch_personalization/', $this->urlBuilder->getCurrentUrl())) { @@ -322,54 +283,7 @@ protected function formatNotice($title, $content, $icon = 'icon-warning') */ public function getPersonalizationStatus() { - $info = $this->proxyHelper->getInfo(ProxyHelper::INFO_TYPE_PERSONALIZATION); - $status = 2; - - if ($info - && array_key_exists('personalization', $info) - && array_key_exists('personalization_enabled_at', $info)) { - if (!$info['personalization']) { - $status = 0; - - // If perso is not avaible in the plan but activated in admin for some reason, turn it off - if ($this->personalizationHelper->isPersoEnabled()) { - $this->personalizationHelper->disablePerso(); - } - } - if ($info['personalization_enabled_at'] === null) { - $status = min(1, $status); - } - } - - return $status; - } - - /** @return bool */ - public function isQueryRulesEnabled() - { - $info = $this->proxyHelper->getInfo(ProxyHelper::INFO_TYPE_QUERY_RULES); - - // In case the call to API proxy fails, - // be "nice" and return true - if ($info && array_key_exists('query_rules', $info)) { - return $info['query_rules']; - } - - return true; - } - - /** @return bool */ - public function isClickAnalyticsEnabled() - { - $info = $this->proxyHelper->getInfo(ProxyHelper::INFO_TYPE_ANALYTICS); - - // In case the call to API proxy fails, - // be "nice" and return true - if ($info && array_key_exists('click_analytics', $info)) { - return $info['click_analytics']; - } - - return true; + return 2; } public function isMsiExternalModuleNeeded() diff --git a/Helper/Entity/CategoryHelper.php b/Helper/Entity/CategoryHelper.php index 827b8d887..ac060632f 100755 --- a/Helper/Entity/CategoryHelper.php +++ b/Helper/Entity/CategoryHelper.php @@ -165,11 +165,7 @@ public function getCategoryCollectionQuery($storeId, $categoryIds = null) $storeRootCategoryPath = sprintf('%d/%d', $this->getRootCategoryId(), $store->getRootCategoryId()); $unserializedCategorysAttrs = $this->getAdditionalAttributes($storeId); - - $additionalAttr = []; - foreach ($unserializedCategorysAttrs as $attr) { - $additionalAttr[] = $attr['attribute']; - } + $additionalAttr = array_column($unserializedCategorysAttrs, 'attribute'); $categories = $this->categoryCollectionFactory->create() ->distinct(true) @@ -465,9 +461,8 @@ private function getCategoryKeyId($categoryId) if ($this->getCorrectIdColumn() === 'row_id') { $category = $this->getCategoryById($categoryId); - if ($category) { - $categoryKeyId = $category->getRowId(); - } + + return $category ? $category->getRowId() : null; } return $categoryKeyId; @@ -475,7 +470,7 @@ private function getCategoryKeyId($categoryId) private function getCategoryById($categoryId) { - $categories = $this->getCoreCategories(); + $categories = $this->getCoreCategories(false); return isset($categories[$categoryId]) ? $categories[$categoryId] : null; } diff --git a/Helper/Entity/Product/PriceManager/ProductWithChildren.php b/Helper/Entity/Product/PriceManager/ProductWithChildren.php index 3434a194e..0e6b75201 100644 --- a/Helper/Entity/Product/PriceManager/ProductWithChildren.php +++ b/Helper/Entity/Product/PriceManager/ProductWithChildren.php @@ -22,6 +22,10 @@ protected function addAdditionalData($product, $withTax, $subProducts, $currency if (!$this->customData[$field][$currencyCode]['default']) { $this->handleZeroDefaultPrice($field, $currencyCode, $min, $max); + + # need to rehandle specialPrice + $specialPrice = $this->getSpecialPrice($product, $currencyCode, $withTax); + $this->addSpecialPrices($specialPrice, $field, $currencyCode); } if ($this->areCustomersGroupsEnabled) { @@ -46,7 +50,7 @@ protected function getMinMaxPrices(Product $product, $withTax, $subProducts, $cu $original = min($original, $basePrice); $max = max($max, $price); - $originalMax = max($max, $basePrice); + $originalMax = max($originalMax, $basePrice); } } else { $originalMax = $original = $min = $max; diff --git a/Helper/Entity/Product/PriceManager/ProductWithoutChildren.php b/Helper/Entity/Product/PriceManager/ProductWithoutChildren.php index e39d2092e..d9f4619aa 100644 --- a/Helper/Entity/Product/PriceManager/ProductWithoutChildren.php +++ b/Helper/Entity/Product/PriceManager/ProductWithoutChildren.php @@ -132,7 +132,7 @@ protected function convertPrice($amount, $currencyCode) return $this->priceCurrency->convert($amount, $this->store, $currencyCode); } - protected function getTaxPrice($product, $amount, $withTax) + public function getTaxPrice($product, $amount, $withTax) { return (float) $this->catalogHelper->getTaxPrice( $product, diff --git a/Helper/Entity/ProductHelper.php b/Helper/Entity/ProductHelper.php index 87114dcde..669985d55 100755 --- a/Helper/Entity/ProductHelper.php +++ b/Helper/Entity/ProductHelper.php @@ -445,9 +445,10 @@ public function setSettings($indexName, $indexNameTmp, $storeId, $saveToTmpIndic } } - public function getAllCategories($categoryIds) + public function getAllCategories($categoryIds, $storeId) { - $categories = $this->categoryHelper->getCoreCategories(false); + $filterNotIncludedCategories = !$this->configHelper->showCatsNotIncludedInNavigation($storeId); + $categories = $this->categoryHelper->getCoreCategories($filterNotIncludedCategories); $selectedCategories = []; foreach ($categoryIds as $id) { @@ -628,7 +629,7 @@ private function addCategoryData($customData, Product $product) $_categoryIds = $product->getCategoryIds(); if (is_array($_categoryIds) && count($_categoryIds) > 0) { - $categoryCollection = $this->getAllCategories($_categoryIds); + $categoryCollection = $this->getAllCategories($_categoryIds, $storeId); /** @var Store $store */ $store = $this->storeManager->getStore($product->getStoreId()); @@ -829,7 +830,14 @@ private function addNullValue($customData, $subProducts, $attribute, AttributeRe $valueText = $subProduct->getAttributeText($attributeName); $values = array_merge($values, $this->getValues($valueText, $subProduct, $attributeResource)); - $subProductImages = $this->addSubProductImage($subProductImages, $attribute, $subProduct, $valueText); + if ($this->configHelper->useAdaptiveImage($attributeResource->getStoreId())) { + $subProductImages = $this->addSubProductImage( + $subProductImages, + $attribute, + $subProduct, + $valueText + ); + } } } @@ -869,11 +877,6 @@ private function addSubProductImage($subProductImages, $attribute, $subProduct, return $subProductImages; } - $subImage = $subProduct->getData($this->configHelper->getImageType()); - if (!$subImage || $subImage === 'no_selection') { - return $subProductImages; - } - $image = $this->imageHelper ->init($subProduct, $this->configHelper->getImageType()) ->resize( @@ -881,6 +884,11 @@ private function addSubProductImage($subProductImages, $attribute, $subProduct, $this->configHelper->getImageHeight() ); + $subImage = $subProduct->getData($image->getType()); + if (!$subImage || $subImage === 'no_selection') { + return $subProductImages; + } + try { $textValueInLower = mb_strtolower($valueText, 'utf-8'); $subProductImages[$textValueInLower] = $image->getUrl(); diff --git a/Helper/Entity/SuggestionHelper.php b/Helper/Entity/SuggestionHelper.php index 46c2d210d..581d6510b 100755 --- a/Helper/Entity/SuggestionHelper.php +++ b/Helper/Entity/SuggestionHelper.php @@ -106,28 +106,20 @@ public function getPopularQueries($storeId) $collection->getSelect()->where( 'num_results >= ' . $this->configHelper->getMinNumberOfResults() . ' AND popularity >= ' . $this->configHelper->getMinPopularity() . ' - AND query_text != "__empty__"' + AND query_text != "__empty__" AND CHAR_LENGTH(query_text) >= 3' ); - $collection->getSelect()->limit(12); - $collection->setOrder('popularity', 'DESC'); - $collection->setOrder('num_results', 'DESC'); - $collection->setOrder('updated_at', 'ASC'); if ($storeId) { $collection->getSelect()->where('store_id = ?', (int) $storeId); } - $collection->load(); - - $suggestions = []; + $collection->setOrder('popularity', 'DESC'); + $collection->setOrder('num_results', 'DESC'); + $collection->setOrder('updated_at', 'ASC'); - foreach ($collection as $suggestion) { - if (mb_strlen($suggestion['query_text']) >= 3) { - $suggestions[] = $suggestion['query_text']; - } - } + $collection->getSelect()->limit(10); - $queries = array_slice($suggestions, 0, 9); + $queries = $collection->getColumnValues('query_text'); $this->cache->save($this->serializer->serialize($queries), $this->popularQueriesCacheId, [], 24*3600); diff --git a/Helper/ProxyHelper.php b/Helper/ProxyHelper.php deleted file mode 100644 index 8dd7bbe07..000000000 --- a/Helper/ProxyHelper.php +++ /dev/null @@ -1,121 +0,0 @@ -configHelper = $configHelper; - } - - /** - * @param string $type - * - * @return string|array - */ - public function getInfo($type) - { - $appId = $this->configHelper->getApplicationID(); - $apiKey = $this->configHelper->getAPIKey(); - - $token = $appId . ':' . $apiKey; - $token = base64_encode($token); - $token = str_replace(["\n", '='], '', $token); - - $params = [ - 'appId' => $appId, - 'token' => $token, - ]; - - if ($type !== self::INFO_TYPE_EXTENSION_SUPPORT) { - $params['type'] = $type; - } - - $info = $this->postRequest($params, self::PROXY_URL_PARAM_GET_INFO); - - if ($info) { - $info = json_decode($info, true); - } - - return $info; - } - - /** - * @param string $appId - * @param string $eventName - * @param array $data - */ - public function trackEvent($appId, $eventName, $data) - { - $params = [ - 'appId' => $appId, - 'eventName' => $eventName, - 'data' => $data, - ]; - - $this->postRequest($params, self::PROXY_URL_PARAM_TRACK_EVENT); - } - - public function getClientConfigurationData() - { - if (!$this->allClientData) { - $this->allClientData = $this->getInfo(self::INFO_TYPE_ALL); - } - - return $this->allClientData; - } - - /** - * @param array $data - * - * @return bool - */ - public function pushSupportTicket($data) - { - $result = $this->postRequest($data, self::PROXY_URL_PARAM_POST_DATA); - - return $result === 'true'; - } - - /** - * @param $data - * @param $proxyMethod - * - * @return bool|string - */ - private function postRequest($data, $proxyMethod) - { - $ch = curl_init(); - - curl_setopt($ch, CURLOPT_URL, self::PROXY_URL . $proxyMethod); - curl_setopt($ch, CURLOPT_POST, 1); - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - - $result = curl_exec($ch); - - curl_close($ch); - - return $result; - } -} diff --git a/Helper/SupportHelper.php b/Helper/SupportHelper.php index 28399b4f0..94607767e 100644 --- a/Helper/SupportHelper.php +++ b/Helper/SupportHelper.php @@ -2,32 +2,17 @@ namespace Algolia\AlgoliaSearch\Helper; -use Algolia\AlgoliaSearch\Model\ResourceModel\NoteBuilder; - class SupportHelper { /** @var ConfigHelper */ private $configHelper; - /** @var ProxyHelper */ - private $proxyHelper; - - /** @var NoteBuilder */ - private $noteBuilder; - /** * @param ConfigHelper $configHelper - * @param ProxyHelper $proxyHelper - * @param NoteBuilder $noteBuilder */ - public function __construct( - ConfigHelper $configHelper, - ProxyHelper $proxyHelper, - NoteBuilder $noteBuilder - ) { + public function __construct(ConfigHelper $configHelper) + { $this->configHelper = $configHelper; - $this->proxyHelper = $proxyHelper; - $this->noteBuilder = $noteBuilder; } /** @return string */ @@ -41,56 +26,4 @@ public function getExtensionVersion() { return $this->configHelper->getExtensionVersion(); } - - /** - * @param array $data - * - * @throws \Zend_Db_Statement_Exception - * @throws \Magento\Framework\Exception\LocalizedException - * - * @return bool - */ - public function processContactForm($data) - { - list($firstname, $lastname) = $this->splitName($data['name']); - - $messageData = [ - 'email' => $data['email'], - 'firstname' => $firstname, - 'lastname' => $lastname, - 'subject' => $data['subject'], - 'text' => $data['message'], - 'note' => $this->noteBuilder->getNote($data['send_additional_info']), - ]; - - $this->proxyHelper->trackEvent($this->configHelper->getApplicationID(), 'Sent Contact Form', [ - 'source' => 'magento2.help.contact', - ]); - - return $this->proxyHelper->pushSupportTicket($messageData); - } - - /** @return bool */ - public function isExtensionSupportEnabled() - { - $info = $this->proxyHelper->getInfo(ProxyHelper::INFO_TYPE_EXTENSION_SUPPORT); - - // In case the call to API proxy fails, - // be "nice" and return true - if ($info && array_key_exists('extension_support', $info)) { - return $info['extension_support']; - } - - return true; - } - - /** - * @param string $name - * - * @return array - */ - private function splitName($name) - { - return explode(' ', $name, 2); - } } diff --git a/Model/Backend/EnableClickAnalytics.php b/Model/Backend/EnableClickAnalytics.php deleted file mode 100755 index 306bd3bb4..000000000 --- a/Model/Backend/EnableClickAnalytics.php +++ /dev/null @@ -1,80 +0,0 @@ -algoliaHelper = $algoliaHelper; - $this->productHelper = $productHelper; - $this->configHelper = $configHelper; - } - - public function beforeSave() - { - $value = trim($this->getData('value')); - - if ($value !== '1') { - return parent::beforeSave(); - } - - $ch = curl_init(); - - $headers = [ - 'X-Algolia-Api-Key: ' . $this->configHelper->getAPIKey(), - 'X-Algolia-Application-Id: ' . $this->configHelper->getApplicationID(), - 'Content-Type: application/x-www-form-urlencoded', - ]; - - curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); - - $postFields = json_encode([ - 'timestamp' => time(), - 'queryID' => 'a', - 'objectID' => 'non_existent_object_id', - 'position' => 1, - ]); - - curl_setopt($ch, CURLOPT_URL, 'https://insights.algolia.io/1/searches/click'); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields); - curl_setopt($ch, CURLOPT_POST, 1); - - $result = curl_exec($ch); - curl_close($ch); - - if ($result) { - $result = json_decode($result); - if ($result->status === 401 && $result->message === 'Feature not available') { - throw new LocalizedException( - __('Click & Conversion analytics are not supported on your current plan. Please refer to Algolia\'s pricing page for more details.') - ); - } - } - - return parent::beforeSave(); - } -} diff --git a/Model/ConfigurationTracker.php b/Model/ConfigurationTracker.php deleted file mode 100644 index 953e49dc3..000000000 --- a/Model/ConfigurationTracker.php +++ /dev/null @@ -1,128 +0,0 @@ -proxyHelper = $proxyHelper; - $this->configHelper = $configHelper; - $this->queryCollection = $queryCollection; - $this->landingPageCollection = $landingPageCollection; - $this->upgradeSchema = $upgradeSchema; - } - - /** - * @param int $storeId - */ - public function trackConfiguration($storeId) - { - $this->proxyHelper->trackEvent($this->configHelper->getApplicationID($storeId), 'Configuration saved', [ - 'source' => 'magento2.saveconfig', - 'indexingEnabled' => $this->configHelper->isEnabledBackend($storeId), - 'searchEnabled' => $this->configHelper->isEnabledFrontEnd($storeId), - 'autocompleteEnabled' => $this->configHelper->isAutoCompleteEnabled($storeId), - 'instantsearchEnabled' => $this->configHelper->isInstantEnabled($storeId), - 'sortingChanged' => $this->isSortingChanged($storeId), - 'rankingChanged' => $this->isCustomRankingChanged($storeId), - 'replaceImageByVariantUsed' => $this->configHelper->useAdaptiveImage($storeId), - 'indexingQueueEnabled' => $this->configHelper->isQueueActive($storeId), - 'synonymsManagementEnabled' => $this->configHelper->isEnabledSynonyms($storeId), - 'clickAnalyticsEnabled' => $this->configHelper->isClickConversionAnalyticsEnabled($storeId), - 'googleAnalyticsEnabled' => $this->configHelper->isAnalyticsEnabled($storeId), - 'customerGroupsEnabled' => $this->configHelper->isCustomerGroupsEnabled($storeId), - 'merchangisingQRsCreated' => $this->getCountMerchandisingQueries() > 0, - 'noOfMerchandisingQRs' => (int) $this->getCountMerchandisingQueries(), - 'landingPageCreated' => $this->getCountLandingPages() > 0, - 'noOfLandingPages' => (int) $this->getCountLandingPages(), - 'storeId' => $storeId, - ]); - } - - /** - * @param null $storeId - * - * @return bool - */ - private function isSortingChanged($storeId = null) - { - return $this->configHelper->getRawSortingValue($storeId) - !== $this->getDefaultConfigurationFromPath(ConfigHelper::SORTING_INDICES); - } - - /** - * @param null $storeId - * - * @return bool - */ - private function isCustomRankingChanged($storeId = null) - { - return $this->configHelper->getRawProductCustomRanking($storeId) - !== $this->getDefaultConfigurationFromPath(ConfigHelper::PRODUCT_CUSTOM_RANKING); - } - - /** - * @return int - */ - private function getCountMerchandisingQueries() - { - return $this->queryCollection->getSize(); - } - - /** - * @return int - */ - private function getCountLandingPages() - { - return $this->landingPageCollection->getSize(); - } - - /** - * @param string $path - * - * @return mixed|null - */ - private function getDefaultConfigurationFromPath($path) - { - $config = $this->upgradeSchema->getDefaultConfigData(); - if (isset($config[$path]) && $config[$path]) { - return $config[$path]; - } - - return null; - } -} diff --git a/Model/Indexer/AdditionalSection.php b/Model/Indexer/AdditionalSection.php index c689dcc42..bc92f06f0 100755 --- a/Model/Indexer/AdditionalSection.php +++ b/Model/Indexer/AdditionalSection.php @@ -5,12 +5,11 @@ use Algolia\AlgoliaSearch\Helper\ConfigHelper; use Algolia\AlgoliaSearch\Helper\Data; use Algolia\AlgoliaSearch\Model\Queue; -use Magento; use Magento\Framework\Message\ManagerInterface; use Magento\Store\Model\StoreManagerInterface; use Symfony\Component\Console\Output\ConsoleOutput; -class AdditionalSection implements Magento\Framework\Indexer\ActionInterface, Magento\Framework\Mview\ActionInterface +class AdditionalSection implements \Magento\Framework\Indexer\ActionInterface, \Magento\Framework\Mview\ActionInterface { private $fullAction; private $storeManager; diff --git a/Model/Indexer/Category.php b/Model/Indexer/Category.php index 624ad28ad..0aa57ac20 100755 --- a/Model/Indexer/Category.php +++ b/Model/Indexer/Category.php @@ -7,12 +7,11 @@ use Algolia\AlgoliaSearch\Helper\Entity\CategoryHelper; use Algolia\AlgoliaSearch\Model\IndicesConfigurator; use Algolia\AlgoliaSearch\Model\Queue; -use Magento; use Magento\Framework\Message\ManagerInterface; use Magento\Store\Model\StoreManagerInterface; use Symfony\Component\Console\Output\ConsoleOutput; -class Category implements Magento\Framework\Indexer\ActionInterface, Magento\Framework\Mview\ActionInterface +class Category implements \Magento\Framework\Indexer\ActionInterface, \Magento\Framework\Mview\ActionInterface { private $storeManager; private $categoryHelper; diff --git a/Model/Indexer/DeleteProduct.php b/Model/Indexer/DeleteProduct.php index 5aee899bc..ad6078bf1 100755 --- a/Model/Indexer/DeleteProduct.php +++ b/Model/Indexer/DeleteProduct.php @@ -6,12 +6,11 @@ use Algolia\AlgoliaSearch\Helper\ConfigHelper; use Algolia\AlgoliaSearch\Helper\Data; use Algolia\AlgoliaSearch\Model\Queue; -use Magento; use Magento\Framework\Message\ManagerInterface; use Magento\Store\Model\StoreManagerInterface; use Symfony\Component\Console\Output\ConsoleOutput; -class DeleteProduct implements Magento\Framework\Indexer\ActionInterface, Magento\Framework\Mview\ActionInterface +class DeleteProduct implements \Magento\Framework\Indexer\ActionInterface, \Magento\Framework\Mview\ActionInterface { private $fullAction; private $storeManager; diff --git a/Model/Indexer/Page.php b/Model/Indexer/Page.php index 22ba3f212..4d157c49a 100755 --- a/Model/Indexer/Page.php +++ b/Model/Indexer/Page.php @@ -7,12 +7,11 @@ use Algolia\AlgoliaSearch\Helper\Data; use Algolia\AlgoliaSearch\Helper\Entity\PageHelper; use Algolia\AlgoliaSearch\Model\Queue; -use Magento; use Magento\Framework\Message\ManagerInterface; use Magento\Store\Model\StoreManagerInterface; use Symfony\Component\Console\Output\ConsoleOutput; -class Page implements Magento\Framework\Indexer\ActionInterface, Magento\Framework\Mview\ActionInterface +class Page implements \Magento\Framework\Indexer\ActionInterface, \Magento\Framework\Mview\ActionInterface { private $fullAction; private $storeManager; diff --git a/Model/Indexer/Product.php b/Model/Indexer/Product.php index cf1b2ed61..2dc309e24 100755 --- a/Model/Indexer/Product.php +++ b/Model/Indexer/Product.php @@ -9,12 +9,11 @@ use Algolia\AlgoliaSearch\Model\IndexMover; use Algolia\AlgoliaSearch\Model\IndicesConfigurator; use Algolia\AlgoliaSearch\Model\Queue; -use Magento; use Magento\Framework\Message\ManagerInterface; use Magento\Store\Model\StoreManagerInterface; use Symfony\Component\Console\Output\ConsoleOutput; -class Product implements Magento\Framework\Indexer\ActionInterface, Magento\Framework\Mview\ActionInterface +class Product implements \Magento\Framework\Indexer\ActionInterface, \Magento\Framework\Mview\ActionInterface { private $storeManager; private $productHelper; diff --git a/Model/Indexer/QueueRunner.php b/Model/Indexer/QueueRunner.php index 91d0076de..3f0ac6feb 100644 --- a/Model/Indexer/QueueRunner.php +++ b/Model/Indexer/QueueRunner.php @@ -4,11 +4,10 @@ use Algolia\AlgoliaSearch\Helper\ConfigHelper; use Algolia\AlgoliaSearch\Model\Queue; -use Magento; use Magento\Framework\Message\ManagerInterface; use Symfony\Component\Console\Output\ConsoleOutput; -class QueueRunner implements Magento\Framework\Indexer\ActionInterface, Magento\Framework\Mview\ActionInterface +class QueueRunner implements \Magento\Framework\Indexer\ActionInterface, \Magento\Framework\Mview\ActionInterface { const INDEXER_ID = 'algolia_queue_runner'; diff --git a/Model/Indexer/Suggestion.php b/Model/Indexer/Suggestion.php index 2cc1db299..d47196f40 100755 --- a/Model/Indexer/Suggestion.php +++ b/Model/Indexer/Suggestion.php @@ -7,12 +7,11 @@ use Algolia\AlgoliaSearch\Helper\Data; use Algolia\AlgoliaSearch\Helper\Entity\SuggestionHelper; use Algolia\AlgoliaSearch\Model\Queue; -use Magento; use Magento\Framework\Message\ManagerInterface; use Magento\Store\Model\StoreManagerInterface; use Symfony\Component\Console\Output\ConsoleOutput; -class Suggestion implements Magento\Framework\Indexer\ActionInterface, Magento\Framework\Mview\ActionInterface +class Suggestion implements \Magento\Framework\Indexer\ActionInterface, \Magento\Framework\Mview\ActionInterface { private $fullAction; private $storeManager; diff --git a/Model/Observer/Insights/CheckoutCartProductAddAfter.php b/Model/Observer/Insights/CheckoutCartProductAddAfter.php index 68191b5b1..227ae13fb 100644 --- a/Model/Observer/Insights/CheckoutCartProductAddAfter.php +++ b/Model/Observer/Insights/CheckoutCartProductAddAfter.php @@ -6,6 +6,7 @@ use Algolia\AlgoliaSearch\Helper\InsightsHelper; use Magento\Framework\Event\Observer; use Magento\Framework\Event\ObserverInterface; +use Psr\Log\LoggerInterface; class CheckoutCartProductAddAfter implements ObserverInterface { @@ -15,12 +16,17 @@ class CheckoutCartProductAddAfter implements ObserverInterface /** @var InsightsHelper */ private $insightsHelper; + /** @var LoggerInterface */ + private $logger; + public function __construct( Data $dataHelper, - InsightsHelper $insightsHelper + InsightsHelper $insightsHelper, + LoggerInterface $logger ) { $this->dataHelper = $dataHelper; $this->insightsHelper = $insightsHelper; + $this->logger = $logger; } /** @@ -58,19 +64,27 @@ public function execute(Observer $observer) if ($this->getConfigHelper()->isClickConversionAnalyticsEnabled($storeId) && $this->getConfigHelper()->getConversionAnalyticsMode($storeId) === 'add_to_cart') { if ($product->hasData('queryId')) { - $userClient->convertedObjectIDsAfterSearch( + try { + $userClient->convertedObjectIDsAfterSearch( + __('Added to Cart'), + $this->dataHelper->getIndexName('_products', $storeId), + [$product->getId()], + $product->getData('queryId') + ); + } catch (\Exception $e) { + $this->logger->critical($e); + } + } + } else { + try { + $userClient->convertedObjectIDs( __('Added to Cart'), $this->dataHelper->getIndexName('_products', $storeId), - [$product->getId()], - $product->getData('queryId') + [$product->getId()] ); + } catch (\Exception $e) { + $this->logger->critical($e); } - } else { - $userClient->convertedObjectIDs( - __('Added to Cart'), - $this->dataHelper->getIndexName('_products', $storeId), - [$product->getId()] - ); } } } diff --git a/Model/Observer/Merchandising.php b/Model/Observer/Merchandising.php index 018567d84..2968e495c 100755 --- a/Model/Observer/Merchandising.php +++ b/Model/Observer/Merchandising.php @@ -38,8 +38,15 @@ public function execute(Observer $observer) $positions = json_decode($positions, true); + $storeId = $this->request->getParam('store_id'); + if ($storeId > 0) { + $stores[] = $this->storeManager->getStore($storeId); + } else { + $stores = $this->storeManager->getStores(); + } + try { - foreach ($this->storeManager->getStores() as $store) { + foreach ($stores as $store) { if (!$store->getIsActive()) { continue; } diff --git a/Model/Observer/SaveSettings.php b/Model/Observer/SaveSettings.php index 8cb3d9983..1a85d772f 100755 --- a/Model/Observer/SaveSettings.php +++ b/Model/Observer/SaveSettings.php @@ -3,7 +3,6 @@ namespace Algolia\AlgoliaSearch\Model\Observer; use Algolia\AlgoliaSearch\Exceptions\AlgoliaException; -use Algolia\AlgoliaSearch\Model\ConfigurationTracker; use Algolia\AlgoliaSearch\Model\IndicesConfigurator; use Magento\Framework\Event\Observer; use Magento\Framework\Event\ObserverInterface; @@ -17,17 +16,12 @@ class SaveSettings implements ObserverInterface /** @var IndicesConfigurator */ private $indicesConfigurator; - /** @var ConfigurationTracker */ - private $configurationTracker; - public function __construct( StoreManagerInterface $storeManager, - IndicesConfigurator $indicesConfigurator, - ConfigurationTracker $configurationTracker + IndicesConfigurator $indicesConfigurator ) { $this->storeManager = $storeManager; $this->indicesConfigurator = $indicesConfigurator; - $this->configurationTracker = $configurationTracker; } /** @@ -41,7 +35,6 @@ public function execute(Observer $observer) foreach ($storeIds as $storeId) { $this->indicesConfigurator->saveConfigurationToAlgolia($storeId); - $this->configurationTracker->trackConfiguration($storeId); } } } diff --git a/Model/Product/Url.php b/Model/Product/Url.php index 2b281c332..53f92e564 100755 --- a/Model/Product/Url.php +++ b/Model/Product/Url.php @@ -62,7 +62,7 @@ public function getUrl(Product $product, $params = []) $routeParams['_scope'] = $urlDataObject->getStoreId(); } else { $requestPath = $product->getRequestPath(); - if ($requestPath === '') { + if (empty($requestPath) && $requestPath !== false) { $filterData = [ UrlRewrite::ENTITY_ID => $product->getId(), UrlRewrite::ENTITY_TYPE => ProductUrlRewriteGenerator::ENTITY_TYPE, diff --git a/Model/Source/Facets.php b/Model/Source/Facets.php index be3a6e6b2..391a845a7 100755 --- a/Model/Source/Facets.php +++ b/Model/Source/Facets.php @@ -2,29 +2,8 @@ namespace Algolia\AlgoliaSearch\Model\Source; -use Algolia\AlgoliaSearch\Helper\ConfigHelper; -use Algolia\AlgoliaSearch\Helper\Entity\CategoryHelper; -use Algolia\AlgoliaSearch\Helper\Entity\ProductHelper; -use Algolia\AlgoliaSearch\Helper\ProxyHelper; -use Magento\Backend\Block\Template\Context; - class Facets extends AbstractTable { - protected $proxyHelper; - - public function __construct( - Context $context, - ProductHelper $producthelper, - CategoryHelper $categoryHelper, - ConfigHelper $configHelper, - ProxyHelper $proxyHelper, - array $data = [] - ) { - $this->proxyHelper = $proxyHelper; - - parent::__construct($context, $producthelper, $categoryHelper, $configHelper, $data); - } - protected function getTableData() { $productHelper = $this->productHelper; @@ -62,26 +41,11 @@ protected function getTableData() ], ]; - if ($this->isQueryRulesEnabled()) { - $config['create_rule'] = [ - 'label' => 'Create Query rule?', - 'values' => ['2' => 'No', '1' => 'Yes'], - ]; - } + $config['create_rule'] = [ + 'label' => 'Create Query rule?', + 'values' => ['2' => 'No', '1' => 'Yes'], + ]; return $config; } - - private function isQueryRulesEnabled() - { - $info = $this->proxyHelper->getInfo(\Algolia\AlgoliaSearch\Helper\ProxyHelper::INFO_TYPE_QUERY_RULES); - - // In case the call to API proxy fails, - // be "nice" and return true - if ($info && array_key_exists('query_rules', $info)) { - return $info['query_rules']; - } - - return true; - } } diff --git a/Model/Source/JobMethods.php b/Model/Source/JobMethods.php index 049698dcd..c988a5a29 100644 --- a/Model/Source/JobMethods.php +++ b/Model/Source/JobMethods.php @@ -9,6 +9,7 @@ class JobMethods implements \Magento\Framework\Data\OptionSourceInterface 'moveIndexWithSetSettings' => 'Move Index', 'deleteObjects' => 'Object deletion', 'rebuildStoreCategoryIndex' => 'Category Reindex', + 'rebuildCategoryIndex' => 'Category Reindex', 'rebuildStoreProductIndex' => 'Product Reindex', 'rebuildProductIndex' => 'Product Reindex', 'rebuildStoreAdditionalSectionsIndex' => 'Additional Section Reindex', diff --git a/Model/Source/MaxRecordSize.php b/Model/Source/MaxRecordSize.php deleted file mode 100644 index 05b1679e7..000000000 --- a/Model/Source/MaxRecordSize.php +++ /dev/null @@ -1,52 +0,0 @@ -configHelper = $configHelper; - $this->proxyHelper = $proxyHelper; - } - - /** - * Legacy default is 20000 - * - * @return array - */ - public function toOptionArray() - { - $options[] = $this->configHelper->getDefaultMaxRecordSize(); - $clientData = $this->proxyHelper->getClientConfigurationData(); - - if ($clientData && isset($clientData['max_record_size'])) { - if (!in_array($clientData['max_record_size'], $options)) { - $options[] = $clientData['max_record_size']; - } - } - - rsort($options); - - $formattedOptions = []; - foreach ($options as $option) { - $formattedOptions[] = [ - 'value' => $option, - 'label' => $option, - ]; - } - - return $formattedOptions; - } -} diff --git a/Plugin/RenderingCacheContextPlugin.php b/Plugin/RenderingCacheContextPlugin.php index 4de894175..b60c4f76a 100755 --- a/Plugin/RenderingCacheContextPlugin.php +++ b/Plugin/RenderingCacheContextPlugin.php @@ -39,23 +39,24 @@ public function __construct( * we set a different page variation, and the FPC stores a different cached page) * * @param HttpContext $subject + * @param string[] $data * * @return array */ - public function beforeGetVaryString(HttpContext $subject) + public function afterGetData(HttpContext $subject, $data) { $storeId = $this->storeManager->getStore()->getId(); - if (! ($this->request->getControllerName() === 'category' - && $this->configHelper->replaceCategories($storeId) === true)) { - return []; + if (!($this->request->getControllerName() === 'category' + && $this->configHelper->replaceCategories($storeId) === true)) { + return $data; } $context = $this->configHelper->preventBackendRendering() ? self::RENDERING_WITHOUT_BACKEND : self::RENDERING_WITH_BACKEND; - $subject->setValue(self::RENDERING_CONTEXT, $context, self::RENDERING_WITH_BACKEND); + $data[self::RENDERING_CONTEXT] = $context; - return []; + return $data; } } diff --git a/README.md b/README.md index e6ea6f98d..813ea8892 100755 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ Algolia Search for Magento 2 ================== -![Latest version](https://img.shields.io/badge/latest-3.1.0-green.svg) +![Latest version](https://img.shields.io/badge/latest-3.2.0-green.svg) ![Magento 2](https://img.shields.io/badge/Magento-%32.3,%202.4-blue.svg) [![CircleCI](https://circleci.com/gh/algolia/algoliasearch-magento-2/tree/master.svg?style=svg)](https://circleci.com/gh/algolia/algoliasearch-magento-2/tree/master) diff --git a/Test/Integration/TestCase.php b/Test/Integration/TestCase.php index 8c6bec8f1..00c7947d2 100644 --- a/Test/Integration/TestCase.php +++ b/Test/Integration/TestCase.php @@ -114,10 +114,10 @@ private function bootstrap() $this->configHelper = $config = $this->getObjectManager()->create(ConfigHelper::class); $this->setConfig('algoliasearch_credentials/credentials/application_id', getenv('ALGOLIA_APPLICATION_ID')); - $this->setConfig('algoliasearch_credentials/credentials/search_only_api_key', getenv('ALGOLIA_SEARCH_API_KEY')); + $this->setConfig('algoliasearch_credentials/credentials/search_only_api_key', getenv('ALGOLIA_SEARCH_KEY_1') ?: getenv('ALGOLIA_SEARCH_API_KEY')); $this->setConfig('algoliasearch_credentials/credentials/api_key', getenv('ALGOLIA_API_KEY')); - $this->indexPrefix = 'TRAVIS_M2_' . getmypid() . (getenv('INDEX_PREFIX') ?: 'magento20tests_'); + $this->indexPrefix = 'magento2_' . date('Y-m-d_H:i:s') . '_' . (getenv('INDEX_PREFIX') ?: 'circleci_'); $this->setConfig('algoliasearch_credentials/credentials/index_prefix', $this->indexPrefix); $this->boostrapped = true; diff --git a/ViewModel/Adminhtml/Analytics/Overview.php b/ViewModel/Adminhtml/Analytics/Overview.php index 2fb96f5d2..cbf7b3d07 100644 --- a/ViewModel/Adminhtml/Analytics/Overview.php +++ b/ViewModel/Adminhtml/Analytics/Overview.php @@ -199,8 +199,7 @@ public function getDailySearchData() $search['conversion'] = $this->getDateValue($conversion, $search['date'], 'rate'); } - $date = $this->getBackendView()->getDateTime()->date($search['date']); - $search['formatted'] = date('M, d', $date->getTimestamp()); + $search['formatted'] = date('M, d', strtotime($search['date'])); } return $searches; diff --git a/ViewModel/Adminhtml/Merchandising/Page.php b/ViewModel/Adminhtml/Merchandising/Page.php deleted file mode 100644 index 33193e747..000000000 --- a/ViewModel/Adminhtml/Merchandising/Page.php +++ /dev/null @@ -1,37 +0,0 @@ -proxyHelper = $proxyHelper; - } - - /** - * @return bool - */ - public function canAccessLandingPageBuilder() - { - $clientData = $this->proxyHelper->getClientConfigurationData(); - $planLevel = (isset($clientData['plan_level']) ? (int) $clientData['plan_level'] : 1); - - return $planLevel > 1; - } - - /** - * @return bool - */ - public function canAccessMerchandisingFeature() - { - $clientData = $this->proxyHelper->getClientConfigurationData(); - - return isset($clientData['query_rules']) ? (bool) $clientData['query_rules'] : false; - } -} diff --git a/ViewModel/Adminhtml/Support/Contact.php b/ViewModel/Adminhtml/Support/Contact.php deleted file mode 100644 index 89d5c847a..000000000 --- a/ViewModel/Adminhtml/Support/Contact.php +++ /dev/null @@ -1,86 +0,0 @@ -backendView = $backendView; - $this->supportHelper = $supportHelper; - $this->moduleList = $moduleList; - $this->authSession = $authSession; - } - - /** @return bool */ - public function isExtensionSupportEnabled() - { - return $this->supportHelper->isExtensionSupportEnabled(); - } - - /** @return string */ - public function getExtensionVersion() - { - return $this->moduleList->getOne('Algolia_AlgoliaSearch')['setup_version']; - } - - /** @return string */ - public function getDefaultName() - { - $name = $this->backendView->getRequest()->getParam('name'); - - return $name ?: $this->getCurrenctAdmin()->getName(); - } - - /** @return string */ - public function getDefaultEmail() - { - $name = $this->backendView->getRequest()->getParam('email'); - - return $name ?: $this->getCurrenctAdmin()->getEmail(); - } - - /** - * @param string $message - * - * @return string - */ - public function getTooltipHtml($message) - { - return $this->backendView->getTooltipHtml($message); - } - - /** @return User|null */ - private function getCurrenctAdmin() - { - return $this->authSession->getUser(); - } -} diff --git a/ViewModel/Adminhtml/Support/Overview.php b/ViewModel/Adminhtml/Support/Overview.php index 257688b56..1bd8107f3 100644 --- a/ViewModel/Adminhtml/Support/Overview.php +++ b/ViewModel/Adminhtml/Support/Overview.php @@ -24,12 +24,6 @@ public function __construct(BackendView $backendView, SupportHelper $supportHelp $this->supportHelper = $supportHelper; } - /** @return bool */ - public function isExtensionSupportEnabled() - { - return $this->supportHelper->isExtensionSupportEnabled(); - } - /** @return string */ public function getApplicationId() { diff --git a/composer.json b/composer.json index 6fe02eecf..59be871aa 100755 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "description": "Algolia Search integration for Magento 2", "type": "magento2-module", "license": ["MIT"], - "version": "3.1.0", + "version": "3.2.0", "require": { "magento/framework": "~102.0|~103.0", "algolia/algoliasearch-client-php": "^2.4", diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 064440900..1a9d41ceb 100755 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -632,7 +632,11 @@ Magento\Config\Model\Config\Source\Yesno - Algolia\AlgoliaSearch\Model\Backend\EnableClickAnalytics + + + @@ -916,7 +920,6 @@ - Algolia\AlgoliaSearch\Block\System\Form\Field\Logo Magento\Config\Model\Config\Source\Yesno diff --git a/etc/csp_whitelist.xml b/etc/csp_whitelist.xml index 1cd489e6a..d72b51192 100644 --- a/etc/csp_whitelist.xml +++ b/etc/csp_whitelist.xml @@ -11,12 +11,7 @@ *.algolia.net *.algolia.com - - - - - *.algolia.net - *.algolia.com + *.algolianet.com diff --git a/etc/module.xml b/etc/module.xml index 887b13ede..2be30d3ee 100755 --- a/etc/module.xml +++ b/etc/module.xml @@ -1,11 +1,11 @@ - + - + diff --git a/etc/mview.xml b/etc/mview.xml index 9f426e4a5..a85787433 100755 --- a/etc/mview.xml +++ b/etc/mview.xml @@ -7,7 +7,7 @@ - + diff --git a/i18n/en_US.csv b/i18n/en_US.csv index 4f8bbd8f4..ce114e710 100644 --- a/i18n/en_US.csv +++ b/i18n/en_US.csv @@ -36,6 +36,7 @@ Go,Go "See products in","See products in" "All departments","All departments" "or in","or in" +"out of","out of" " Algolia Search diff --git a/view/adminhtml/layout/algolia_algoliasearch_handle_query_access_denied.xml b/view/adminhtml/layout/algolia_algoliasearch_handle_query_access_denied.xml deleted file mode 100644 index 378552a7d..000000000 --- a/view/adminhtml/layout/algolia_algoliasearch_handle_query_access_denied.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - Algolia | Query Merchandiser - - - - - - - diff --git a/view/adminhtml/layout/algolia_algoliasearch_merchandising_index.xml b/view/adminhtml/layout/algolia_algoliasearch_merchandising_index.xml index a8c49fc48..2ef0e94da 100644 --- a/view/adminhtml/layout/algolia_algoliasearch_merchandising_index.xml +++ b/view/adminhtml/layout/algolia_algoliasearch_merchandising_index.xml @@ -7,14 +7,7 @@ - - - - Algolia\AlgoliaSearch\ViewModel\Adminhtml\Merchandising\Page - - - - + diff --git a/view/adminhtml/layout/algolia_algoliasearch_support_contact.xml b/view/adminhtml/layout/algolia_algoliasearch_support_contact.xml deleted file mode 100644 index 27ffd89b0..000000000 --- a/view/adminhtml/layout/algolia_algoliasearch_support_contact.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - \ No newline at end of file + diff --git a/view/adminhtml/templates/configuration.phtml b/view/adminhtml/templates/configuration.phtml index 7067797fb..843fe77ec 100755 --- a/view/adminhtml/templates/configuration.phtml +++ b/view/adminhtml/templates/configuration.phtml @@ -14,10 +14,6 @@ $extensionNotices = []; $personalizationStatus = 0; if (preg_match('/algoliasearch_/', $section)) { - if ($section === 'algoliasearch_cc_analytics') { - $isClickAnalyticsEnabled = $viewModel->isClickAnalyticsEnabled(); - } - $linksAndVideoTemplate = $viewModel->getLinksAndVideoTemplate($section); $extensionNotices = $viewModel->getExtensionNotices(); $personalizationStatus = $viewModel->getPersonalizationStatus(); diff --git a/view/adminhtml/templates/landingpage/access_denied.phtml b/view/adminhtml/templates/landingpage/access_denied.phtml deleted file mode 100644 index d079049b3..000000000 --- a/view/adminhtml/templates/landingpage/access_denied.phtml +++ /dev/null @@ -1,21 +0,0 @@ -getViewFileUrl('Algolia_AlgoliaSearch::images/illu-lpb.svg'); -$bookIllustration = $block->getViewFileUrl('Algolia_AlgoliaSearch::images/icon-book.svg'); -$starsIllustration = $block->getViewFileUrl('Algolia_AlgoliaSearch::images/icon-stars.svg'); -?> -
-
- -
- -

The Landing Page Builder allows you to easily create customised landing pages out of search queries.

-

It is a powerful marketing tool to promote products, with a strong focus on SEO. To find out more about the Landing Page Builder, please see our documentation.

-
-
- -

To get access to this Algolia feature, please consider upgrading to a higher plan.

-
-
diff --git a/view/adminhtml/templates/landingpage/search-configuration.phtml b/view/adminhtml/templates/landingpage/search-configuration.phtml index 1eed9efc7..c32ae2e52 100644 --- a/view/adminhtml/templates/landingpage/search-configuration.phtml +++ b/view/adminhtml/templates/landingpage/search-configuration.phtml @@ -77,21 +77,13 @@ $isConfig = [

Products shown on landing page

- getPlanLevel() == 3) : ?> - - +
- getPlanLevel() < 3) : ?> -
- -

To be able to sort search results in particular order (promote or demote items), please consider upgrading to a higher plan.

-
-
@@ -106,9 +98,7 @@ $isConfig = [
- getPlanLevel() == 3) : ?> - - + @@ -116,9 +106,7 @@ $isConfig = [ @@ -132,24 +120,22 @@ $isConfig = [ - getPlanLevel() == 3) : ?> - - + {{/hits}} @@ -177,9 +163,7 @@ $isConfig = [ - getPlanLevel() == 3) : ?> - - + @@ -187,9 +171,7 @@ $isConfig = [ @@ -203,7 +185,6 @@ $isConfig = [ - getPlanLevel() == 3) : ?> - {{/hits}} @@ -232,9 +212,7 @@ $isConfig = [ @@ -248,7 +226,6 @@ $isConfig = [ - getPlanLevel() == 3) : ?> - @@ -660,12 +636,10 @@ $isConfig = [ } ); - getPlanLevel() == 3) : ?> search.on('render', function() { initAutocomplete(); initSortableTable(); }); - search.start(); diff --git a/view/adminhtml/templates/merchandising/page.phtml b/view/adminhtml/templates/merchandising/page.phtml index b2d65c8ab..1ae3de7eb 100644 --- a/view/adminhtml/templates/merchandising/page.phtml +++ b/view/adminhtml/templates/merchandising/page.phtml @@ -1,7 +1,5 @@ -getViewModel(); ?> +/** @var \Magento\Backend\Block\Template $block */ ?>
- canAccessMerchandisingFeature()): ?> - escapeHtml(__('Merchandise search results')) ?> - - getChildHtml('upsell') ?> - + escapeHtml(__('Merchandise search results')) ?>
@@ -45,12 +39,7 @@

escapeHtml(__('Give more visibility to specific products within a category page. Promote or demote displayed items by using a simple drag and drop mechanism.')) ?>

- - canAccessMerchandisingFeature()): ?> - escapeHtml(__('Promote products within a category')) ?> - - getChildHtml('upsell') ?> - + escapeHtml(__('Promote products within a category')) ?>
@@ -60,11 +49,6 @@

escapeHtml(__('The Landing Page Builder allows you to easily create customised landing pages out of search queries. It is a powerful marketing tool to promote products, with a strong focus on SEO.')) ?>

- - canAccessLandingPageBuilder()): ?> - escapeHtml(__('Create a new landing page')) ?> - - getChildHtml('upsell') ?> - + escapeHtml(__('Create a new landing page')) ?>
- \ No newline at end of file + diff --git a/view/adminhtml/templates/query/access_denied.phtml b/view/adminhtml/templates/query/access_denied.phtml deleted file mode 100644 index 94231c2ae..000000000 --- a/view/adminhtml/templates/query/access_denied.phtml +++ /dev/null @@ -1,21 +0,0 @@ -getViewFileUrl('Algolia_AlgoliaSearch::images/illu-querymerchandiser.svg'); -$bookIllustration = $block->getViewFileUrl('Algolia_AlgoliaSearch::images/icon-book.svg'); -$starsIllustration = $block->getViewFileUrl('Algolia_AlgoliaSearch::images/icon-stars.svg'); -?> -
-
- -
- -

Easily promote or demote products for a search. Based on Algolia's Query rules, the Query Merchandiser allows you to enchance the ranking behaviour for specific search queries.

-

Merchandising a query will create a new query rule (which are part of your Algolia plan). To find out more about the Query Merchandiser, please see our documentation.

-
-
- -

To get access to this Algolia feature, please consider upgrading to a higher plan.

-
-
diff --git a/view/adminhtml/templates/support/contact.phtml b/view/adminhtml/templates/support/contact.phtml deleted file mode 100644 index caadef989..000000000 --- a/view/adminhtml/templates/support/contact.phtml +++ /dev/null @@ -1,158 +0,0 @@ -getViewModel(); - -?> - -

escapeHtml(__('Contact Algolia')) ?>

- -isExtensionSupportEnabled()) : ?> -
- - -
-
-
- - -
- -
-
- -
- -
- -
-
- -
- -
- -
-
- -
- -
- - -
-
i
- - To provide a better support, this information will be attached to your request: -
    -
  • Magento and Algolia extension version numbers
  • -
  • Algolia extension configuration
  • -
  • - Indexing queue information - getTooltipHtml(__(' - - Number of jobs in indexing queue
    - - Information about last 20 failed indexing jobs
    - - Creation time of the oldest job in indexing queue - ')); - ?> -
  • -
- No personal information will be sent to Algolia. -
-
-
-
- - -
- -
- -
-
-
-
-
-
-
- escapeHtml(__('Related to your subject ...')) ?> -
- -
-
- - - - - getViewFileUrl('Algolia_AlgoliaSearch::images/illu-help.svg'); - $bookIllustration = $block->getViewFileUrl('Algolia_AlgoliaSearch::images/icon-book.svg'); - $starsIllustration = $block->getViewFileUrl('Algolia_AlgoliaSearch::images/icon-stars.svg'); - ?> -
- -
- -

There's Documentation, Tutorials and Videos - But we also offer expert advice and solutions through direct email support by Algolia engineers and product specialists.

-
-
- -

To get access to this Algolia feature, please consider upgrading to a higher plan.

-
-
- - diff --git a/view/adminhtml/templates/support/overview.phtml b/view/adminhtml/templates/support/overview.phtml index 4e91aa1b5..55d4f8dbc 100644 --- a/view/adminhtml/templates/support/overview.phtml +++ b/view/adminhtml/templates/support/overview.phtml @@ -25,11 +25,6 @@ $videoFeatures = $block->getViewFileUrl('Algolia_AlgoliaSearch::images/video-fea escapeHtml(__('Search Documentation')) ?> -
  • - - escapeHtml(__('Contact Us')) ?> - -
  • @@ -250,9 +245,4 @@ $videoFeatures = $block->getViewFileUrl('Algolia_AlgoliaSearch::images/video-fea
    - -
    - getChildHtml('support_contact') ?> -
    - diff --git a/view/adminhtml/templates/tracking.phtml b/view/adminhtml/templates/tracking.phtml deleted file mode 100644 index 0952f2963..000000000 --- a/view/adminhtml/templates/tracking.phtml +++ /dev/null @@ -1,389 +0,0 @@ -getViewModel(); -$applicationId = $view->getApplicationId(); -?> - - \ No newline at end of file diff --git a/view/adminhtml/templates/ui/upsell-plan.phtml b/view/adminhtml/templates/ui/upsell-plan.phtml deleted file mode 100644 index ef4e2f79b..000000000 --- a/view/adminhtml/templates/ui/upsell-plan.phtml +++ /dev/null @@ -1,7 +0,0 @@ - -
    - -

    To get access to this Algolia feature, please consider upgrading to a higher plan.

    -
    \ No newline at end of file diff --git a/view/adminhtml/web/css/analytics.css b/view/adminhtml/web/css/analytics.css index a4c456833..88e42226e 100644 --- a/view/adminhtml/web/css/analytics.css +++ b/view/adminhtml/web/css/analytics.css @@ -73,6 +73,10 @@ padding: 2rem; } +.algoliasearch-analytics-overview .section.popular-results { + margin-left: 2% +} + .algoliasearch-analytics-overview .analytics-footer { margin-top: 1.5rem; text-align: left; diff --git a/view/adminhtml/web/css/landing-page.css b/view/adminhtml/web/css/landing-page.css index 2d9e91ad2..e70d6532f 100644 --- a/view/adminhtml/web/css/landing-page.css +++ b/view/adminhtml/web/css/landing-page.css @@ -783,7 +783,7 @@ a.ais-current-refined-values--link:hover { padding-top: 50px; } -@media (max-width: 992px) { +@media (max-width: 991px) { #algolia_instant_selector .facets { padding-top: 10px; } diff --git a/view/adminhtml/web/css/support.css b/view/adminhtml/web/css/support.css index 811a894fa..ca788df5a 100644 --- a/view/adminhtml/web/css/support.css +++ b/view/adminhtml/web/css/support.css @@ -362,10 +362,6 @@ a.footer { padding-top: 20px; } -#algolia-contact-panel { - display: none; -} - /* access denied */ .algolia-suggestions-header { width : 100%; diff --git a/view/frontend/templates/instant/stats.phtml b/view/frontend/templates/instant/stats.phtml index 5b740847c..65c246220 100644 --- a/view/frontend/templates/instant/stats.phtml +++ b/view/frontend/templates/instant/stats.phtml @@ -2,7 +2,7 @@ {{#hasOneResult}}1escapeHtml(__('result')); ?> found{{/hasOneResult}} {{#hasManyResults}} - {{^hasNoResults}}{{first}}-{{last}} out of{{/hasNoResults}} + {{^hasNoResults}}{{first}}-{{last}} escapeHtml(__('out of')); ?>{{/hasNoResults}} {{nbHits}} escapeHtml(__('results found')); ?> diff --git a/view/frontend/web/instantsearch.js b/view/frontend/web/instantsearch.js index 624e03d8f..deb9831a0 100644 --- a/view/frontend/web/instantsearch.js +++ b/view/frontend/web/instantsearch.js @@ -477,12 +477,10 @@ requirejs(['algoliaBundle', 'Magento_Catalog/js/price-utils'], function (algolia return ['rangeInput', { container: facet.wrapper.appendChild(createISWidgetContainer(facet.attribute)), attribute: facet.attribute, - labels: { - currency: algoliaConfig.currencySymbol, - separator: algoliaConfig.translations.to, - button: algoliaConfig.translations.go - }, - templates: templates, + templates: $.extend({ + separatorText: algoliaConfig.translations.to, + submitText: algoliaConfig.translations.go + }, templates), cssClasses: { root: 'conjunctive' }, @@ -619,6 +617,8 @@ requirejs(['algoliaBundle', 'Magento_Catalog/js/price-utils'], function (algolia input.value = ''; }); } + + input.value = renderOptions.query; } }); diff --git a/view/frontend/web/internals/common.js b/view/frontend/web/internals/common.js index c4768ea52..23ebda35b 100644 --- a/view/frontend/web/internals/common.js +++ b/view/frontend/web/internals/common.js @@ -98,7 +98,7 @@ requirejs(['algoliaBundle'], function(algoliaBundle) { var colors = []; $.each(hit._highlightResult.color, function (i, color) { - if (color.matchLevel === 'none') { + if (color.matchLevel === undefined || color.matchLevel === 'none') { return; } @@ -106,7 +106,6 @@ requirejs(['algoliaBundle'], function(algoliaBundle) { if (algoliaConfig.useAdaptiveImage === true) { var matchedColor = color.matchedWords.join(' '); - if (hit.images_data && color.fullyHighlighted && color.fullyHighlighted === true) { matchedColors.push(matchedColor); } @@ -292,6 +291,7 @@ requirejs(['algoliaBundle'], function(algoliaBundle) { hit.displayKey = hit.displayKey || hit.name; + hit.__indexName = algoliaConfig.indexName + "_" + section.name; hit.__queryID = payload.queryID; hit.__position = payload.hits.indexOf(hit) + 1; @@ -336,6 +336,7 @@ requirejs(['algoliaBundle'], function(algoliaBundle) { var toEscape = hit._highlightResult.query.value; hit._highlightResult.query.value = algoliaBundle.autocomplete.escapeHighlightedString(toEscape); + hit.__indexName = algoliaConfig.indexName + "_" + section.name; hit.__queryID = payload.queryID; hit.__position = payload.hits.indexOf(hit) + 1; @@ -355,6 +356,7 @@ requirejs(['algoliaBundle'], function(algoliaBundle) { suggestion: function (hit, payload) { hit.url = algoliaConfig.baseUrl + '/catalogsearch/result/?q=' + hit.value + '&refinement_key=' + encodeURIComponent(section.name); + hit.__indexName = algoliaConfig.indexName + "_section_" + section.name; hit.__queryID = payload.queryID; hit.__position = payload.hits.indexOf(hit) + 1; @@ -569,7 +571,7 @@ requirejs(['algoliaBundle'], function(algoliaBundle) { uiStateProductIndex.hierarchicalMenu[currentFacet.attribute+ '.level0'].join('~')); } // Handle sliders - if (currentFacet.type == 'slider') { + if (currentFacet.type == 'slider' || currentFacet.type == 'priceRanges') { routeParameters[currentFacet.attribute] = (uiStateProductIndex.range && uiStateProductIndex.range[currentFacet.attribute] && uiStateProductIndex.range[currentFacet.attribute]); @@ -621,7 +623,7 @@ requirejs(['algoliaBundle'], function(algoliaBundle) { uiStateProductIndex['hierarchicalMenu']['categories.level0'] = [algoliaConfig.request.path]; } // Handle sliders - if (currentFacet.type == 'slider') { + if (currentFacet.type == 'slider' || currentFacet.type == 'priceRanges') { var currentFacetAttribute = currentFacet.attribute; if (currentFacetAttribute.indexOf("price") !== -1) { currentFacetAttribute += algoliaConfig.priceKey; diff --git a/view/frontend/web/internals/grid.css b/view/frontend/web/internals/grid.css index 3fffe2706..16308eb09 100644 --- a/view/frontend/web/internals/grid.css +++ b/view/frontend/web/internals/grid.css @@ -105,7 +105,7 @@ } } -@media (max-width: 992px) { +@media (max-width: 991px) { #algolia_instant_selector .visible-sm { display: block !important; }
    SKU Name PricePin itPin it
    - getPlanLevel() == 3) : ?> - - + {{ objectID }} {{{ _highlightResult.name.value }}} {{ price.getCurrencyCode() ?>.default_formated }} - - + +
    SKU Name PricePin itPin it
    - getPlanLevel() == 3) : ?> - - + {{ objectID }} {{{ _highlightResult.name.value }}} {{ price.getCurrencyCode() ?>.default_formated }}
    - getPlanLevel() == 3) : ?> - - + {{ objectID }} {{{ name }}} {{ price.getCurrencyCode() ?>.default_formated }}