Skip to content

Commit

Permalink
Merge pull request #887 from algolia/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
Jan Petr authored Aug 30, 2017
2 parents f70e9b6 + 4b90016 commit 79fc7a6
Show file tree
Hide file tree
Showing 38 changed files with 888 additions and 121 deletions.
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
## CHANGE LOG

### 1.11.0

## FEATURES
- Added option to turn on autocomplete's `debug` option from configuration (#865)
- The extension now displays the right image for a color variant depending on search query or selected color filter (#883)

## UPDATES
- Added CSS class for proper function of collapsible IS widgets (#859)
- Changed Magento archive URLs in dev containers (#874)
- Updated Magento 1.9.3 version to the latest one in dev container (#882)
- Optimization of `getPopularQueries()` method (#888)

## FIXES
- Fixed the hardcode admin URL for fetching queue info (#854)
- Fixed issue when some attributes weren't set as retrievable when custom groups were enabled (#856)
- Fixed back button which returned all products on category pages (#852)
- Removed not-necessary additional query on category page (#852)
- Fixed displayed link to analytics documentation (#869)
- Fixed store specific facets (#868)
- Fixed option to disable the module by disabling it's output (#866)


### 1.10.0

#### FEATURES
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
Algolia Search for Magento 1.6+
==================

![Latest version](https://img.shields.io/badge/latest-1.10.0-green.svg)
![Latest version](https://img.shields.io/badge/latest-1.11.0-green.svg)

[![Build Status](https://travis-ci.org/algolia/algoliasearch-magento.svg?branch=master)](https://travis-ci.org/algolia/algoliasearch-magento)
![PHP >= 5.3](https://img.shields.io/badge/php-%3E=5.3-green.svg)

Expand Down
42 changes: 38 additions & 4 deletions app/code/community/Algolia/Algoliasearch/Helper/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Algolia_Algoliasearch_Helper_Config extends Mage_Core_Helper_Abstract
const SEARCH_ONLY_API_KEY = 'algoliasearch/credentials/search_only_api_key';
const INDEX_PREFIX = 'algoliasearch/credentials/index_prefix';
const IS_INSTANT_ENABLED = 'algoliasearch/credentials/is_instant_enabled';
const USE_ADAPTIVE_IMAGE = 'algoliasearch/credentials/use_adaptive_image';

const REPLACE_CATEGORIES = 'algoliasearch/instant/replace_categories';
const INSTANT_SELECTOR = 'algoliasearch/instant/instant_selector';
Expand All @@ -30,6 +31,7 @@ class Algolia_Algoliasearch_Helper_Config extends Mage_Core_Helper_Abstract
const MIN_NUMBER_OF_RESULTS = 'algoliasearch/autocomplete/min_number_of_results';
const DISPLAY_SUGGESTIONS_CATEGORIES = 'algoliasearch/autocomplete/display_categories_with_suggestions';
const RENDER_TEMPLATE_DIRECTIVES = 'algoliasearch/autocomplete/render_template_directives';
const AUTOCOMPLETE_MENU_DEBUG = 'algoliasearch/autocomplete/debug';

const NUMBER_OF_PRODUCT_RESULTS = 'algoliasearch/products/number_product_results';
const PRODUCT_ATTRIBUTES = 'algoliasearch/products/product_additional_attributes';
Expand All @@ -48,6 +50,9 @@ class Algolia_Algoliasearch_Helper_Config extends Mage_Core_Helper_Abstract
const IS_ACTIVE = 'algoliasearch/queue/active';
const NUMBER_OF_ELEMENT_BY_PAGE = 'algoliasearch/queue/number_of_element_by_page';
const NUMBER_OF_JOB_TO_RUN = 'algoliasearch/queue/number_of_job_to_run';
const RETRY_LIMIT = 'algoliasearch/queue/number_of_retries';
const CHECK_PRICE_INDEX = 'algoliasearch/queue/check_price_index';
const CHECK_STOCK_INDEX = 'algoliasearch/queue/check_stock_index';

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

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

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

public function getRetryLimit($storeId = null)
{
return (int) Mage::getStoreConfig(self::RETRY_LIMIT, $storeId);
}

public function getRemoveWordsIfNoResult($storeId = null)
{
return Mage::getStoreConfig(self::REMOVE_IF_NO_RESULT, $storeId);
Expand Down Expand Up @@ -294,6 +314,11 @@ public function isInstantEnabled($storeId = null)
return Mage::getStoreConfigFlag(self::IS_INSTANT_ENABLED, $storeId);
}

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

public function getInstantSelector($storeId = null)
{
return Mage::getStoreConfig(self::INSTANT_SELECTOR, $storeId);
Expand All @@ -315,6 +340,11 @@ public function getRenderTemplateDirectives($storeId = null)
return Mage::getStoreConfigFlag(self::RENDER_TEMPLATE_DIRECTIVES, $storeId);
}

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

public function getSortingIndices($storeId = null)
{
/** @var Algolia_Algoliasearch_Helper_Entity_Producthelper $product_helper */
Expand Down Expand Up @@ -424,7 +454,7 @@ public function getAttributesToRetrieve($group_id)

$attributes = array_unique($attributes);

return $attributes;
return array_values($attributes);
}

public function getCategoryAdditionalAttributes($storeId = null)
Expand Down Expand Up @@ -497,13 +527,17 @@ public function getCurrency($storeId = null)

public function getPopularQueries($storeId = null)
{
if (!$this->isInstantEnabled($storeId) || !$this->showSuggestionsOnNoResultsPage($storeId)) {
return array();
}

if ($storeId === null) {
$storeId = Mage::app()->getStore()->getId();
}

/** @var Algolia_Algoliasearch_Helper_Entity_Suggestionhelper $suggestion_helper */
$suggestion_helper = Mage::helper('algoliasearch/entity_suggestionhelper');
$popularQueries = $suggestion_helper->getPopularQueries($storeId);
/** @var Algolia_Algoliasearch_Helper_Entity_Suggestionhelper $suggestionHelper */
$suggestionHelper = Mage::helper('algoliasearch/entity_suggestionhelper');
$popularQueries = $suggestionHelper->getPopularQueries($storeId);

return $popularQueries;
}
Expand Down
32 changes: 25 additions & 7 deletions app/code/community/Algolia/Algoliasearch/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,27 +185,32 @@ public function rebuildStoreAdditionalSectionsIndex($storeId)
}
}

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

return;
}

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

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

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

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

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

$this->algolia_helper->setSettings($index_name, $this->page_helper->getIndexSettings($storeId));
$this->algolia_helper->moveIndex($indexName, $finalIndexName);
$this->algolia_helper->setSettings($finalIndexName, $this->page_helper->getIndexSettings($storeId));
}

$this->stopEmulation($emulationInfo);
}
Expand Down Expand Up @@ -444,6 +449,19 @@ protected function getProductsRecords($storeId, $collection, $potentiallyDeleted
$potentiallyDeletedProductsIds = array();
}

if (method_exists('Mage', 'getEdition') === true && Mage::getEdition() === Mage::EDITION_ENTERPRISE) {
$productIds = array();

/** @var Mage_Catalog_Model_Product $products */
foreach ($collection as $products) {
$productIds[] = $products->getId();
}

/** @var Algolia_Algoliasearch_Helper_IndexChecker $indexChecker */
$indexChecker = Mage::helper('algoliasearch/indexChecker');
$indexChecker->checkIndexers($storeId, $productIds);
}

$this->logger->start('CREATE RECORDS '.$this->logger->getStoreName($storeId));
$this->logger->log(count($collection).' product records to create');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,8 @@ public static function getStores($store_id)
$store_ids[] = $store->getId();
}
}
} elseif (is_array($store_id)) {
return $store_id;
} else {
$store_ids = array($store_id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,18 @@ public function getIndexSettings($storeId)
return $indexSettings;
}

public function getPages($storeId)
public function getPages($storeId, $pageIds = null)
{
/** @var Mage_Cms_Model_Page $cmsPage */
$cmsPage = Mage::getModel('cms/page');

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

if ($pageIds && count($pageIds) > 0) {
$pages = $pages->addFieldToFilter('page_id', array('in' => $pageIds));
}

Mage::dispatchEvent('algolia_after_pages_collection_build', array('store' => $storeId, 'collection' => $pages));

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

return $pages;
}

public function shouldIndexPages($storeId)
{
$autocompleteSections = $this->config->getAutocompleteSections($storeId);

foreach ($autocompleteSections as $section) {
if ($section['name'] === 'pages') {
return true;
}
}

return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ public function setSettings($storeId, $saveToTmpIndicesToo = false)

$customRankingAttributes = array();

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

/** @var Mage_Directory_Model_Currency $directoryCurrency */
$directoryCurrency = Mage::getModel('directory/currency');
Expand Down Expand Up @@ -291,7 +291,7 @@ public function setSettings($storeId, $saveToTmpIndicesToo = false)
/*
* Handle replicas
*/
$sorting_indices = $this->config->getSortingIndices();
$sorting_indices = $this->config->getSortingIndices($storeId);

if (count($sorting_indices) > 0) {
$replicas = array();
Expand Down Expand Up @@ -905,15 +905,16 @@ public function getObject(Mage_Catalog_Model_Product $product)
if ($attribute_resource) {
$attribute_resource->setStoreId($product->getStoreId());

$values = array();
$subProductImages = array();

/**
* if $value is missing or if the attribute is SKU,
* use values from child products.
*/
if (($value === null || 'sku' == $attribute_name) && ($type == 'configurable' || $type == 'grouped' || $type == 'bundle')) {
if ($value === null) {
$values = array();
} else {
$values = array($this->getValueOrValueText($product, $attribute_name, $attribute_resource));
if ($value !== null) {
$values[] = $this->getValueOrValueText($product, $attribute_name, $attribute_resource);
}

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

if ($value) {
$values[] = $this->getValueOrValueText($sub_product, $attribute_name, $attribute_resource);
$textValue = $this->getValueOrValueText($sub_product, $attribute_name, $attribute_resource);

$values[] = $textValue;

if (mb_strtolower($attribute_name, 'utf-8') === 'color') {
$image = $imageHelper->init($sub_product, $this->config->getImageType())
->resize($this->config->getImageWidth(),
$this->config->getImageHeight());

try {
$textValueInLower = mb_strtolower($textValue, 'utf-8');
$subProductImages[$textValueInLower] = $image->toString();
} catch (\Exception $e) {
$this->logger->log($e->getMessage());
$this->logger->log($e->getTraceAsString());
}
}
}
}
}
Expand All @@ -940,6 +957,10 @@ public function getObject(Mage_Catalog_Model_Product $product)
$customData[$attribute_name] = array_values(array_unique($values, SORT_REGULAR));
}

if (empty($subProductImages) === false) {
$customData['images_data'] = $subProductImages;
}

// Set main product out of stock if all
// sub-products are out of stock.
if ($customData['in_stock'] && $all_sub_products_out_of_stock) {
Expand Down
Loading

0 comments on commit 79fc7a6

Please sign in to comment.