Skip to content

Commit

Permalink
Merge pull request #367 from algolia/develop
Browse files Browse the repository at this point in the history
1.5.5 release
  • Loading branch information
maxiloc committed Apr 28, 2016
2 parents a91de23 + afdffd9 commit 0e17a7a
Show file tree
Hide file tree
Showing 28 changed files with 2,343 additions and 910 deletions.
2 changes: 1 addition & 1 deletion Algolia_Algoliasearch.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Algolia_Algoliasearch>
<active>true</active>
<codePool>community</codePool>
<version>1.5.4</version>
<version>1.5.5</version>
</Algolia_Algoliasearch>
</modules>
</config>
18 changes: 16 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
## Change Log

### 1.5.5

- NEW: Add an option to include data from out-of-stock sub products
- NEW: Use secured api keys to only retrieve one group price in the frontend
- NEW: Better update strategy to simplify the indexer code and to avoid missing deleted products event
- UPDATE: Better handling of include in navigation config
- UPDATE: underlying php client
- UPDATE: Conditionally render template directives
- UPDATE: Make sub product skus searchable
- FIX: slaves creation issue
- FIX: small price issue
- FIX: fallback to default search in case there is a error from the api


### 1.5.4

- UPDATED: instantsearch.js update
Expand Down Expand Up @@ -58,7 +72,7 @@

### 1.4.8
- NEW: allow to have custom product types
- NEW: make image generation size parameter customizable to be able to save ressources when already in cache
- NEW: make image generation size parameter customizable to be able to save resources when already in cache
- UPDATED: remove root category when fetching product categories
- UPDATED: rewrite image class to be able to log the error when not being able to generate it
- UPDATED: Handle display price with AND without tax
Expand Down Expand Up @@ -198,6 +212,6 @@
- Upgrade the underlying Algolia PHP API client to 1.5.5 (high available DNS)

### 1.0.3
- Upgrade the underlying PHP API client to 1.5.4
- Upgrade the underlying PHP API client to 1.5.5
- Fix deadlock that may occur with order processing
- Fix results saved every search (remove flag probably added for debugging).
8 changes: 8 additions & 0 deletions code/Helper/Algoliahelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
require_once Mage::getBaseDir('lib').'/AlgoliaSearch/ClientContext.php';
require_once Mage::getBaseDir('lib').'/AlgoliaSearch/Client.php';
require_once Mage::getBaseDir('lib').'/AlgoliaSearch/Index.php';
require_once Mage::getBaseDir('lib').'/AlgoliaSearch/PlacesIndex.php';
require_once Mage::getBaseDir('lib').'/AlgoliaSearch/IndexBrowser.php';
}

class Algolia_Algoliasearch_Helper_Algoliahelper extends Mage_Core_Helper_Abstract
{
/** @var \AlgoliaSearch\Client */
protected $client;
protected $config;

Expand All @@ -26,6 +29,11 @@ public function resetCredentialsFromConfig()
$this->client = new \AlgoliaSearch\Client($this->config->getApplicationID(), $this->config->getAPIKey());
}

public function generateSearchSecuredApiKey($key, $params = array())
{
return $this->client->generateSecuredApiKey($key, $params);
}

public function getIndex($name)
{
return $this->client->initIndex($name);
Expand Down
56 changes: 52 additions & 4 deletions code/Helper/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,19 @@ class Algolia_Algoliasearch_Helper_Config extends Mage_Core_Helper_Abstract
const EXCLUDED_PAGES = 'algoliasearch/autocomplete/excluded_pages';
const MIN_POPULARITY = 'algoliasearch/autocomplete/min_popularity';
const MIN_NUMBER_OF_RESULTS = 'algoliasearch/autocomplete/min_number_of_results';
const RENDER_TEMPLATE_DIRECTIVES = 'algoliasearch/autocomplete/render_template_directives';

const NUMBER_OF_PRODUCT_RESULTS = 'algoliasearch/products/number_product_results';
const PRODUCT_ATTRIBUTES = 'algoliasearch/products/product_additional_attributes';
const PRODUCT_CUSTOM_RANKING = 'algoliasearch/products/custom_ranking_product_attributes';
const RESULTS_LIMIT = 'algoliasearch/products/results_limit';
const SHOW_SUGGESTIONS_NO_RESULTS = 'algoliasearch/products/show_suggestions_on_no_result_page';
const INDEX_OUT_OF_STOCK_OPTIONS = 'algoliasearch/products/index_out_of_stock_options';

const CATEGORY_ATTRIBUTES = 'algoliasearch/categories/category_additional_attributes2';
const INDEX_PRODUCT_COUNT = 'algoliasearch/categories/index_product_count';
const CATEGORY_CUSTOM_RANKING = 'algoliasearch/categories/custom_ranking_category_attributes';
const SHOW_CATS_NOT_INCLUDED_IN_NAVIGATION = 'algoliasearch/categories/show_cats_not_included_in_navigation';


const IS_ACTIVE = 'algoliasearch/queue/active';
Expand All @@ -60,6 +63,16 @@ class Algolia_Algoliasearch_Helper_Config extends Mage_Core_Helper_Abstract

protected $_productTypeMap = array();

public function indexOutOfStockOptions($storeId = null)
{
return Mage::getStoreConfigFlag(self::INDEX_OUT_OF_STOCK_OPTIONS, $storeId);
}

public function showCatsNotIncludedInNavigation($storeId = null)
{
return Mage::getStoreConfigFlag(self::SHOW_CATS_NOT_INCLUDED_IN_NAVIGATION, $storeId);
}

public function isDefaultSelector($storeId = null)
{
return '.algolia-search-input' === $this->getAutocompleteSelector($storeId);
Expand Down Expand Up @@ -259,6 +272,11 @@ public function getExcludedPages($storeId = NULL)
return array();
}

public function getRenderTemplateDirectives($storeId = NULL)
{
return Mage::getStoreConfigFlag(self::RENDER_TEMPLATE_DIRECTIVES, $storeId);
}

public function getSortingIndices($storeId = NULL)
{
$product_helper = Mage::helper('algoliasearch/entity_producthelper');
Expand Down Expand Up @@ -297,22 +315,52 @@ public function getSortingIndices($storeId = NULL)

public function getApplicationID($storeId = NULL)
{
return Mage::getStoreConfig(self::APPLICATION_ID, $storeId);
return trim(Mage::getStoreConfig(self::APPLICATION_ID, $storeId));
}

public function getAPIKey($storeId = NULL)
{
return Mage::getStoreConfig(self::API_KEY, $storeId);
return trim(Mage::getStoreConfig(self::API_KEY, $storeId));
}

public function getSearchOnlyAPIKey($storeId = NULL)
{
return Mage::getStoreConfig(self::SEARCH_ONLY_API_KEY, $storeId);
return trim(Mage::getStoreConfig(self::SEARCH_ONLY_API_KEY, $storeId));
}

public function getIndexPrefix($storeId = NULL)
{
return Mage::getStoreConfig(self::INDEX_PREFIX, $storeId);
return trim(Mage::getStoreConfig(self::INDEX_PREFIX, $storeId));
}

public function getAttributesToRetrieve($group_id)
{
if (false === $this->isCustomerGroupsEnabled()) {
return [];
}

$attributes = array();
foreach ($this->getProductAdditionalAttributes() as $attribute) {
if ($attribute['attribute'] !== 'price') {
$attributes[] = $attribute['attribute'];
}
}

$attributes = array_merge($attributes, ['objectID', 'name', 'url', 'visibility_search', 'visibility_catalog', 'categories', 'categories_without_path', 'thumbnail_url', 'image_url', 'in_stock', 'type_id']);

$currencies = Mage::getModel('directory/currency')->getConfigAllowCurrencies();

foreach ($currencies as $currency) {
$attributes[] = 'price.'.$currency.'.default';
$attributes[] = 'price.'.$currency.'.default_formated';
$attributes[] = 'price.'.$currency.'.group_'.$group_id;
$attributes[] = 'price.'.$currency.'.group_'.$group_id.'_formated';
$attributes[] = 'price.'.$currency.'.special_from_date';
$attributes[] = 'price.'.$currency.'.special_to_date';
}


return ['attributesToRetrieve' => $attributes];
}

public function getCategoryAdditionalAttributes($storeId = NULL)
Expand Down
4 changes: 3 additions & 1 deletion code/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
require_once Mage::getBaseDir('lib').'/AlgoliaSearch/ClientContext.php';
require_once Mage::getBaseDir('lib').'/AlgoliaSearch/Client.php';
require_once Mage::getBaseDir('lib').'/AlgoliaSearch/Index.php';
require_once Mage::getBaseDir('lib').'/AlgoliaSearch/PlacesIndex.php';
require_once Mage::getBaseDir('lib').'/AlgoliaSearch/IndexBrowser.php';
}

class Algolia_Algoliasearch_Helper_Data extends Mage_Core_Helper_Abstract
Expand All @@ -25,7 +27,7 @@ class Algolia_Algoliasearch_Helper_Data extends Mage_Core_Helper_Abstract

public function __construct()
{
\AlgoliaSearch\Version::$custom_value = " Magento (1.5.4)";
\AlgoliaSearch\Version::$custom_value = " Magento (1.5.5)";

$this->algolia_helper = Mage::helper('algoliasearch/algoliahelper');

Expand Down
11 changes: 7 additions & 4 deletions code/Helper/Entity/Additionalsectionshelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ public function getAttributeValues($storeId, $section)
$products = Mage::getResourceModel('catalog/product_collection')
->addStoreFilter($storeId)
->addAttributeToFilter('visibility', array('in' => Mage::getSingleton('catalog/product_visibility')->getVisibleInSearchIds()))
->addAttributeToFilter('status', array('eq' => Mage_Catalog_Model_Product_Status::STATUS_ENABLED))
->addAttributeToFilter($attributeCode, array('notnull' => true))
->addAttributeToFilter($attributeCode, array('neq' => ''))
->addAttributeToSelect($attributeCode);

$usedAttributeValues = array_unique($products->getColumnValues($attributeCode));
$usedAttributeValues = array_keys(array_flip( // array unique
explode(',', implode(',', $products->getColumnValues($attributeCode)))));

$attributeModel = Mage::getSingleton('eav/config')
->getAttribute('catalog_product', $attributeCode)
Expand All @@ -45,7 +47,7 @@ public function getAttributeValues($storeId, $section)
$values = array($values);
}

$values = array_map(function ($value) use ($section) {
$values = array_map(function ($value) use ($section, $storeId) {

$record = array(
'objectID' => $value,
Expand All @@ -54,7 +56,8 @@ public function getAttributeValues($storeId, $section)

$transport = new Varien_Object($record);

Mage::dispatchEvent('algolia_additional_section_item_index_before', array('section' => $section, 'record' => $transport));
Mage::dispatchEvent('algolia_additional_section_item_index_before',
array('section' => $section, 'record' => $transport, 'store_id' => $storeId));

$record = $transport->getData();

Expand All @@ -63,4 +66,4 @@ public function getAttributeValues($storeId, $section)

return $values;
}
}
}
26 changes: 14 additions & 12 deletions code/Helper/Entity/Categoryhelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,14 @@ public function getCategoryCollectionQuery($storeId, $categoryIds = null)
foreach ($unserializedCategorysAttrs as $attr)
$additionalAttr[] = $attr['attribute'];

$additionalAttr[] = 'include_in_menu';

$categories
->addPathFilter($storeRootCategoryPath)
->addNameToResult()
->addUrlRewriteToResult()
->addIsActiveFilter()
->setStoreId($storeId)
->addAttributeToFilter('include_in_menu', '1')
->addAttributeToSelect(array_merge(array('name'), $additionalAttr))
->addFieldToFilter('level', array('gt' => 1));

Expand Down Expand Up @@ -140,14 +141,15 @@ public function getObject(Mage_Catalog_Model_Category $category)
} catch (Exception $e) { /* no image, no default: not fatal */
}
$data = array(
'objectID' => $category->getId(),
'name' => $category->getName(),
'path' => $path,
'level' => $category->getLevel(),
'url' => $category->getUrl(),
'_tags' => array('category'),
'popularity' => 1,
'product_count' => $category->getProductCount()
'objectID' => $category->getId(),
'name' => $category->getName(),
'path' => $path,
'level' => $category->getLevel(),
'url' => $category->getUrl(),
'include_in_menu' => $category->getIncludeInMenu(),
'_tags' => array('category'),
'popularity' => 1,
'product_count' => $category->getProductCount()
);

if ( ! empty($image_url)) {
Expand All @@ -158,11 +160,11 @@ public function getObject(Mage_Catalog_Model_Category $category)
{
$value = $category->getData($attribute['attribute']);

$attribute_ressource = $category->getResource()->getAttribute($attribute['attribute']);
$attribute_resource = $category->getResource()->getAttribute($attribute['attribute']);

if ($attribute_ressource)
if ($attribute_resource)
{
$value = $attribute_ressource->getFrontend()->getValue($category);
$value = $attribute_resource->getFrontend()->getValue($category);
}

if (isset($data[$attribute['attribute']]))
Expand Down
3 changes: 2 additions & 1 deletion code/Helper/Entity/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ protected function strip($s)
$s = trim(preg_replace('/\s+/', ' ', $s));
$s = preg_replace('/&nbsp;/', ' ', $s);
$s = preg_replace('!\s+!', ' ', $s);
$s = preg_replace('/\{\{[^}]+\}\}/', ' ', $s);

return trim(strip_tags($s));
}
Expand Down Expand Up @@ -231,4 +232,4 @@ public static function getStores($store_id)
return $store_ids;
}

}
}
11 changes: 8 additions & 3 deletions code/Helper/Entity/Pagehelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,19 @@ public function getPages($storeId)
if (! $page->getId())
continue;

$page_obj['objectID'] = $page->getId();
$content = $page->getContent();
if ($this->config->getRenderTemplateDirectives()) {
$tmplProc = Mage::helper('cms')->getPageTemplateProcessor();
$content = $tmplProc->filter($content);
}

$page_obj['objectID'] = $page->getId();
$page_obj['url'] = Mage::helper('cms/page')->getPageUrl($page->getId());
$page_obj['content'] = $this->strip($page->getContent());
$page_obj['content'] = $this->strip($content);

$pages[] = $page_obj;
}

return $pages;
}
}
}
Loading

0 comments on commit 0e17a7a

Please sign in to comment.