Skip to content

Commit 923dcaa

Browse files
authored
Merge pull request #1235 from algolia/release/3.8.1
Release/3.8.1
2 parents 37295d7 + 43d7e2f commit 923dcaa

File tree

15 files changed

+177
-60
lines changed

15 files changed

+177
-60
lines changed

CHANGELOG.md

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

3+
## 3.8.1
4+
5+
### UPDATES
6+
- Updated the system configuration message for Click & Conversion Analytics
7+
- Added validation in synonyms upload section (for Algolia Search) in the Magento admin(#1226)
8+
- Updated code to set "Filter Only" facets via the instantsearch/facets settings in the Magento admin panel(#1224)
9+
- Updated CSR policy to fix content security error for insights.io(#1228)
10+
11+
### FIXES
12+
- Fixed the InstantSearch variant image issue(#1223)
13+
- Fixed the proper case for 'Related Products' in comment Magento Admin (#1221)
14+
- Fixed the code deploy error if the DB has tables with Prefix - patch not applied(#1229)
15+
- Fixed the Remove trailing ? url in category page(#1222)
16+
317
## 3.8.0
418

519
### New Features

Helper/Entity/ProductHelper.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ public function setSettings($indexName, $indexNameTmp, $storeId, $saveToTmpIndic
391391

392392
if ($this->configHelper->isEnabledSynonyms($storeId) === true) {
393393
if ($synonymsFile = $this->configHelper->getSynonymsFile($storeId)) {
394-
$synonymsToSet = json_decode(file_get_contents($synonymsFile));
394+
$synonymsToSet = json_decode(file_get_contents($synonymsFile), true);
395395
} else {
396396
$synonymsToSet = [];
397397

@@ -1000,8 +1000,12 @@ private function getAttributesForFaceting($storeId)
10001000
}
10011001
} else {
10021002
$attribute = $facet['attribute'];
1003-
if (array_key_exists('searchable', $facet) && $facet['searchable'] === '1') {
1004-
$attribute = 'searchable(' . $attribute . ')';
1003+
if (array_key_exists('searchable', $facet)) {
1004+
if ($facet['searchable'] === '1') {
1005+
$attribute = 'searchable(' . $attribute . ')';
1006+
} elseif ($facet['searchable'] === '3') {
1007+
$attribute = 'filterOnly(' . $attribute . ')';
1008+
}
10051009
}
10061010

10071011
$attributesForFaceting[] = $attribute;

Model/Source/Facets.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ protected function getTableData()
3636
'label' => 'Label',
3737
],
3838
'searchable' => [
39-
'label' => 'Searchable?',
40-
'values' => ['1' => 'Yes', '2' => 'No'],
39+
'label' => 'Options',
40+
'values' => ['1' => 'Searchable', '2' => 'Not Searchable', '3' => 'Filter Only'],
4141
],
4242
];
4343

Model/Source/SynonymsFile.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,72 @@
33
namespace Algolia\AlgoliaSearch\Model\Source;
44

55
use Magento\Config\Model\Config\Backend\File;
6+
use Magento\Framework\Filesystem;
7+
use Magento\Framework\Serialize\JsonValidator;
8+
use Magento\Framework\App\Config\ScopeConfigInterface;
69

710
class SynonymsFile extends File
811
{
12+
/**
13+
* @var JsonValidator
14+
*/
15+
protected $jsonValidator;
16+
17+
/**
18+
* @param \Magento\Framework\Model\Context $context
19+
* @param \Magento\Framework\Registry $registry
20+
* @param ScopeConfigInterface $config
21+
* @param \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList
22+
* @param \Magento\MediaStorage\Model\File\UploaderFactory $uploaderFactory
23+
* @param File\RequestData\RequestDataInterface $requestData
24+
* @param Filesystem $filesystem
25+
* @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource
26+
* @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection
27+
* @param JsonValidator $jsonValidator
28+
* @param array $data
29+
*/
30+
public function __construct(
31+
\Magento\Framework\Model\Context $context,
32+
\Magento\Framework\Registry $registry,
33+
ScopeConfigInterface $config,
34+
\Magento\Framework\App\Cache\TypeListInterface $cacheTypeList,
35+
\Magento\MediaStorage\Model\File\UploaderFactory $uploaderFactory,
36+
File\RequestData\RequestDataInterface $requestData,
37+
Filesystem $filesystem,
38+
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
39+
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
40+
JsonValidator $jsonValidator,
41+
array $data = []
42+
) {
43+
parent::__construct($context, $registry, $config, $cacheTypeList, $uploaderFactory, $requestData, $filesystem, $resource, $resourceCollection, $data);
44+
$this->jsonValidator = $jsonValidator;
45+
}
46+
947
protected function _getAllowedExtensions()
1048
{
1149
return ['json'];
1250
}
51+
52+
public function beforeSave()
53+
{
54+
$file = $this->getFileData();
55+
if (!empty($file)) {
56+
$data = file_get_contents($file['tmp_name']);
57+
if (!$this->jsonValidator->isValid($data)) {
58+
throw new \Magento\Framework\Exception\LocalizedException(
59+
__('Json file is not valid. Please check the file')
60+
);
61+
}
62+
63+
$convertJsontoArray = json_decode($data, true);
64+
foreach ($convertJsontoArray as $jsonArray) {
65+
if (!array_key_exists('objectID', $jsonArray)) {
66+
throw new \Magento\Framework\Exception\LocalizedException(
67+
__('objectID is missing from the json, please make sure objectId is unique and added for all the synonyms')
68+
);
69+
}
70+
}
71+
}
72+
return parent::beforeSave();
73+
}
1374
}

Model/Indexer/StockItemObserver.php renamed to Plugin/StockItemObserver.php

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,50 @@
11
<?php
22

3-
namespace Algolia\AlgoliaSearch\Model\Indexer;
3+
namespace Algolia\AlgoliaSearch\Plugin;
44

55
use Magento\Framework\Indexer\IndexerRegistry;
6+
use Magento\Framework\Model\AbstractModel as StockItem;
67

78
class StockItemObserver
89
{
9-
private $indexer;
10-
10+
/**
11+
* @var IndexerRegistry
12+
*/
13+
protected $indexer;
14+
15+
/**
16+
* @param IndexerRegistry $indexerRegistry
17+
*/
1118
public function __construct(IndexerRegistry $indexerRegistry)
1219
{
1320
$this->indexer = $indexerRegistry->get('algolia_products');
1421
}
1522

16-
public function afterSave(
23+
/**
24+
* @param \Magento\CatalogInventory\Model\ResourceModel\Stock\Item $stockItemModel
25+
* @param StockItem $stockItem
26+
* @return void
27+
*/
28+
public function beforeSave(
1729
\Magento\CatalogInventory\Model\ResourceModel\Stock\Item $stockItemModel,
18-
\Magento\CatalogInventory\Model\ResourceModel\Stock\Item $result,
19-
\Magento\CatalogInventory\Api\Data\StockItemInterface $stockItem
30+
StockItem $stockItem
2031
) {
2132
$stockItemModel->addCommitCallback(function () use ($stockItem) {
2233
if (!$this->indexer->isScheduled()) {
2334
$this->indexer->reindexRow($stockItem->getProductId());
2435
}
2536
});
26-
27-
return $result;
2837
}
2938

39+
/**
40+
* @param \Magento\CatalogInventory\Model\ResourceModel\Stock\Item $stockItemResource
41+
* @param \Magento\CatalogInventory\Model\ResourceModel\Stock\Item|null $result
42+
* @param \Magento\CatalogInventory\Api\Data\StockItemInterface $stockItem
43+
* @return \Magento\CatalogInventory\Model\ResourceModel\Stock\Item|null
44+
*/
3045
public function afterDelete(
3146
\Magento\CatalogInventory\Model\ResourceModel\Stock\Item $stockItemResource,
32-
\Magento\CatalogInventory\Model\ResourceModel\Stock\Item $result,
47+
\Magento\CatalogInventory\Model\ResourceModel\Stock\Item $result = null,
3348
\Magento\CatalogInventory\Api\Data\StockItemInterface $stockItem
3449
) {
3550
$stockItemResource->addCommitCallback(function () use ($stockItem) {

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
Algolia Search for Magento 2
22
==================
33

4-
![Latest version](https://img.shields.io/badge/latest-3.8.0-green)
4+
![Latest version](https://img.shields.io/badge/latest-3.8.1-green)
55
![Magento 2](https://img.shields.io/badge/Magento-2.4.x-orange)
66

7-
![PHP](https://img.shields.io/badge/PHP-7.4%2C8.1-blue)
7+
![PHP](https://img.shields.io/badge/PHP-8.1-blue)
88

99
[![CircleCI](https://circleci.com/gh/algolia/algoliasearch-magento-2/tree/master.svg?style=svg)](https://circleci.com/gh/algolia/algoliasearch-magento-2/tree/master)
1010

Setup/Patch/Data/UpdateMviewPatch.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ class UpdateMviewPatch implements DataPatchInterface
1212
/**
1313
* @var SubscriptionFactory
1414
*/
15-
private $subscriptionFactory;
15+
protected $subscriptionFactory;
1616

1717
/**
1818
* @var IndexerInterfaceFactory
1919
*/
20-
private $indexerFactory;
20+
protected $indexerFactory;
2121

2222
/**
2323
* @var ModuleDataSetupInterface
2424
*/
25-
private $moduleDataSetup;
25+
protected $moduleDataSetup;
2626

2727
/**
2828
* @param SubscriptionFactory $subscriptionFactory
@@ -39,6 +39,9 @@ public function __construct(
3939
$this->indexerFactory = $indexerFactory;
4040
}
4141

42+
/**
43+
* @return UpdateMviewPatch|void
44+
*/
4245
public function apply()
4346
{
4447
$this->moduleDataSetup->getConnection()->startSetup();
@@ -49,7 +52,7 @@ public function apply()
4952
$subscriptionInstance = $this->subscriptionFactory->create(
5053
[
5154
'view' => $indexer->getView(),
52-
'tableName' => 'catalog_product_index_price',
55+
'tableName' => $this->moduleDataSetup->getTable('catalog_product_index_price'),
5356
'columnName' => 'entity_id',
5457
]
5558
);

Setup/Patch/Schema/ConfigPatch.php

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,22 @@ class ConfigPatch implements SchemaPatchInterface
1414
/**
1515
* @var ConfigInterface
1616
*/
17-
private $config;
17+
protected $config;
1818

1919
/**
2020
* @var ProductMetadataInterface
2121
*/
22-
private $productMetadata;
22+
protected $productMetadata;
2323

2424
/**
2525
* @var ModuleDataSetupInterface
2626
*/
27-
private $moduleDataSetup;
27+
protected $moduleDataSetup;
2828

2929
/**
30-
* @var SubscriptionFactory
30+
* @var string[]
3131
*/
32-
private $subscriptionFactory;
33-
34-
private $defaultConfigData = [
32+
protected $defaultConfigData = [
3533
'algoliasearch_credentials/credentials/enable_backend' => '1',
3634
'algoliasearch_credentials/credentials/enable_frontend' => '1',
3735
'algoliasearch_credentials/credentials/application_id' => '',
@@ -97,7 +95,10 @@ class ConfigPatch implements SchemaPatchInterface
9795
'algoliasearch_advanced/advanced/archive_clear_limit' => '30',
9896
];
9997

100-
private $defaultArrayConfigData = [
98+
/**
99+
* @var string[][][]
100+
*/
101+
protected $defaultArrayConfigData = [
101102
'algoliasearch_autocomplete/autocomplete/sections' => [
102103
[
103104
'name' => 'pages',
@@ -257,35 +258,43 @@ class ConfigPatch implements SchemaPatchInterface
257258
],
258259
];
259260

260-
private $indexerFactory;
261-
261+
/**
262+
* @param ConfigInterface $config
263+
* @param ProductMetadataInterface $productMetadata
264+
* @param ModuleDataSetupInterface $moduleDataSetup Magento\Framework\App\ResourceConnection
265+
*/
262266
public function __construct(
263267
ConfigInterface $config,
264268
ProductMetadataInterface $productMetadata,
265-
ModuleDataSetupInterface $moduleDataSetup,
266-
SubscriptionFactory $subscriptionFactory,
267-
IndexerInterfaceFactory $indexerFactory
269+
ModuleDataSetupInterface $moduleDataSetup
268270
) {
269271
$this->config = $config;
270272
$this->productMetadata = $productMetadata;
271273
$this->moduleDataSetup = $moduleDataSetup;
272-
$this->subscriptionFactory = $subscriptionFactory;
273274

274275
$this->serializeDefaultArrayConfigData();
275276
$this->mergeDefaultDataWithArrayData();
276-
$this->indexerFactory = $indexerFactory;
277277
}
278278

279+
/**
280+
* @return array|string[]
281+
*/
279282
public static function getDependencies()
280283
{
281284
return [];
282285
}
283286

287+
/**
288+
* @return array|string[]
289+
*/
284290
public function getAliases()
285291
{
286292
return [];
287293
}
288294

295+
/**
296+
* @return ConfigPatch|void
297+
*/
289298
public function apply()
290299
{
291300
$movedConfigDirectives = [
@@ -298,17 +307,16 @@ public function apply()
298307

299308
$this->moduleDataSetup->getConnection()->startSetup();
300309
$connection = $this->moduleDataSetup->getConnection();
301-
$table = $connection->getTableName('core_config_data');
310+
$table = $this->moduleDataSetup->getTable('core_config_data');
302311
foreach ($movedConfigDirectives as $from => $to) {
303312
try {
304313
$connection->query('UPDATE ' . $table . ' SET path = "' . $to . '" WHERE path = "' . $from . '"');
305314
} catch (\Magento\Framework\DB\Adapter\DuplicateException $e) {
306-
//
315+
// Skip
307316
}
308317
}
309318

310319
/* SET DEFAULT CONFIG DATA */
311-
312320
$alreadyInserted = $connection->getConnection()
313321
->query('SELECT path, value FROM ' . $table . ' WHERE path LIKE "algoliasearch_%"')
314322
->fetchAll(\PDO::FETCH_KEY_PAIR);
@@ -323,12 +331,18 @@ public function apply()
323331
$this->moduleDataSetup->getConnection()->endSetup();
324332
}
325333

334+
/**
335+
* @return string[]
336+
*/
326337
public function getDefaultConfigData()
327338
{
328339
return $this->defaultConfigData;
329340
}
330341

331-
private function serializeDefaultArrayConfigData()
342+
/**
343+
* @return void
344+
*/
345+
protected function serializeDefaultArrayConfigData()
332346
{
333347
$serializeMethod = 'serialize';
334348

@@ -342,7 +356,10 @@ private function serializeDefaultArrayConfigData()
342356
}
343357
}
344358

345-
private function mergeDefaultDataWithArrayData()
359+
/**
360+
* @return void
361+
*/
362+
protected function mergeDefaultDataWithArrayData()
346363
{
347364
$this->defaultConfigData = array_merge($this->defaultConfigData, $this->defaultArrayConfigData);
348365
}

0 commit comments

Comments
 (0)