Skip to content

Commit 79fc7a6

Browse files
author
Jan Petr
authored
Merge pull request #887 from algolia/develop
Release
2 parents f70e9b6 + 4b90016 commit 79fc7a6

File tree

38 files changed

+888
-121
lines changed

38 files changed

+888
-121
lines changed

CHANGELOG.md

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

3+
### 1.11.0
4+
5+
## FEATURES
6+
- Added option to turn on autocomplete's `debug` option from configuration (#865)
7+
- The extension now displays the right image for a color variant depending on search query or selected color filter (#883)
8+
9+
## UPDATES
10+
- Added CSS class for proper function of collapsible IS widgets (#859)
11+
- Changed Magento archive URLs in dev containers (#874)
12+
- Updated Magento 1.9.3 version to the latest one in dev container (#882)
13+
- Optimization of `getPopularQueries()` method (#888)
14+
15+
## FIXES
16+
- Fixed the hardcode admin URL for fetching queue info (#854)
17+
- Fixed issue when some attributes weren't set as retrievable when custom groups were enabled (#856)
18+
- Fixed back button which returned all products on category pages (#852)
19+
- Removed not-necessary additional query on category page (#852)
20+
- Fixed displayed link to analytics documentation (#869)
21+
- Fixed store specific facets (#868)
22+
- Fixed option to disable the module by disabling it's output (#866)
23+
24+
325
### 1.10.0
426

527
#### FEATURES

README.md

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

4-
![Latest version](https://img.shields.io/badge/latest-1.10.0-green.svg)
4+
![Latest version](https://img.shields.io/badge/latest-1.11.0-green.svg)
5+
56
[![Build Status](https://travis-ci.org/algolia/algoliasearch-magento.svg?branch=master)](https://travis-ci.org/algolia/algoliasearch-magento)
67
![PHP >= 5.3](https://img.shields.io/badge/php-%3E=5.3-green.svg)
78

app/code/community/Algolia/Algoliasearch/Helper/Config.php

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class Algolia_Algoliasearch_Helper_Config extends Mage_Core_Helper_Abstract
1313
const SEARCH_ONLY_API_KEY = 'algoliasearch/credentials/search_only_api_key';
1414
const INDEX_PREFIX = 'algoliasearch/credentials/index_prefix';
1515
const IS_INSTANT_ENABLED = 'algoliasearch/credentials/is_instant_enabled';
16+
const USE_ADAPTIVE_IMAGE = 'algoliasearch/credentials/use_adaptive_image';
1617

1718
const REPLACE_CATEGORIES = 'algoliasearch/instant/replace_categories';
1819
const INSTANT_SELECTOR = 'algoliasearch/instant/instant_selector';
@@ -30,6 +31,7 @@ class Algolia_Algoliasearch_Helper_Config extends Mage_Core_Helper_Abstract
3031
const MIN_NUMBER_OF_RESULTS = 'algoliasearch/autocomplete/min_number_of_results';
3132
const DISPLAY_SUGGESTIONS_CATEGORIES = 'algoliasearch/autocomplete/display_categories_with_suggestions';
3233
const RENDER_TEMPLATE_DIRECTIVES = 'algoliasearch/autocomplete/render_template_directives';
34+
const AUTOCOMPLETE_MENU_DEBUG = 'algoliasearch/autocomplete/debug';
3335

3436
const NUMBER_OF_PRODUCT_RESULTS = 'algoliasearch/products/number_product_results';
3537
const PRODUCT_ATTRIBUTES = 'algoliasearch/products/product_additional_attributes';
@@ -48,6 +50,9 @@ class Algolia_Algoliasearch_Helper_Config extends Mage_Core_Helper_Abstract
4850
const IS_ACTIVE = 'algoliasearch/queue/active';
4951
const NUMBER_OF_ELEMENT_BY_PAGE = 'algoliasearch/queue/number_of_element_by_page';
5052
const NUMBER_OF_JOB_TO_RUN = 'algoliasearch/queue/number_of_job_to_run';
53+
const RETRY_LIMIT = 'algoliasearch/queue/number_of_retries';
54+
const CHECK_PRICE_INDEX = 'algoliasearch/queue/check_price_index';
55+
const CHECK_STOCK_INDEX = 'algoliasearch/queue/check_stock_index';
5156

5257
const XML_PATH_IMAGE_WIDTH = 'algoliasearch/image/width';
5358
const XML_PATH_IMAGE_HEIGHT = 'algoliasearch/image/height';
@@ -259,6 +264,21 @@ public function isQueueActive($storeId = null)
259264
return Mage::getStoreConfigFlag(self::IS_ACTIVE, $storeId);
260265
}
261266

267+
public function shouldCheckPriceIndex($storeId = null)
268+
{
269+
return Mage::getStoreConfigFlag(self::CHECK_PRICE_INDEX, $storeId);
270+
}
271+
272+
public function shouldCheckStockIndex($storeId = null)
273+
{
274+
return Mage::getStoreConfigFlag(self::CHECK_STOCK_INDEX, $storeId);
275+
}
276+
277+
public function getRetryLimit($storeId = null)
278+
{
279+
return (int) Mage::getStoreConfig(self::RETRY_LIMIT, $storeId);
280+
}
281+
262282
public function getRemoveWordsIfNoResult($storeId = null)
263283
{
264284
return Mage::getStoreConfig(self::REMOVE_IF_NO_RESULT, $storeId);
@@ -294,6 +314,11 @@ public function isInstantEnabled($storeId = null)
294314
return Mage::getStoreConfigFlag(self::IS_INSTANT_ENABLED, $storeId);
295315
}
296316

317+
public function useAdaptiveImage($storeId = null)
318+
{
319+
return Mage::getStoreConfigFlag(self::USE_ADAPTIVE_IMAGE, $storeId);
320+
}
321+
297322
public function getInstantSelector($storeId = null)
298323
{
299324
return Mage::getStoreConfig(self::INSTANT_SELECTOR, $storeId);
@@ -315,6 +340,11 @@ public function getRenderTemplateDirectives($storeId = null)
315340
return Mage::getStoreConfigFlag(self::RENDER_TEMPLATE_DIRECTIVES, $storeId);
316341
}
317342

343+
public function isAutocompleteDebugEnabled($storeId = null)
344+
{
345+
return Mage::getStoreConfigFlag(self::AUTOCOMPLETE_MENU_DEBUG, $storeId);
346+
}
347+
318348
public function getSortingIndices($storeId = null)
319349
{
320350
/** @var Algolia_Algoliasearch_Helper_Entity_Producthelper $product_helper */
@@ -424,7 +454,7 @@ public function getAttributesToRetrieve($group_id)
424454

425455
$attributes = array_unique($attributes);
426456

427-
return $attributes;
457+
return array_values($attributes);
428458
}
429459

430460
public function getCategoryAdditionalAttributes($storeId = null)
@@ -497,13 +527,17 @@ public function getCurrency($storeId = null)
497527

498528
public function getPopularQueries($storeId = null)
499529
{
530+
if (!$this->isInstantEnabled($storeId) || !$this->showSuggestionsOnNoResultsPage($storeId)) {
531+
return array();
532+
}
533+
500534
if ($storeId === null) {
501535
$storeId = Mage::app()->getStore()->getId();
502536
}
503537

504-
/** @var Algolia_Algoliasearch_Helper_Entity_Suggestionhelper $suggestion_helper */
505-
$suggestion_helper = Mage::helper('algoliasearch/entity_suggestionhelper');
506-
$popularQueries = $suggestion_helper->getPopularQueries($storeId);
538+
/** @var Algolia_Algoliasearch_Helper_Entity_Suggestionhelper $suggestionHelper */
539+
$suggestionHelper = Mage::helper('algoliasearch/entity_suggestionhelper');
540+
$popularQueries = $suggestionHelper->getPopularQueries($storeId);
507541

508542
return $popularQueries;
509543
}

app/code/community/Algolia/Algoliasearch/Helper/Data.php

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -185,27 +185,32 @@ public function rebuildStoreAdditionalSectionsIndex($storeId)
185185
}
186186
}
187187

188-
public function rebuildStorePageIndex($storeId)
188+
public function rebuildStorePageIndex($storeId, $pageIds = null)
189189
{
190190
if ($this->config->isEnabledBackend($storeId) === false) {
191191
$this->logger->log('INDEXING IS DISABLED FOR '.$this->logger->getStoreName($storeId));
192192

193193
return;
194194
}
195195

196-
$emulationInfo = $this->startEmulation($storeId);
196+
$shouldUseTmpIndex = ($pageIds === null);
197197

198-
$index_name = $this->page_helper->getIndexName($storeId);
198+
$emulationInfo = $this->startEmulation($storeId);
199199

200-
$pages = $this->page_helper->getPages($storeId);
200+
$indexName = $this->page_helper->getIndexName($storeId, $shouldUseTmpIndex);
201201

202+
/** @var array $pages */
203+
$pages = $this->page_helper->getPages($storeId, $pageIds);
202204
foreach (array_chunk($pages, 100) as $chunk) {
203-
$this->algolia_helper->addObjects($chunk, $index_name.'_tmp');
205+
$this->algolia_helper->addObjects($chunk, $indexName);
204206
}
205207

206-
$this->algolia_helper->moveIndex($index_name.'_tmp', $index_name);
208+
if ($shouldUseTmpIndex === true) {
209+
$finalIndexName = $this->page_helper->getIndexName($storeId);
207210

208-
$this->algolia_helper->setSettings($index_name, $this->page_helper->getIndexSettings($storeId));
211+
$this->algolia_helper->moveIndex($indexName, $finalIndexName);
212+
$this->algolia_helper->setSettings($finalIndexName, $this->page_helper->getIndexSettings($storeId));
213+
}
209214

210215
$this->stopEmulation($emulationInfo);
211216
}
@@ -444,6 +449,19 @@ protected function getProductsRecords($storeId, $collection, $potentiallyDeleted
444449
$potentiallyDeletedProductsIds = array();
445450
}
446451

452+
if (method_exists('Mage', 'getEdition') === true && Mage::getEdition() === Mage::EDITION_ENTERPRISE) {
453+
$productIds = array();
454+
455+
/** @var Mage_Catalog_Model_Product $products */
456+
foreach ($collection as $products) {
457+
$productIds[] = $products->getId();
458+
}
459+
460+
/** @var Algolia_Algoliasearch_Helper_IndexChecker $indexChecker */
461+
$indexChecker = Mage::helper('algoliasearch/indexChecker');
462+
$indexChecker->checkIndexers($storeId, $productIds);
463+
}
464+
447465
$this->logger->start('CREATE RECORDS '.$this->logger->getStoreName($storeId));
448466
$this->logger->log(count($collection).' product records to create');
449467

app/code/community/Algolia/Algoliasearch/Helper/Entity/Helper.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,8 @@ public static function getStores($store_id)
272272
$store_ids[] = $store->getId();
273273
}
274274
}
275+
} elseif (is_array($store_id)) {
276+
return $store_id;
275277
} else {
276278
$store_ids = array($store_id);
277279
}

app/code/community/Algolia/Algoliasearch/Helper/Entity/Pagehelper.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,18 @@ public function getIndexSettings($storeId)
2121
return $indexSettings;
2222
}
2323

24-
public function getPages($storeId)
24+
public function getPages($storeId, $pageIds = null)
2525
{
2626
/** @var Mage_Cms_Model_Page $cmsPage */
2727
$cmsPage = Mage::getModel('cms/page');
2828

2929
/** @var Mage_Cms_Model_Resource_Page_Collection $pages */
3030
$pages = $cmsPage->getCollection()->addStoreFilter($storeId)->addFieldToFilter('is_active', 1);
3131

32+
if ($pageIds && count($pageIds) > 0) {
33+
$pages = $pages->addFieldToFilter('page_id', array('in' => $pageIds));
34+
}
35+
3236
Mage::dispatchEvent('algolia_after_pages_collection_build', array('store' => $storeId, 'collection' => $pages));
3337

3438
$ids = $pages->toOptionArray();
@@ -85,4 +89,17 @@ public function getPages($storeId)
8589

8690
return $pages;
8791
}
92+
93+
public function shouldIndexPages($storeId)
94+
{
95+
$autocompleteSections = $this->config->getAutocompleteSections($storeId);
96+
97+
foreach ($autocompleteSections as $section) {
98+
if ($section['name'] === 'pages') {
99+
return true;
100+
}
101+
}
102+
103+
return false;
104+
}
88105
}

app/code/community/Algolia/Algoliasearch/Helper/Entity/Producthelper.php

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ public function setSettings($storeId, $saveToTmpIndicesToo = false)
229229

230230
$customRankingAttributes = array();
231231

232-
$facets = $this->config->getFacets();
232+
$facets = $this->config->getFacets($storeId);
233233

234234
/** @var Mage_Directory_Model_Currency $directoryCurrency */
235235
$directoryCurrency = Mage::getModel('directory/currency');
@@ -291,7 +291,7 @@ public function setSettings($storeId, $saveToTmpIndicesToo = false)
291291
/*
292292
* Handle replicas
293293
*/
294-
$sorting_indices = $this->config->getSortingIndices();
294+
$sorting_indices = $this->config->getSortingIndices($storeId);
295295

296296
if (count($sorting_indices) > 0) {
297297
$replicas = array();
@@ -905,15 +905,16 @@ public function getObject(Mage_Catalog_Model_Product $product)
905905
if ($attribute_resource) {
906906
$attribute_resource->setStoreId($product->getStoreId());
907907

908+
$values = array();
909+
$subProductImages = array();
910+
908911
/**
909912
* if $value is missing or if the attribute is SKU,
910913
* use values from child products.
911914
*/
912915
if (($value === null || 'sku' == $attribute_name) && ($type == 'configurable' || $type == 'grouped' || $type == 'bundle')) {
913-
if ($value === null) {
914-
$values = array();
915-
} else {
916-
$values = array($this->getValueOrValueText($product, $attribute_name, $attribute_resource));
916+
if ($value !== null) {
917+
$values[] = $this->getValueOrValueText($product, $attribute_name, $attribute_resource);
917918
}
918919

919920
$all_sub_products_out_of_stock = true;
@@ -931,7 +932,23 @@ public function getObject(Mage_Catalog_Model_Product $product)
931932
$value = $sub_product->getData($attribute_name);
932933

933934
if ($value) {
934-
$values[] = $this->getValueOrValueText($sub_product, $attribute_name, $attribute_resource);
935+
$textValue = $this->getValueOrValueText($sub_product, $attribute_name, $attribute_resource);
936+
937+
$values[] = $textValue;
938+
939+
if (mb_strtolower($attribute_name, 'utf-8') === 'color') {
940+
$image = $imageHelper->init($sub_product, $this->config->getImageType())
941+
->resize($this->config->getImageWidth(),
942+
$this->config->getImageHeight());
943+
944+
try {
945+
$textValueInLower = mb_strtolower($textValue, 'utf-8');
946+
$subProductImages[$textValueInLower] = $image->toString();
947+
} catch (\Exception $e) {
948+
$this->logger->log($e->getMessage());
949+
$this->logger->log($e->getTraceAsString());
950+
}
951+
}
935952
}
936953
}
937954
}
@@ -940,6 +957,10 @@ public function getObject(Mage_Catalog_Model_Product $product)
940957
$customData[$attribute_name] = array_values(array_unique($values, SORT_REGULAR));
941958
}
942959

960+
if (empty($subProductImages) === false) {
961+
$customData['images_data'] = $subProductImages;
962+
}
963+
943964
// Set main product out of stock if all
944965
// sub-products are out of stock.
945966
if ($customData['in_stock'] && $all_sub_products_out_of_stock) {

0 commit comments

Comments
 (0)