Skip to content

Commit

Permalink
Merge pull request #1235 from algolia/release/3.8.1
Browse files Browse the repository at this point in the history
Release/3.8.1
  • Loading branch information
mohitalgolia authored Sep 2, 2022
2 parents 37295d7 + 43d7e2f commit 923dcaa
Show file tree
Hide file tree
Showing 15 changed files with 177 additions and 60 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# CHANGE LOG

## 3.8.1

### UPDATES
- Updated the system configuration message for Click & Conversion Analytics
- Added validation in synonyms upload section (for Algolia Search) in the Magento admin(#1226)
- Updated code to set "Filter Only" facets via the instantsearch/facets settings in the Magento admin panel(#1224)
- Updated CSR policy to fix content security error for insights.io(#1228)

### FIXES
- Fixed the InstantSearch variant image issue(#1223)
- Fixed the proper case for 'Related Products' in comment Magento Admin (#1221)
- Fixed the code deploy error if the DB has tables with Prefix - patch not applied(#1229)
- Fixed the Remove trailing ? url in category page(#1222)

## 3.8.0

### New Features
Expand Down
10 changes: 7 additions & 3 deletions Helper/Entity/ProductHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ public function setSettings($indexName, $indexNameTmp, $storeId, $saveToTmpIndic

if ($this->configHelper->isEnabledSynonyms($storeId) === true) {
if ($synonymsFile = $this->configHelper->getSynonymsFile($storeId)) {
$synonymsToSet = json_decode(file_get_contents($synonymsFile));
$synonymsToSet = json_decode(file_get_contents($synonymsFile), true);
} else {
$synonymsToSet = [];

Expand Down Expand Up @@ -1000,8 +1000,12 @@ private function getAttributesForFaceting($storeId)
}
} else {
$attribute = $facet['attribute'];
if (array_key_exists('searchable', $facet) && $facet['searchable'] === '1') {
$attribute = 'searchable(' . $attribute . ')';
if (array_key_exists('searchable', $facet)) {
if ($facet['searchable'] === '1') {
$attribute = 'searchable(' . $attribute . ')';
} elseif ($facet['searchable'] === '3') {
$attribute = 'filterOnly(' . $attribute . ')';
}
}

$attributesForFaceting[] = $attribute;
Expand Down
4 changes: 2 additions & 2 deletions Model/Source/Facets.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ protected function getTableData()
'label' => 'Label',
],
'searchable' => [
'label' => 'Searchable?',
'values' => ['1' => 'Yes', '2' => 'No'],
'label' => 'Options',
'values' => ['1' => 'Searchable', '2' => 'Not Searchable', '3' => 'Filter Only'],
],
];

Expand Down
61 changes: 61 additions & 0 deletions Model/Source/SynonymsFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,72 @@
namespace Algolia\AlgoliaSearch\Model\Source;

use Magento\Config\Model\Config\Backend\File;
use Magento\Framework\Filesystem;
use Magento\Framework\Serialize\JsonValidator;
use Magento\Framework\App\Config\ScopeConfigInterface;

class SynonymsFile extends File
{
/**
* @var JsonValidator
*/
protected $jsonValidator;

/**
* @param \Magento\Framework\Model\Context $context
* @param \Magento\Framework\Registry $registry
* @param ScopeConfigInterface $config
* @param \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList
* @param \Magento\MediaStorage\Model\File\UploaderFactory $uploaderFactory
* @param File\RequestData\RequestDataInterface $requestData
* @param Filesystem $filesystem
* @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource
* @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection
* @param JsonValidator $jsonValidator
* @param array $data
*/
public function __construct(
\Magento\Framework\Model\Context $context,
\Magento\Framework\Registry $registry,
ScopeConfigInterface $config,
\Magento\Framework\App\Cache\TypeListInterface $cacheTypeList,
\Magento\MediaStorage\Model\File\UploaderFactory $uploaderFactory,
File\RequestData\RequestDataInterface $requestData,
Filesystem $filesystem,
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
JsonValidator $jsonValidator,
array $data = []
) {
parent::__construct($context, $registry, $config, $cacheTypeList, $uploaderFactory, $requestData, $filesystem, $resource, $resourceCollection, $data);
$this->jsonValidator = $jsonValidator;
}

protected function _getAllowedExtensions()
{
return ['json'];
}

public function beforeSave()
{
$file = $this->getFileData();
if (!empty($file)) {
$data = file_get_contents($file['tmp_name']);
if (!$this->jsonValidator->isValid($data)) {
throw new \Magento\Framework\Exception\LocalizedException(
__('Json file is not valid. Please check the file')
);
}

$convertJsontoArray = json_decode($data, true);
foreach ($convertJsontoArray as $jsonArray) {
if (!array_key_exists('objectID', $jsonArray)) {
throw new \Magento\Framework\Exception\LocalizedException(
__('objectID is missing from the json, please make sure objectId is unique and added for all the synonyms')
);
}
}
}
return parent::beforeSave();
}
}
Original file line number Diff line number Diff line change
@@ -1,35 +1,50 @@
<?php

namespace Algolia\AlgoliaSearch\Model\Indexer;
namespace Algolia\AlgoliaSearch\Plugin;

use Magento\Framework\Indexer\IndexerRegistry;
use Magento\Framework\Model\AbstractModel as StockItem;

class StockItemObserver
{
private $indexer;

/**
* @var IndexerRegistry
*/
protected $indexer;

/**
* @param IndexerRegistry $indexerRegistry
*/
public function __construct(IndexerRegistry $indexerRegistry)
{
$this->indexer = $indexerRegistry->get('algolia_products');
}

public function afterSave(
/**
* @param \Magento\CatalogInventory\Model\ResourceModel\Stock\Item $stockItemModel
* @param StockItem $stockItem
* @return void
*/
public function beforeSave(
\Magento\CatalogInventory\Model\ResourceModel\Stock\Item $stockItemModel,
\Magento\CatalogInventory\Model\ResourceModel\Stock\Item $result,
\Magento\CatalogInventory\Api\Data\StockItemInterface $stockItem
StockItem $stockItem
) {
$stockItemModel->addCommitCallback(function () use ($stockItem) {
if (!$this->indexer->isScheduled()) {
$this->indexer->reindexRow($stockItem->getProductId());
}
});

return $result;
}

/**
* @param \Magento\CatalogInventory\Model\ResourceModel\Stock\Item $stockItemResource
* @param \Magento\CatalogInventory\Model\ResourceModel\Stock\Item|null $result
* @param \Magento\CatalogInventory\Api\Data\StockItemInterface $stockItem
* @return \Magento\CatalogInventory\Model\ResourceModel\Stock\Item|null
*/
public function afterDelete(
\Magento\CatalogInventory\Model\ResourceModel\Stock\Item $stockItemResource,
\Magento\CatalogInventory\Model\ResourceModel\Stock\Item $result,
\Magento\CatalogInventory\Model\ResourceModel\Stock\Item $result = null,
\Magento\CatalogInventory\Api\Data\StockItemInterface $stockItem
) {
$stockItemResource->addCommitCallback(function () use ($stockItem) {
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Algolia Search for Magento 2
==================

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

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

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

Expand Down
11 changes: 7 additions & 4 deletions Setup/Patch/Data/UpdateMviewPatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ class UpdateMviewPatch implements DataPatchInterface
/**
* @var SubscriptionFactory
*/
private $subscriptionFactory;
protected $subscriptionFactory;

/**
* @var IndexerInterfaceFactory
*/
private $indexerFactory;
protected $indexerFactory;

/**
* @var ModuleDataSetupInterface
*/
private $moduleDataSetup;
protected $moduleDataSetup;

/**
* @param SubscriptionFactory $subscriptionFactory
Expand All @@ -39,6 +39,9 @@ public function __construct(
$this->indexerFactory = $indexerFactory;
}

/**
* @return UpdateMviewPatch|void
*/
public function apply()
{
$this->moduleDataSetup->getConnection()->startSetup();
Expand All @@ -49,7 +52,7 @@ public function apply()
$subscriptionInstance = $this->subscriptionFactory->create(
[
'view' => $indexer->getView(),
'tableName' => 'catalog_product_index_price',
'tableName' => $this->moduleDataSetup->getTable('catalog_product_index_price'),
'columnName' => 'entity_id',
]
);
Expand Down
57 changes: 37 additions & 20 deletions Setup/Patch/Schema/ConfigPatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,22 @@ class ConfigPatch implements SchemaPatchInterface
/**
* @var ConfigInterface
*/
private $config;
protected $config;

/**
* @var ProductMetadataInterface
*/
private $productMetadata;
protected $productMetadata;

/**
* @var ModuleDataSetupInterface
*/
private $moduleDataSetup;
protected $moduleDataSetup;

/**
* @var SubscriptionFactory
* @var string[]
*/
private $subscriptionFactory;

private $defaultConfigData = [
protected $defaultConfigData = [
'algoliasearch_credentials/credentials/enable_backend' => '1',
'algoliasearch_credentials/credentials/enable_frontend' => '1',
'algoliasearch_credentials/credentials/application_id' => '',
Expand Down Expand Up @@ -97,7 +95,10 @@ class ConfigPatch implements SchemaPatchInterface
'algoliasearch_advanced/advanced/archive_clear_limit' => '30',
];

private $defaultArrayConfigData = [
/**
* @var string[][][]
*/
protected $defaultArrayConfigData = [
'algoliasearch_autocomplete/autocomplete/sections' => [
[
'name' => 'pages',
Expand Down Expand Up @@ -257,35 +258,43 @@ class ConfigPatch implements SchemaPatchInterface
],
];

private $indexerFactory;

/**
* @param ConfigInterface $config
* @param ProductMetadataInterface $productMetadata
* @param ModuleDataSetupInterface $moduleDataSetup Magento\Framework\App\ResourceConnection
*/
public function __construct(
ConfigInterface $config,
ProductMetadataInterface $productMetadata,
ModuleDataSetupInterface $moduleDataSetup,
SubscriptionFactory $subscriptionFactory,
IndexerInterfaceFactory $indexerFactory
ModuleDataSetupInterface $moduleDataSetup
) {
$this->config = $config;
$this->productMetadata = $productMetadata;
$this->moduleDataSetup = $moduleDataSetup;
$this->subscriptionFactory = $subscriptionFactory;

$this->serializeDefaultArrayConfigData();
$this->mergeDefaultDataWithArrayData();
$this->indexerFactory = $indexerFactory;
}

/**
* @return array|string[]
*/
public static function getDependencies()
{
return [];
}

/**
* @return array|string[]
*/
public function getAliases()
{
return [];
}

/**
* @return ConfigPatch|void
*/
public function apply()
{
$movedConfigDirectives = [
Expand All @@ -298,17 +307,16 @@ public function apply()

$this->moduleDataSetup->getConnection()->startSetup();
$connection = $this->moduleDataSetup->getConnection();
$table = $connection->getTableName('core_config_data');
$table = $this->moduleDataSetup->getTable('core_config_data');
foreach ($movedConfigDirectives as $from => $to) {
try {
$connection->query('UPDATE ' . $table . ' SET path = "' . $to . '" WHERE path = "' . $from . '"');
} catch (\Magento\Framework\DB\Adapter\DuplicateException $e) {
//
// Skip
}
}

/* SET DEFAULT CONFIG DATA */

$alreadyInserted = $connection->getConnection()
->query('SELECT path, value FROM ' . $table . ' WHERE path LIKE "algoliasearch_%"')
->fetchAll(\PDO::FETCH_KEY_PAIR);
Expand All @@ -323,12 +331,18 @@ public function apply()
$this->moduleDataSetup->getConnection()->endSetup();
}

/**
* @return string[]
*/
public function getDefaultConfigData()
{
return $this->defaultConfigData;
}

private function serializeDefaultArrayConfigData()
/**
* @return void
*/
protected function serializeDefaultArrayConfigData()
{
$serializeMethod = 'serialize';

Expand All @@ -342,7 +356,10 @@ private function serializeDefaultArrayConfigData()
}
}

private function mergeDefaultDataWithArrayData()
/**
* @return void
*/
protected function mergeDefaultDataWithArrayData()
{
$this->defaultConfigData = array_merge($this->defaultConfigData, $this->defaultArrayConfigData);
}
Expand Down
Loading

0 comments on commit 923dcaa

Please sign in to comment.