Skip to content

Commit

Permalink
Release 1.13.2 (#1054)
Browse files Browse the repository at this point in the history
### UPDATES
- Update copyQueryRules to use client scopedCopyIndex (#1030) 
- Removed obsolete trigger for catalog_product_entity_media_gallery from mview.xml (#1025) @vmalyk
- Added CSP whitelisted hosts for Magento 2.3.5 or higher (#1036) @vmalyk
- Refactor getSalesData() method for optimisation (#1041) 
- Add filterPromotes to true for query rules (#1045) 
- Add category_without_path only if categories is searchable (#969) (#1051) @VincentMarmiesse

### FIXES
- Prevent division by zero in the Notice Helper when configuration is not set (#1031) @vmalyk
- Fix ProductHelper for bundle subproducts error (#1014) 
- Check the right storeId for moveIndex (#1016) (#1051) @palviggi-flagbit

### TOOLING
- Circleci do not use cache on the global composer vendor (#997) (#1028) 
- Remove composer self-update from circleCI quality tools (#1032) (#1052)
- Update CircleCI quality tools to remove composer set and install (#1033) (#1052)
  • Loading branch information
bsuravech authored Jun 25, 2020
1 parent 8743ad5 commit d0ccc1d
Show file tree
Hide file tree
Showing 14 changed files with 133 additions and 81 deletions.
12 changes: 4 additions & 8 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,16 @@ jobs:
sudo chown circleci:circleci ~/.composer/
- restore_cache:
keys:
- composer-v2-{{ checksum "composer.json" }}
- composer-v2-
- composer-v3-{{ checksum "composer.json" }}
- composer-v3-

- run:
name: Prepare environment
command: |
sudo composer self-update
composer config http-basic.'repo.magento.com' ${MAGENTO_AUTH_USERNAME} ${MAGENTO_AUTH_PASSWORD}
composer install -n --prefer-dist --ignore-platform-reqs --no-progress
sudo chown circleci:circleci ~/.composer/
composer global config prefer-stable true
composer global config minimum-stability dev
composer global require algolia/magento2-tools --ignore-platform-reqs
composer global require algolia/magento2-tools
# We have to do this again because we restore the cache above, overwriting the vendor with the original.
cd ~/magento_directory/vendor/algolia
Expand All @@ -97,10 +94,9 @@ jobs:
cd ~/magento_directory
composer dump-autoload
- save_cache:
key: composer-v2-{{ checksum "composer.json" }}
key: composer-v3-{{ checksum "composer.json" }}
paths:
- vendor
- ~/.composer/vendor
- run:
name: Quality tools
command: |
Expand Down
35 changes: 32 additions & 3 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ The development team will review all issues and contributions submitted by the c
4. PRs which include bug fixing, must be accompanied with step-by-step description of how to reproduce the bug.
5. PRs which include new logic or new features must be submitted along with:
* Integration test coverage
* Proposed [documentation](https://community.algolia.com/magento/) update. Documentation contributions can be submitted [here](https://github.com/algolia/magento).
6. All automated tests are passed successfully (all builds on [Travis CI](https://travis-ci.org/algolia/algoliasearch-magento-2/) must be green).
* Proposed [documentation](https://www.algolia.com/doc/integration/magento-2/getting-started/quick-start/) update
6. All automated tests are passed successfully:
* CircleCI Magento 2.2
* CircleCI Magento 2.3
* CircleCI [Quality Tools](https://github.com/algolia/magento2-tools) (phpcs and php compatibility)

# Contribution process

Expand All @@ -35,7 +38,7 @@ If you are a new GitHub user, we recommend that you create your own [free github

# Continuous Integration checks

Automated continous integration checks are run on [Travis CI](https://travis-ci.org/algolia/algoliasearch-magento-2/).
Automated continous integration checks are run on [CircleCI](../.circleci/config.yml).

## Integration tests

Expand Down Expand Up @@ -152,3 +155,29 @@ $ composer create-project --repository=https://repo.magento.com magento/marketpl
```bash
[[magento-coding-standard_dir]]/vendor/bin/phpcs --runtime-set ignore_warnings_on_exit true --ignore=dev,Test [[magento_root_dir]]/vendor/algolia/algoliasearch-magento-2 --standard=MEQP2 --extensions=php,phtml
```

## Quality Tools
As an alternative to testing Code Styling and Static Analysis individually, you can use our [Quality Tools](https://github.com/algolia/magento2-tools) tool that our CircleCI integration check against, to lint and test your changes.

You can install the tool via composer:
```bash
composer global require algolia/magento2-tools
```

Make sure to place Composer's system-wide vendor bin directory in your `$PATH` so the `magento2-tool` executable can be located by your system.

Finally, you can launch the quality tools with:
```bash
{command} path/to/magento/extension
```

Here is the list of available commands:

- **`magento2-lint`**: Runs the linter and fixes the found issues - configuration file under `algoliasearch-magento-2/.php_cs`.

- **`magento2-types`**: Runs the type checker and displays the found issues - configuration file under `algoliasearch-magento-2/phpstan.neon`.

- **`magento2-php-compatibility`**: Checks if your code is compatibility between multiple all php versions supported by magento.

- **`magento2-test`**: Runs all previous commands in `--dry-run` mode.

20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
# CHANGE LOG

## 1.13.2

### UPDATES
- Update copyQueryRules to use client scopedCopyIndex (#1030)
- Removed obsolete trigger for catalog_product_entity_media_gallery from mview.xml (#1025) @vmalyk
- Added CSP whitelisted hosts for Magento 2.3.5 or higher (#1036) @vmalyk
- Refactor getSalesData() method for optimisation (#1041)
- Add filterPromotes to true for query rules (#1045)
- Add category_without_path only if categories is searchable (#969) (#1051) @VincentMarmiesse

### FIXES
- Prevent division by zero in the Notice Helper when configuration is not set (#1031) @vmalyk
- Fix ProductHelper for bundle subproducts error (#1014)
- Check the right storeId for moveIndex (#1016) (#1051) @palviggi-flagbit

### TOOLING
- Circleci do not use cache on the global composer vendor (#997) (#1028)
- Remove composer self-update from circleCI quality tools (#1032) (#1052)
- Update CircleCI quality tools to remove composer set and install (#1033) (#1052)

## 1.13.1

### UPDATES
Expand Down
35 changes: 5 additions & 30 deletions Helper/AlgoliaHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -351,40 +351,15 @@ public function copySynonyms($fromIndexName, $toIndexName)
/**
* @param $fromIndexName
* @param $toIndexName
*
* @throws AlgoliaException
*/
public function copyQueryRules($fromIndexName, $toIndexName)
{
$fromIndex = $this->getIndex($fromIndexName);
$toIndex = $this->getIndex($toIndexName);

$queryRulesToSet = [];

$hitsPerPage = 100;
$page = 0;
do {
$fetchedQueryRules = $fromIndex->searchRules([
'page' => $page,
'hitsPerPage' => $hitsPerPage,
]);
$res = $this->getClient()->scopedCopyIndex($fromIndexName, $toIndexName, ['rules'], [
'forwardToReplicas' => true,
'clearExistingRules' => true,
]);

foreach ($fetchedQueryRules['hits'] as $hit) {
unset($hit['_highlightResult']);

$queryRulesToSet[] = $hit;
}

$page++;
} while (($page * $hitsPerPage) < $fetchedQueryRules['nbHits']);

if (!$queryRulesToSet) {
$res = $toIndex->clearRules(true);
} else {
$res = $toIndex->batchRules($queryRulesToSet, true, true);
}

self::$lastUsedIndexName= $toIndex;
self::$lastUsedIndexName = $toIndexName;
self::$lastTaskId = $res['taskID'];
}

Expand Down
4 changes: 3 additions & 1 deletion Helper/ConfigHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,9 @@ public function getNumberOfElementByPage($storeId = null)

public function getNumberOfJobToRun($storeId = null)
{
return (int) $this->configInterface->getValue(self::NUMBER_OF_JOB_TO_RUN, ScopeInterface::SCOPE_STORE, $storeId);
$nbJobs = (int) $this->configInterface->getValue(self::NUMBER_OF_JOB_TO_RUN, ScopeInterface::SCOPE_STORE, $storeId);

return max($nbJobs, 1);
}

public function getRetryLimit($storeId = null)
Expand Down
31 changes: 18 additions & 13 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -739,24 +739,29 @@ private function getSalesData($storeId, Collection $collection)
return [];
}

$ordersTableName = $this->resource->getTableName('sales_order_item');
$salesData = [];

$ids = $collection->getColumnValues('entity_id');
$ids[] = '0'; // Makes sure the imploded string is not empty

$ids = implode(', ', $ids);
if (count($ids)) {
$ordersTableName = $this->resource->getTableName('sales_order_item');

try {
$salesConnection = $this->resource->getConnectionByName('sales');
} catch (\DomainException $e) {
$salesConnection = $this->resource->getConnection();
}
try {
$salesConnection = $this->resource->getConnectionByName('sales');
} catch (\DomainException $e) {
$salesConnection = $this->resource->getConnection();
}

$select = $salesConnection->select()
->from($ordersTableName, [])
->columns('product_id')
->columns(['ordered_qty' => new \Zend_Db_Expr('SUM(qty_ordered)')])
->columns(['total_ordered' => new \Zend_Db_Expr('SUM(row_total)')])
->where('product_id IN (?)', $ids)
->group('product_id');

$query = 'SELECT product_id, SUM(qty_ordered) AS ordered_qty, SUM(row_total) AS total_ordered
FROM ' . $ordersTableName . '
WHERE product_id IN (' . $ids . ')
GROUP BY product_id';
$salesData = $salesConnection->query($query)->fetchAll(\PDO::FETCH_GROUP|\PDO::FETCH_UNIQUE|\PDO::FETCH_ASSOC);
$salesData = $salesConnection->fetchAll($select, [], \PDO::FETCH_GROUP|\PDO::FETCH_ASSOC|\PDO::FETCH_UNIQUE);
}

return $salesData;
}
Expand Down
10 changes: 5 additions & 5 deletions Helper/Entity/ProductHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ private function getSubProducts(Product $product)
if ($typeInstance instanceof Configurable) {
$subProducts = $typeInstance->getUsedProducts($product);
} elseif ($typeInstance instanceof BundleProductType) {
$subProducts = $typeInstance->getSelectionsCollection($typeInstance->getOptionsIds($product), $product);
$subProducts = $typeInstance->getSelectionsCollection($typeInstance->getOptionsIds($product), $product)->getItems();
} else { // Grouped product
$subProducts = $typeInstance->getAssociatedProducts($product);
}
Expand Down Expand Up @@ -929,11 +929,11 @@ private function getSearchableAttributes($storeId = null)
} else {
$searchableAttributes[] = 'unordered(' . $attribute['attribute'] . ')';
}
}

if ($attribute['attribute'] === 'categories') {
$searchableAttributes[] = (isset($attribute['order']) && $attribute['order'] === 'ordered') ?
'categories_without_path' : 'unordered(categories_without_path)';
if ($attribute['attribute'] === 'categories') {
$searchableAttributes[] = (isset($attribute['order']) && $attribute['order'] === 'ordered') ?
'categories_without_path' : 'unordered(categories_without_path)';
}
}
}

Expand Down
1 change: 1 addition & 0 deletions Helper/MerchandisingHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public function saveQueryRule($storeId, $entityId, $rawPositions, $entityType, $
'context' => 'magento-' . $entityType . '-' . $entityId,
],
'consequence' => [
'filterPromotes' => true,
'promote' => $positions,
],
];
Expand Down
11 changes: 6 additions & 5 deletions Model/IndexMover.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ public function __construct(
/**
* @param string $tmpIndexName
* @param string $indexName
* @param int $storeId
*/
public function moveIndex($tmpIndexName, $indexName)
public function moveIndex($tmpIndexName, $indexName, $storeId)
{
if ($this->baseHelper->isIndexingEnabled() === false) {
if ($this->baseHelper->isIndexingEnabled($storeId) === false) {
return;
}

Expand All @@ -48,17 +49,17 @@ public function moveIndex($tmpIndexName, $indexName)
/**
* @param string $tmpIndexName
* @param string $indexName
* @param int $storeId
* @param int $storeId
*
* @throws AlgoliaException
*/
public function moveIndexWithSetSettings($tmpIndexName, $indexName, $storeId)
{
if ($this->baseHelper->isIndexingEnabled() === false) {
if ($this->baseHelper->isIndexingEnabled($storeId) === false) {
return;
}

$this->indicesConfigurator->saveConfigurationToAlgolia($storeId, true);
$this->moveIndex($tmpIndexName, $indexName);
$this->moveIndex($tmpIndexName, $indexName, $storeId);
}
}
34 changes: 21 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
Algolia Search for Magento 2
==================

![Latest version](https://img.shields.io/badge/latest-1.13.1-green.svg)
![Magento 2](https://img.shields.io/badge/Magento-%3E=2.2-blue.svg)
![Latest version](https://img.shields.io/badge/latest-1.13.2-green.svg)
![Magento 2](https://img.shields.io/badge/Magento-%3E=2.2%20<2.4-blue.svg)
![PHP >= 7.0.6](https://img.shields.io/badge/PHP-%3E=7.0-green.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)

-------

🔎 Are you a Magento engineer? [Join our team](https://www.algolia.com/careers#!?j=eed58660-f684-436d-a2ff-e9947d2b65a2) and help us deliver the best search solution for Magento stores!
🔎 &nbsp; **Need help?** Check out our [Technical Troubleshooting Guide](https://www.algolia.com/doc/integration/magento-2/troubleshooting/technical-troubleshooting/). For feedback, bug reporting, or unresolved issues with the extension, please contact us at [[email protected]](mailto:[email protected]). Please include your Magento version, extension version, application ID, and steps to reproducing your issue. Add additional information like screenshots, screencasts, and error messages to help our team better troubleshoot your issues.

-------

- **Auto-completion menu:** Offer End-Users immediate access to your whole catalog from the dropdown menu, whatever your number of categories or attributes.
- **Autocompletion menu:** Offer End-Users immediate access to your whole catalog from the dropdown menu, whatever your number of categories or attributes.

- **Instant search results page:** Have your search results page, navigation and pagination updated in realtime, after each keystroke.
- **Instantsearch results page:** Have your search results page, navigation and pagination updated in realtime, after each keystroke.

Official website: [community.algolia.com/magento](https://community.algolia.com/magento).
Official website: [https://www.algolia.com/solutions/magento/](https://www.algolia.com/solutions/magento/).

*Note: if your store is running under Magento version 1.x, please check our [Algolia for Magento 1 extension](https://github.com/algolia/algoliasearch-magento).*

Demo
--------------

Try the auto-complete and the instant search results page on our [live demo](https://magento2.algolia.com).
Try the autocomplete and the instantsearch results page on our [live demo](https://magento2.algolia.com).

Algolia Search
--------------
Expand All @@ -33,11 +33,6 @@ Algolia Search

This extension replaces the default search of Magento with a typo-tolerant, fast & relevant search experience backed by Algolia. It's based on [algoliasearch-client-php](https://github.com/algolia/algoliasearch-client-php), [autocomplete.js](https://github.com/algolia/autocomplete.js) and [instantsearch.js](https://github.com/algolia/instantsearch.js).

<!--
The extension officially supports only 2.0.X versions of Magento.
It's possible to use it for versions >= 2.1.0, but some unexpected issues might appear. When you experience that, please [open an issue](https://github.com/algolia/algoliasearch-magento-2/issues/new).
-->

Documentation
--------------

Expand All @@ -58,4 +53,17 @@ Run the following commands:
Contribution
------------

To start contribuiting to the extension follow the [contributing guildelines](.github/CONTRIBUTING.md).
To start contributing to the extension follow the [contributing guildelines](.github/CONTRIBUTING.md).

Need Help?
------------
Here are some helpful documentation to help with your issue:

- [General FAQs](https://www.algolia.com/doc/integration/magento-2/troubleshooting/general-faq/)
- [Technical Troubleshooting Guide](https://www.algolia.com/doc/integration/magento-2/troubleshooting/technical-troubleshooting/)
- [Indexing Queue](https://www.algolia.com/doc/integration/magento-2/how-it-works/indexing-queue/)
- [Frontend Custom Events](https://www.algolia.com/doc/integration/magento-2/customize/custom-front-end-events/)
- [Dispatched Backend Events](https://www.algolia.com/doc/integration/magento-2/customize/custom-back-end-events/)

For feedback, bug reporting, or unresolved issues with the extension, please contact us at [[email protected]](mailto:[email protected]). Please include your Magento version, extension version, application ID, and steps to reproducing your issue. Add additional information like screenshots, screencasts, and error messages to help our team better troubleshoot your issues.

2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Algolia Search integration for Magento 2",
"type": "magento2-module",
"license": ["MIT"],
"version": "1.13.1",
"version": "1.13.2",
"require": {
"php": "~7.0|~7.1|~7.2|~7.3",
"magento/framework": "~101.0|~102.0",
Expand Down
16 changes: 16 additions & 0 deletions etc/csp_whitelist.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<csp_whitelist xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Csp:etc/csp_whitelist.xsd">
<policies>
<policy id="script-src">
<values>
<value id="polyfill" type="host">polyfill.io</value>
</values>
</policy>
<policy id="connect-src">
<values>
<value id="algolia" type="host">*.algolia.net</value>
</values>
</policy>
</policies>
</csp_whitelist>
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Algolia_AlgoliaSearch" setup_version="1.13.1">
<module name="Algolia_AlgoliaSearch" setup_version="1.13.2">
<sequence>
<module name="Magento_Theme"/>
<module name="Magento_Backend"/>
Expand Down
1 change: 0 additions & 1 deletion etc/mview.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
<table name="catalog_product_entity_decimal" entity_column="entity_id" />
<table name="catalog_product_entity_gallery" entity_column="entity_id" />
<table name="catalog_product_entity_int" entity_column="entity_id" />
<table name="catalog_product_entity_media_gallery" entity_column="value_id" />
<table name="catalog_product_entity_media_gallery_value" entity_column="entity_id" />
<table name="catalog_product_entity_text" entity_column="entity_id" />
<table name="catalog_product_entity_tier_price" entity_column="entity_id" />
Expand Down

0 comments on commit d0ccc1d

Please sign in to comment.