Skip to content

Commit 64316d2

Browse files
author
Jan Petr
authored
Merge pull request #645 from algolia/develop
Develop
2 parents 4b9d6f0 + b4c554e commit 64316d2

File tree

19 files changed

+129
-60
lines changed

19 files changed

+129
-60
lines changed

CHANGELOG.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
1-
## Change Log
1+
## CHANGE LOG
2+
3+
### 1.7.2
4+
5+
#### FEATURES
6+
- Ability to select sort and ranking attributes from all attributes, not only indexed ones. Those attributes are indexed automatically with proper settings (searchable, retrievable, ...) (#632)
7+
- Swedish translation (#613)
8+
9+
#### UPDATES
10+
- "No"/empty values can now be removed from all attributes, not only from attributes fetched from children products (#623)
11+
- Ability to select autocomplete menu item by hitting Enter (#626)
12+
- For better relevancy hardcoded searchable attributes (in pages, suggestions, additional sections ...) set as `unordered` (#634)
13+
14+
#### FIXES
15+
- Missing semicolon in instantsearch.js file (#630)
16+
- Product reindexing when using `catalogsearch_fulltext` indexer name (#633)
17+
- Hide API key from configuration's HTML code (#637)
18+
- Fixed fatal error on delete product (#640)
19+
- Fixed untranslatable hard-coded strings in stats widget template (#641)
220

321
### 1.7.1
422

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ This extension replaces the default search of Magento with a typo-tolerant, fast
77

88
See features and benefits of [Algolia Search Extension for Magento](https://community.algolia.com/magento).
99

10-
![Latest version](https://img.shields.io/badge/latest-1.7.1-green.svg)
10+
![Latest version](https://img.shields.io/badge/latest-1.7.2-green.svg)
1111
![Magento 1.6.2](https://img.shields.io/badge/magento-1.6.2-blue.svg)
1212
![Magento 1.7.1](https://img.shields.io/badge/magento-1.7.1-blue.svg)
1313
![Magento 1.8.1](https://img.shields.io/badge/magento-1.8.1-blue.svg)

app/code/community/Algolia/Algoliasearch/Block/System/Config/Form/Field/CustomRankingProductAttributes.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@ public function __construct()
1414
'options' => function () {
1515
$options = array();
1616

17-
/** @var Algolia_Algoliasearch_Helper_Config $config */
18-
$config = Mage::helper('algoliasearch/config');
19-
20-
$attributes = $config->getProductAdditionalAttributes();
21-
foreach ($attributes as $attribute) {
22-
$options[$attribute['attribute']] = $attribute['attribute'];
17+
/** @var Algolia_Algoliasearch_Helper_Entity_Producthelper $product_helper */
18+
$product_helper = Mage::helper('algoliasearch/entity_producthelper');
19+
$attributes = $product_helper->getAllAttributes();
20+
foreach ($attributes as $key => $label) {
21+
$options[$key] = $key ?: $label;
2322
}
2423

2524
$options['custom_attribute'] = '[use custom attribute]';

app/code/community/Algolia/Algoliasearch/Block/System/Config/Form/Field/Sorts.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@ public function __construct()
1414
'options' => function () {
1515
$options = array();
1616

17-
/** @var Algolia_Algoliasearch_Helper_Config $config */
18-
$config = Mage::helper('algoliasearch/config');
19-
20-
$attributes = $config->getProductAdditionalAttributes();
21-
foreach ($attributes as $attribute) {
22-
$options[$attribute['attribute']] = $attribute['attribute'];
17+
/** @var Algolia_Algoliasearch_Helper_Entity_Producthelper $product_helper */
18+
$product_helper = Mage::helper('algoliasearch/entity_producthelper');
19+
$attributes = $product_helper->getAllAttributes();
20+
foreach ($attributes as $key => $label) {
21+
$options[$key] = $key ?: $label;
2322
}
2423

2524
return $options;

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

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,12 @@ public function getApplicationID($storeId = null)
353353

354354
public function getAPIKey($storeId = null)
355355
{
356-
return trim(Mage::getStoreConfig(self::API_KEY, $storeId));
356+
/** @var Mage_Core_Helper_Data $coreHelper */
357+
$coreHelper = Mage::helper('core');
358+
359+
$encrypted = trim(Mage::getStoreConfig(self::API_KEY, $storeId));
360+
361+
return $coreHelper->decrypt($encrypted);
357362
}
358363

359364
public function getSearchOnlyAPIKey($storeId = null)
@@ -422,26 +427,22 @@ public function getCategoryAdditionalAttributes($storeId = null)
422427

423428
public function getProductAdditionalAttributes($storeId = null)
424429
{
425-
$attrs = unserialize(Mage::getStoreConfig(self::PRODUCT_ATTRIBUTES, $storeId));
430+
$attributes = unserialize(Mage::getStoreConfig(self::PRODUCT_ATTRIBUTES, $storeId));
431+
426432
$facets = unserialize(Mage::getStoreConfig(self::FACETS, $storeId));
433+
$attributes = $this->addIndexableAttributes($attributes, $facets, '0');
427434

428-
foreach ((array) $facets as $facet) {
429-
foreach ((array) $attrs as $attr) {
430-
if ($facet['attribute'] == $attr['attribute']) {
431-
continue 2;
432-
}
433-
}
435+
$sorts = unserialize(Mage::getStoreConfig(self::SORTING_INDICES, $storeId));
436+
$attributes = $this->addIndexableAttributes($attributes, $sorts, '0');
434437

435-
$attrs[] = array(
436-
'attribute' => $facet['attribute'],
437-
'searchable' => '0',
438-
'retrievable' => '1',
439-
'index_no_value' => '1',
440-
);
441-
}
438+
$customRankings = unserialize(Mage::getStoreConfig(self::PRODUCT_CUSTOM_RANKING, $storeId));
439+
$customRankings = array_filter($customRankings, function ($customRanking) {
440+
return $customRanking['attribute'] != 'custom_attribute';
441+
});
442+
$attributes = $this->addIndexableAttributes($attributes, $customRankings, '0', '0');
442443

443-
if (is_array($attrs)) {
444-
return $attrs;
444+
if (is_array($attributes)) {
445+
return $attributes;
445446
}
446447

447448
return array();
@@ -574,4 +575,24 @@ private function getCustomRanking($configName, $storeId = null)
574575

575576
return array();
576577
}
578+
579+
private function addIndexableAttributes($attributes, $addedAttributes, $searchable = '1', $retrievable = '1', $indexNoValue = '1')
580+
{
581+
foreach ((array) $addedAttributes as $addedAttribute) {
582+
foreach ((array) $attributes as $attribute) {
583+
if ($addedAttribute['attribute'] == $attribute['attribute']) {
584+
continue 2;
585+
}
586+
}
587+
588+
$attributes[] = array(
589+
'attribute' => $addedAttribute['attribute'],
590+
'searchable' => $searchable,
591+
'retrievable' => $retrievable,
592+
'index_no_value' => $indexNoValue,
593+
);
594+
}
595+
596+
return $attributes;
597+
}
577598
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ protected function getIndexNameSuffix()
1010
public function getIndexSettings($storeId)
1111
{
1212
return array(
13-
'attributesToIndex' => array('value'),
13+
'attributesToIndex' => array('unordered(value)'),
1414
);
1515
}
1616

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ protected function getIndexNameSuffix()
1010
public function getIndexSettings($storeId)
1111
{
1212
return array(
13-
'attributesToIndex' => array('slug', 'name', 'unordered(content)'),
13+
'attributesToIndex' => array('unordered(slug)', 'unordered(name)', 'unordered(content)'),
1414
'attributesToSnippet' => array('content:7'),
1515
);
1616
}

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

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ class Algolia_Algoliasearch_Helper_Entity_Producthelper extends Algolia_Algolias
2525
'special_to_date',
2626
);
2727

28+
private $noAttributes = array();
29+
2830
protected function getIndexNameSuffix()
2931
{
3032
return '_products';
@@ -614,14 +616,14 @@ protected function handlePrice(Mage_Catalog_Model_Product &$product, $sub_produc
614616
}
615617
}
616618

617-
protected function getValueOrValueText(Mage_Catalog_Model_Product $product, $name, Mage_Catalog_Model_Resource_Eav_Attribute $resource, $index_no_value)
619+
protected function getValueOrValueText(Mage_Catalog_Model_Product $product, $name, Mage_Catalog_Model_Resource_Eav_Attribute $resource)
618620
{
619621
$value_text = $product->getAttributeText($name);
620622
if (!$value_text) {
621623
$value_text = $resource->getFrontend()->getValue($product);
622624
}
623625

624-
return $value_text == Mage::helper('catalog')->__('No') && $index_no_value == false ? null : $value_text;
626+
return $value_text;
625627
}
626628

627629
public function getObject(Mage_Catalog_Model_Product $product)
@@ -869,6 +871,8 @@ public function getObject(Mage_Catalog_Model_Product $product)
869871
}
870872
}
871873

874+
$this->setNoAttributes($additionalAttributes);
875+
872876
foreach ($additionalAttributes as $attribute) {
873877
$attribute_name = $attribute['attribute'];
874878
if (isset($customData[$attribute_name])) {
@@ -877,9 +881,6 @@ public function getObject(Mage_Catalog_Model_Product $product)
877881

878882
$value = $product->getData($attribute_name);
879883

880-
// To be more compatible (no backend save required after update), if index_no_value isn't set it's true
881-
$index_no_value = !isset($attribute['index_no_value']) || $attribute['index_no_value'] == 1 ? true : false;
882-
883884
/** @var Mage_Catalog_Model_Resource_Eav_Attribute $attribute_resource */
884885
$attribute_resource = $product->getResource()->getAttribute($attribute_name);
885886

@@ -894,7 +895,7 @@ public function getObject(Mage_Catalog_Model_Product $product)
894895
if ($value === null) {
895896
$values = array();
896897
} else {
897-
$values = array($this->getValueOrValueText($product, $attribute_name, $attribute_resource, $index_no_value));
898+
$values = array($this->getValueOrValueText($product, $attribute_name, $attribute_resource));
898899
}
899900

900901
$all_sub_products_out_of_stock = true;
@@ -912,8 +913,7 @@ public function getObject(Mage_Catalog_Model_Product $product)
912913
$value = $sub_product->getData($attribute_name);
913914

914915
if ($value) {
915-
$values[] = $this->getValueOrValueText($sub_product, $attribute_name,
916-
$attribute_resource, $index_no_value);
916+
$values[] = $this->getValueOrValueText($sub_product, $attribute_name, $attribute_resource);
917917
}
918918
}
919919
}
@@ -928,7 +928,7 @@ public function getObject(Mage_Catalog_Model_Product $product)
928928
$customData['in_stock'] = 0;
929929
}
930930
} elseif (!is_array($value)) {
931-
$value = $this->getValueOrValueText($product, $attribute_name, $attribute_resource, $index_no_value);
931+
$value = $this->getValueOrValueText($product, $attribute_name, $attribute_resource);
932932
}
933933

934934
if ($value && !isset($customData[$attribute_name])) {
@@ -957,6 +957,8 @@ public function getObject(Mage_Catalog_Model_Product $product)
957957

958958
$this->castProductObject($customData);
959959

960+
$customData = $this->clearNoValues($customData);
961+
960962
$this->logger->stop('CREATE RECORD '.$product->getId().' '.$this->logger->getStoreName($product->storeId));
961963

962964
return $customData;
@@ -976,4 +978,28 @@ private function explodeSynomyms($synonyms)
976978
{
977979
return array_map('trim', explode(',', $synonyms));
978980
}
981+
982+
private function setNoAttributes($attributes)
983+
{
984+
foreach ($attributes as $attribute) {
985+
if ($attribute['index_no_value'] !== '1') {
986+
$this->noAttributes[$attribute['attribute']] = 1;
987+
}
988+
}
989+
}
990+
991+
private function clearNoValues($customData, $rootLevel = true)
992+
{
993+
foreach ($customData as $attribute => $value) {
994+
if (is_array($value) && $rootLevel && isset($this->noAttributes[$attribute])) {
995+
$customData[$attribute] = $this->clearNoValues($value, false);
996+
}
997+
998+
if (($rootLevel !== true || isset($this->noAttributes[$attribute])) && $value === Mage::helper('catalog')->__('No')) {
999+
unset($customData[$attribute]);
1000+
}
1001+
}
1002+
1003+
return $customData;
1004+
}
9791005
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ protected function getIndexNameSuffix()
1313
public function getIndexSettings($storeId)
1414
{
1515
return array(
16-
'attributesToIndex' => array('query'),
16+
'attributesToIndex' => array('unordered(query)'),
1717
'customRanking' => array('desc(popularity)', 'desc(number_of_results)', 'asc(date)'),
1818
'typoTolerance' => false,
1919
'attributesToRetrieve' => array('query'),

app/code/community/Algolia/Algoliasearch/Model/Indexer/Abstract.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ protected function _isProductComposite($productId)
8787
/** @var Mage_Catalog_Model_Product $product */
8888
$product = Mage::getModel('catalog/product')->loadByAttribute('entity_id', $productId);
8989

90+
if ($product === false) {
91+
return false;
92+
}
93+
9094
return $product->isComposite();
9195
}
9296
}

0 commit comments

Comments
 (0)