Skip to content

Commit 4762fe2

Browse files
authored
Develop > Master (#1116)
1 parent 188ec3e commit 4762fe2

25 files changed

+540
-352
lines changed

CHANGELOG.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
# CHANGE LOG
22

3+
## 3.0.2
4+
5+
### FEATURES
6+
- CMS Page indexing improvement (#1113) (by @vmalyk)
7+
8+
### UPDATES
9+
- Add tags for QM and LPB queries to use VM if applicable (#1103)
10+
- InfiniteHits change showMoreLabel to showMoreText (#1105)
11+
- Turn off Perso when it’s not available in the plan but activated in the Magento admin (#1104)
12+
- Keep custom Rules set directly on Algolia dashboard for CMS Pages, Suggestions and Additional sections. (#1106)
13+
- Remove from composer suggestion for es compatibility (#1114)
14+
15+
### FIXES
16+
- linter fix templates (#1108)
17+
- Configurable product with broken image when set to “no_selection” (#1101) (by @dverkade)
18+
- Insights Analytics - Fix Add to Cart Conversion (#1111)
19+
- Added try/catch on CheckoutSuccess event (#1112)
20+
- Merge 2 connect-src policy sections to 1 (#1110) (by @vmalyk)
21+
322
## 3.0.1
423

524
### UPDATES

Helper/Configuration/NoticeHelper.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ class NoticeHelper extends \Magento\Framework\App\Helper\AbstractHelper
1919
/** @var ProxyHelper */
2020
private $proxyHelper;
2121

22+
/** @var PersonalizationHelper */
23+
private $personalizationHelper;
24+
2225
/** @var ModuleManager */
2326
private $moduleManager;
2427

@@ -63,6 +66,7 @@ public function __construct(
6366
\Magento\Framework\App\Helper\Context $context,
6467
ConfigHelper $configHelper,
6568
ProxyHelper $proxyHelper,
69+
PersonalizationHelper $personalizationHelper,
6670
ModuleManager $moduleManager,
6771
ObjectManagerInterface $objectManager,
6872
ExtensionNotification $extensionNotification,
@@ -72,6 +76,7 @@ public function __construct(
7276
) {
7377
$this->configHelper = $configHelper;
7478
$this->proxyHelper = $proxyHelper;
79+
$this->personalizationHelper = $personalizationHelper;
7580
$this->moduleManager = $moduleManager;
7681
$this->objectManager = $objectManager;
7782
$this->extensionNotification = $extensionNotification;
@@ -318,14 +323,18 @@ protected function formatNotice($title, $content, $icon = 'icon-warning')
318323
public function getPersonalizationStatus()
319324
{
320325
$info = $this->proxyHelper->getInfo(ProxyHelper::INFO_TYPE_PERSONALIZATION);
321-
322326
$status = 2;
323327

324328
if ($info
325329
&& array_key_exists('personalization', $info)
326330
&& array_key_exists('personalization_enabled_at', $info)) {
327331
if (!$info['personalization']) {
328332
$status = 0;
333+
334+
// If perso is not avaible in the plan but activated in admin for some reason, turn it off
335+
if ($this->personalizationHelper->isPersoEnabled()) {
336+
$this->personalizationHelper->disablePerso();
337+
}
329338
}
330339
if ($info['personalization_enabled_at'] === null) {
331340
$status = min(1, $status);

Helper/Configuration/PersonalizationHelper.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Algolia\AlgoliaSearch\Helper\Configuration;
44

5+
use Magento\Framework\App\Config\ConfigResource\ConfigInterface as ConfigResourceInterface;
56
use Magento\Framework\App\Config\ScopeConfigInterface;
67
use Magento\Store\Model\ScopeInterface;
78

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

34+
/** @var ConfigResourceInterface */
35+
private $configResourceInterface;
36+
3337
public function __construct(
3438
\Magento\Framework\App\Helper\Context $context,
35-
ScopeConfigInterface $configInterface
39+
ScopeConfigInterface $configInterface,
40+
ConfigResourceInterface $configResourceInterface
3641
) {
3742
$this->configInterface = $configInterface;
43+
$this->configResourceInterface = $configResourceInterface;
3844
parent::__construct($context);
3945
}
4046

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

57+
/**
58+
* @param int|null $storeId
59+
*
60+
* @return void
61+
*/
62+
public function disablePerso($storeId = null)
63+
{
64+
$this->configResourceInterface->saveConfig(self::IS_PERSO_ENABLED, 0, 'default', 0);
65+
}
66+
5167
/**
5268
* @param int|null $storeId
5369
*

Helper/Data.php

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,14 @@ public function rebuildStoreAdditionalSectionsIndex($storeId)
173173
$this->algoliaHelper->addObjects($chunk, $indexName . '_tmp');
174174
}
175175

176+
$this->algoliaHelper->copyQueryRules($indexName, $indexName . '_tmp');
176177
$this->algoliaHelper->moveIndex($indexName . '_tmp', $indexName);
177178

178179
$this->algoliaHelper->setSettings($indexName, $this->additionalSectionHelper->getIndexSettings($storeId));
179180
}
180181
}
181182

182-
public function rebuildStorePageIndex($storeId)
183+
public function rebuildStorePageIndex($storeId, array $pageIds = null)
183184
{
184185
if ($this->isIndexingEnabled($storeId) === false) {
185186
return;
@@ -189,20 +190,44 @@ public function rebuildStorePageIndex($storeId)
189190

190191
$this->startEmulation($storeId);
191192

192-
$pages = $this->pageHelper->getPages($storeId);
193+
$pages = $this->pageHelper->getPages($storeId, $pageIds);
193194

194195
$this->stopEmulation();
195196

196-
foreach (array_chunk($pages, 100) as $chunk) {
197-
try {
198-
$this->algoliaHelper->addObjects($chunk, $indexName . '_tmp');
199-
} catch (\Exception $e) {
200-
$this->logger->log($e->getMessage());
201-
continue;
197+
// if there are pageIds defined, do not index to _tmp
198+
$isFullReindex = (!$pageIds);
199+
200+
if (isset($pages['toIndex']) && count($pages['toIndex'])) {
201+
$pagesToIndex = $pages['toIndex'];
202+
$toIndexName = $indexName . ($isFullReindex ? '_tmp' : '');
203+
204+
foreach (array_chunk($pagesToIndex, 100) as $chunk) {
205+
try {
206+
$this->algoliaHelper->addObjects($chunk, $toIndexName);
207+
} catch (\Exception $e) {
208+
$this->logger->log($e->getMessage());
209+
continue;
210+
}
202211
}
203212
}
204213

205-
$this->algoliaHelper->moveIndex($indexName . '_tmp', $indexName);
214+
if (!$isFullReindex && isset($pages['toRemove']) && count($pages['toRemove'])) {
215+
$pagesToRemove = $pages['toRemove'];
216+
217+
foreach (array_chunk($pagesToRemove, 100) as $chunk) {
218+
try {
219+
$this->algoliaHelper->deleteObjects($chunk, $indexName);
220+
} catch (\Exception $e) {
221+
$this->logger->log($e->getMessage());
222+
continue;
223+
}
224+
}
225+
}
226+
227+
if ($isFullReindex) {
228+
$this->algoliaHelper->copyQueryRules($indexName, $indexName . '_tmp');
229+
$this->algoliaHelper->moveIndex($indexName . '_tmp', $indexName);
230+
}
206231

207232
$this->algoliaHelper->setSettings($indexName, $this->pageHelper->getIndexSettings($storeId));
208233
}
@@ -289,6 +314,7 @@ public function moveStoreSuggestionIndex($storeId)
289314
$tmpIndexName = $this->getIndexName($indexNameSuffix, $storeId, true);
290315
$indexName = $this->getIndexName($indexNameSuffix, $storeId);
291316

317+
$this->algoliaHelper->copyQueryRules($indexName, $tmpIndexName);
292318
$this->algoliaHelper->moveIndex($tmpIndexName, $indexName);
293319
}
294320

@@ -592,8 +618,8 @@ public function rebuildStoreProductIndexPage(
592618
return;
593619
}
594620

595-
$wrapperLogMessage = 'rebuildStoreProductIndexPage: ' . $this->logger->getStoreName($storeId) . ',
596-
page ' . $page . ',
621+
$wrapperLogMessage = 'rebuildStoreProductIndexPage: ' . $this->logger->getStoreName($storeId) . ',
622+
page ' . $page . ',
597623
pageSize ' . $pageSize;
598624
$this->logger->start($wrapperLogMessage);
599625

@@ -622,8 +648,8 @@ public function rebuildStoreProductIndexPage(
622648
['collection' => $collection, 'store' => $storeId]
623649
);
624650

625-
$logMessage = 'LOADING: ' . $this->logger->getStoreName($storeId) . ',
626-
collection page: ' . $page . ',
651+
$logMessage = 'LOADING: ' . $this->logger->getStoreName($storeId) . ',
652+
collection page: ' . $page . ',
627653
pageSize: ' . $pageSize;
628654

629655
$this->logger->start($logMessage);

Helper/Entity/PageHelper.php

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,29 +91,30 @@ public function getIndexSettings($storeId)
9191
return $indexSettings;
9292
}
9393

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

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

103-
foreach ($excludedPages as &$excludedPage) {
104-
$excludedPage = $excludedPage['attribute'];
105+
$excludedPages = $this->getExcludedPageIds();
106+
if (count($excludedPages)) {
107+
$magentoPages->addFieldToFilter('identifier', ['nin' => $excludedPages]);
105108
}
106109

110+
$pageIdsToRemove = $pageIds ? array_flip($pageIds) : [];
111+
107112
$pages = [];
108113

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

111116
/** @var Page $page */
112117
foreach ($magentoPages as $page) {
113-
if (in_array($page->getIdentifier(), $excludedPages)) {
114-
continue;
115-
}
116-
117118
$pageObject = [];
118119

119120
$pageObject['slug'] = $page->getIdentifier();
@@ -147,12 +148,27 @@ public function getPages($storeId)
147148
);
148149
$pageObject = $transport->getData();
149150

150-
$pages[] = $pageObject;
151+
if (isset($pageIdsToRemove[$page->getId()])) {
152+
unset($pageIdsToRemove[$page->getId()]);
153+
}
154+
$pages['toIndex'][] = $pageObject;
151155
}
152156

157+
$pages['toRemove'] = array_unique(array_keys($pageIdsToRemove));
158+
153159
return $pages;
154160
}
155161

162+
public function getExcludedPageIds()
163+
{
164+
$excludedPages = array_values($this->configHelper->getExcludedPages());
165+
foreach ($excludedPages as &$excludedPage) {
166+
$excludedPage = $excludedPage['attribute'];
167+
}
168+
169+
return $excludedPages;
170+
}
171+
156172
public function getStores($storeId = null)
157173
{
158174
$storeIds = [];

Helper/Image.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ protected function initBaseFile()
8888
private function getProductImage(\Magento\Catalog\Model\Product\Image $model)
8989
{
9090
$imageUrl = $this->getProduct()->getData($model->getDestinationSubdir());
91-
if (($imageUrl === null || $imageUrl == '') && $this->getProduct()->getTypeId() == ProductTypeConfigurable::TYPE_CODE) {
91+
if (($imageUrl === null || $imageUrl == '' || $imageUrl == 'no_selection') &&
92+
$this->getProduct()->getTypeId() == ProductTypeConfigurable::TYPE_CODE) {
9293
$imageUrl = $this->getType() !== 'image' && $this->getConfigurableProductImage() ?
9394
$this->getConfigurableProductImage() : $this->getProduct()->getImage();
9495
}

Helper/MerchandisingHelper.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,18 @@ public function saveQueryRule($storeId, $entityId, $rawPositions, $entityType, $
5454
$condition['pattern'] = $query;
5555
}
5656

57-
if (! is_null($banner)) {
57+
if (!is_null($banner)) {
5858
$rule['consequence']['userData']['banner'] = $banner;
5959
}
6060

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

65+
if (in_array($entityType, ['query', 'landingpage'])) {
66+
$rule['tags'] = ['visual-editor'];
67+
}
68+
6569
$rule['conditions'] = [$condition];
6670

6771
// Not catching AlgoliaSearchException for disabled query rules on purpose

Model/Indexer/Page.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,6 @@ public function __construct(
4444
}
4545

4646
public function execute($ids)
47-
{
48-
}
49-
50-
public function executeFull()
5147
{
5248
if (!$this->configHelper->getApplicationID()
5349
|| !$this->configHelper->getAPIKey()
@@ -74,17 +70,34 @@ public function executeFull()
7470
}
7571

7672
if ($this->isPagesInAdditionalSections($storeId)) {
77-
$this->queue->addToQueue($this->fullAction, 'rebuildStorePageIndex', ['store_id' => $storeId], 1);
73+
$data = ['store_id' => $storeId];
74+
if (is_array($ids) && count($ids) > 0) {
75+
$data['page_ids'] = $ids;
76+
}
77+
78+
$this->queue->addToQueue(
79+
$this->fullAction,
80+
'rebuildStorePageIndex',
81+
$data,
82+
is_array($ids) ? count($ids) : 1
83+
);
7884
}
7985
}
8086
}
8187

88+
public function executeFull()
89+
{
90+
$this->execute(null);
91+
}
92+
8293
public function executeList(array $ids)
8394
{
95+
$this->execute($ids);
8496
}
8597

8698
public function executeRow($id)
8799
{
100+
$this->execute([$id]);
88101
}
89102

90103
private function isPagesInAdditionalSections($storeId)

0 commit comments

Comments
 (0)