Skip to content

Commit

Permalink
Develop > Master (#1116)
Browse files Browse the repository at this point in the history
  • Loading branch information
damcou authored Nov 26, 2020
1 parent 188ec3e commit 4762fe2
Show file tree
Hide file tree
Showing 25 changed files with 540 additions and 352 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
# CHANGE LOG

## 3.0.2

### FEATURES
- CMS Page indexing improvement (#1113) (by @vmalyk)

### UPDATES
- Add tags for QM and LPB queries to use VM if applicable (#1103)
- InfiniteHits change showMoreLabel to showMoreText (#1105)
- Turn off Perso when it’s not available in the plan but activated in the Magento admin (#1104)
- Keep custom Rules set directly on Algolia dashboard for CMS Pages, Suggestions and Additional sections. (#1106)
- Remove from composer suggestion for es compatibility (#1114)

### FIXES
- linter fix templates (#1108)
- Configurable product with broken image when set to “no_selection” (#1101) (by @dverkade)
- Insights Analytics - Fix Add to Cart Conversion (#1111)
- Added try/catch on CheckoutSuccess event (#1112)
- Merge 2 connect-src policy sections to 1 (#1110) (by @vmalyk)

## 3.0.1

### UPDATES
Expand Down
11 changes: 10 additions & 1 deletion Helper/Configuration/NoticeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class NoticeHelper extends \Magento\Framework\App\Helper\AbstractHelper
/** @var ProxyHelper */
private $proxyHelper;

/** @var PersonalizationHelper */
private $personalizationHelper;

/** @var ModuleManager */
private $moduleManager;

Expand Down Expand Up @@ -63,6 +66,7 @@ public function __construct(
\Magento\Framework\App\Helper\Context $context,
ConfigHelper $configHelper,
ProxyHelper $proxyHelper,
PersonalizationHelper $personalizationHelper,
ModuleManager $moduleManager,
ObjectManagerInterface $objectManager,
ExtensionNotification $extensionNotification,
Expand All @@ -72,6 +76,7 @@ public function __construct(
) {
$this->configHelper = $configHelper;
$this->proxyHelper = $proxyHelper;
$this->personalizationHelper = $personalizationHelper;
$this->moduleManager = $moduleManager;
$this->objectManager = $objectManager;
$this->extensionNotification = $extensionNotification;
Expand Down Expand Up @@ -318,14 +323,18 @@ 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);
Expand Down
18 changes: 17 additions & 1 deletion Helper/Configuration/PersonalizationHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Algolia\AlgoliaSearch\Helper\Configuration;

use Magento\Framework\App\Config\ConfigResource\ConfigInterface as ConfigResourceInterface;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Store\Model\ScopeInterface;

Expand Down Expand Up @@ -30,11 +31,16 @@ class PersonalizationHelper extends \Magento\Framework\App\Helper\AbstractHelper
/** @var ScopeConfigInterface */
private $configInterface;

/** @var ConfigResourceInterface */
private $configResourceInterface;

public function __construct(
\Magento\Framework\App\Helper\Context $context,
ScopeConfigInterface $configInterface
ScopeConfigInterface $configInterface,
ConfigResourceInterface $configResourceInterface
) {
$this->configInterface = $configInterface;
$this->configResourceInterface = $configResourceInterface;
parent::__construct($context);
}

Expand All @@ -48,6 +54,16 @@ public function isPersoEnabled($storeId = null)
return $this->configInterface->isSetFlag(self::IS_PERSO_ENABLED, ScopeInterface::SCOPE_STORE, $storeId);
}

/**
* @param int|null $storeId
*
* @return void
*/
public function disablePerso($storeId = null)
{
$this->configResourceInterface->saveConfig(self::IS_PERSO_ENABLED, 0, 'default', 0);
}

/**
* @param int|null $storeId
*
Expand Down
52 changes: 39 additions & 13 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,14 @@ public function rebuildStoreAdditionalSectionsIndex($storeId)
$this->algoliaHelper->addObjects($chunk, $indexName . '_tmp');
}

$this->algoliaHelper->copyQueryRules($indexName, $indexName . '_tmp');
$this->algoliaHelper->moveIndex($indexName . '_tmp', $indexName);

$this->algoliaHelper->setSettings($indexName, $this->additionalSectionHelper->getIndexSettings($storeId));
}
}

public function rebuildStorePageIndex($storeId)
public function rebuildStorePageIndex($storeId, array $pageIds = null)
{
if ($this->isIndexingEnabled($storeId) === false) {
return;
Expand All @@ -189,20 +190,44 @@ public function rebuildStorePageIndex($storeId)

$this->startEmulation($storeId);

$pages = $this->pageHelper->getPages($storeId);
$pages = $this->pageHelper->getPages($storeId, $pageIds);

$this->stopEmulation();

foreach (array_chunk($pages, 100) as $chunk) {
try {
$this->algoliaHelper->addObjects($chunk, $indexName . '_tmp');
} catch (\Exception $e) {
$this->logger->log($e->getMessage());
continue;
// if there are pageIds defined, do not index to _tmp
$isFullReindex = (!$pageIds);

if (isset($pages['toIndex']) && count($pages['toIndex'])) {
$pagesToIndex = $pages['toIndex'];
$toIndexName = $indexName . ($isFullReindex ? '_tmp' : '');

foreach (array_chunk($pagesToIndex, 100) as $chunk) {
try {
$this->algoliaHelper->addObjects($chunk, $toIndexName);
} catch (\Exception $e) {
$this->logger->log($e->getMessage());
continue;
}
}
}

$this->algoliaHelper->moveIndex($indexName . '_tmp', $indexName);
if (!$isFullReindex && isset($pages['toRemove']) && count($pages['toRemove'])) {
$pagesToRemove = $pages['toRemove'];

foreach (array_chunk($pagesToRemove, 100) as $chunk) {
try {
$this->algoliaHelper->deleteObjects($chunk, $indexName);
} catch (\Exception $e) {
$this->logger->log($e->getMessage());
continue;
}
}
}

if ($isFullReindex) {
$this->algoliaHelper->copyQueryRules($indexName, $indexName . '_tmp');
$this->algoliaHelper->moveIndex($indexName . '_tmp', $indexName);
}

$this->algoliaHelper->setSettings($indexName, $this->pageHelper->getIndexSettings($storeId));
}
Expand Down Expand Up @@ -289,6 +314,7 @@ public function moveStoreSuggestionIndex($storeId)
$tmpIndexName = $this->getIndexName($indexNameSuffix, $storeId, true);
$indexName = $this->getIndexName($indexNameSuffix, $storeId);

$this->algoliaHelper->copyQueryRules($indexName, $tmpIndexName);
$this->algoliaHelper->moveIndex($tmpIndexName, $indexName);
}

Expand Down Expand Up @@ -592,8 +618,8 @@ public function rebuildStoreProductIndexPage(
return;
}

$wrapperLogMessage = 'rebuildStoreProductIndexPage: ' . $this->logger->getStoreName($storeId) . ',
page ' . $page . ',
$wrapperLogMessage = 'rebuildStoreProductIndexPage: ' . $this->logger->getStoreName($storeId) . ',
page ' . $page . ',
pageSize ' . $pageSize;
$this->logger->start($wrapperLogMessage);

Expand Down Expand Up @@ -622,8 +648,8 @@ public function rebuildStoreProductIndexPage(
['collection' => $collection, 'store' => $storeId]
);

$logMessage = 'LOADING: ' . $this->logger->getStoreName($storeId) . ',
collection page: ' . $page . ',
$logMessage = 'LOADING: ' . $this->logger->getStoreName($storeId) . ',
collection page: ' . $page . ',
pageSize: ' . $pageSize;

$this->logger->start($logMessage);
Expand Down
34 changes: 25 additions & 9 deletions Helper/Entity/PageHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,29 +91,30 @@ public function getIndexSettings($storeId)
return $indexSettings;
}

public function getPages($storeId)
public function getPages($storeId, array $pageIds = null)
{
/** @var \Magento\Cms\Model\ResourceModel\Page\Collection $magentoPages */
$magentoPages = $this->pageCollectionFactory->create()
->addStoreFilter($storeId)
->addFieldToFilter('is_active', 1);

$excludedPages = array_values($this->configHelper->getExcludedPages());
if ($pageIds && count($pageIds)) {
$magentoPages->addFieldToFilter('page_id', ['in' => $pageIds]);
}

foreach ($excludedPages as &$excludedPage) {
$excludedPage = $excludedPage['attribute'];
$excludedPages = $this->getExcludedPageIds();
if (count($excludedPages)) {
$magentoPages->addFieldToFilter('identifier', ['nin' => $excludedPages]);
}

$pageIdsToRemove = $pageIds ? array_flip($pageIds) : [];

$pages = [];

$frontendUrlBuilder = $this->frontendUrlFactory->create()->setScope($storeId);

/** @var Page $page */
foreach ($magentoPages as $page) {
if (in_array($page->getIdentifier(), $excludedPages)) {
continue;
}

$pageObject = [];

$pageObject['slug'] = $page->getIdentifier();
Expand Down Expand Up @@ -147,12 +148,27 @@ public function getPages($storeId)
);
$pageObject = $transport->getData();

$pages[] = $pageObject;
if (isset($pageIdsToRemove[$page->getId()])) {
unset($pageIdsToRemove[$page->getId()]);
}
$pages['toIndex'][] = $pageObject;
}

$pages['toRemove'] = array_unique(array_keys($pageIdsToRemove));

return $pages;
}

public function getExcludedPageIds()
{
$excludedPages = array_values($this->configHelper->getExcludedPages());
foreach ($excludedPages as &$excludedPage) {
$excludedPage = $excludedPage['attribute'];
}

return $excludedPages;
}

public function getStores($storeId = null)
{
$storeIds = [];
Expand Down
3 changes: 2 additions & 1 deletion Helper/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ protected function initBaseFile()
private function getProductImage(\Magento\Catalog\Model\Product\Image $model)
{
$imageUrl = $this->getProduct()->getData($model->getDestinationSubdir());
if (($imageUrl === null || $imageUrl == '') && $this->getProduct()->getTypeId() == ProductTypeConfigurable::TYPE_CODE) {
if (($imageUrl === null || $imageUrl == '' || $imageUrl == 'no_selection') &&
$this->getProduct()->getTypeId() == ProductTypeConfigurable::TYPE_CODE) {
$imageUrl = $this->getType() !== 'image' && $this->getConfigurableProductImage() ?
$this->getConfigurableProductImage() : $this->getProduct()->getImage();
}
Expand Down
6 changes: 5 additions & 1 deletion Helper/MerchandisingHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,18 @@ public function saveQueryRule($storeId, $entityId, $rawPositions, $entityType, $
$condition['pattern'] = $query;
}

if (! is_null($banner)) {
if (!is_null($banner)) {
$rule['consequence']['userData']['banner'] = $banner;
}

if ($entityType == 'query') {
unset($condition['context']);
}

if (in_array($entityType, ['query', 'landingpage'])) {
$rule['tags'] = ['visual-editor'];
}

$rule['conditions'] = [$condition];

// Not catching AlgoliaSearchException for disabled query rules on purpose
Expand Down
23 changes: 18 additions & 5 deletions Model/Indexer/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ public function __construct(
}

public function execute($ids)
{
}

public function executeFull()
{
if (!$this->configHelper->getApplicationID()
|| !$this->configHelper->getAPIKey()
Expand All @@ -74,17 +70,34 @@ public function executeFull()
}

if ($this->isPagesInAdditionalSections($storeId)) {
$this->queue->addToQueue($this->fullAction, 'rebuildStorePageIndex', ['store_id' => $storeId], 1);
$data = ['store_id' => $storeId];
if (is_array($ids) && count($ids) > 0) {
$data['page_ids'] = $ids;
}

$this->queue->addToQueue(
$this->fullAction,
'rebuildStorePageIndex',
$data,
is_array($ids) ? count($ids) : 1
);
}
}
}

public function executeFull()
{
$this->execute(null);
}

public function executeList(array $ids)
{
$this->execute($ids);
}

public function executeRow($id)
{
$this->execute([$id]);
}

private function isPagesInAdditionalSections($storeId)
Expand Down
Loading

0 comments on commit 4762fe2

Please sign in to comment.