Skip to content

Commit

Permalink
Merge pull request #848 from algolia/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Jan Petr authored Jun 12, 2017
2 parents b3806dc + 8e7123f commit 1ff3b45
Show file tree
Hide file tree
Showing 32 changed files with 523 additions and 256 deletions.
10 changes: 9 additions & 1 deletion app/code/community/Algolia/Algoliasearch/Helper/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,13 @@ public function getAttributesToRetrieve($group_id)

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

foreach ($this->getCategoryAdditionalAttributes() as $attribute) {
if ($attribute['retrievable'] === '1') {
$attributes[] = $attribute['attribute'];
}
}
Expand Down Expand Up @@ -416,6 +422,8 @@ public function getAttributesToRetrieve($group_id)
$attributes[] = 'price.'.$currency.'.special_to_date';
}

$attributes = array_unique($attributes);

return $attributes;
}

Expand Down
11 changes: 7 additions & 4 deletions app/code/community/Algolia/Algoliasearch/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -563,10 +563,13 @@ public function rebuildStoreProductIndexPage($storeId, $collectionDefault, $page
$toRealRemove = $indexData['toRemove'];
} else {
$indexData['toRemove'] = array_map('strval', $indexData['toRemove']);
$objects = $this->algolia_helper->getObjects($indexName, $indexData['toRemove']);
foreach ($objects['results'] as $object) {
if (isset($object['objectID'])) {
$toRealRemove[] = $object['objectID'];

foreach (array_chunk($indexData['toRemove'], 1000) as $chunk) {
$objects = $this->algolia_helper->getObjects($indexName, $chunk);
foreach ($objects['results'] as $object) {
if (isset($object['objectID'])) {
$toRealRemove[] = $object['objectID'];
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,14 +316,18 @@ public function setSettings($storeId, $saveToTmpIndicesToo = false)

$this->algolia_helper->setSettings($this->getIndexName($storeId), array('replicas' => $replicas));

/** @var Mage_Core_Model_Store $store */
$store = Mage::getModel('core/store')->load($storeId);
$baseCurrencyCode = $store->getBaseCurrencyCode();

foreach ($sorting_indices as $values) {
if ($this->config->isCustomerGroupsEnabled($storeId) && $values['attribute'] === 'price') {
foreach ($groups = Mage::getModel('customer/group')->getCollection() as $group) {
$group_id = (int) $group->getData('customer_group_id');

$suffix_index_name = 'group_'.$group_id;

$sort_attribute = $values['attribute'] === 'price' ? $values['attribute'].'.'.$currencies[0].'.'.$suffix_index_name : $values['attribute'];
$sort_attribute = $values['attribute'] === 'price' ? $values['attribute'].'.'.$baseCurrencyCode.'.'.$suffix_index_name : $values['attribute'];

$mergeSettings['ranking'] = array(
$values['sort'].'('.$sort_attribute.')',
Expand All @@ -340,7 +344,7 @@ public function setSettings($storeId, $saveToTmpIndicesToo = false)
$mergeSettings);
}
} else {
$sort_attribute = $values['attribute'] === 'price' ? $values['attribute'].'.'.$currencies[0].'.'.'default' : $values['attribute'];
$sort_attribute = $values['attribute'] === 'price' ? $values['attribute'].'.'.$baseCurrencyCode.'.'.'default' : $values['attribute'];

$mergeSettings['ranking'] = array(
$values['sort'].'('.$sort_attribute.')',
Expand Down Expand Up @@ -450,6 +454,13 @@ protected function handlePrice(Mage_Catalog_Model_Product &$product, $sub_produc
$directoryCurrency = Mage::getModel('directory/currency');
$currencies = $directoryCurrency->getConfigAllowCurrencies();

if (Mage::helper('core')->isModuleEnabled('Mage_Weee') &&
Mage::helper('weee')->getPriceDisplayType($product->getStore()) == 0) {
$weeeTaxAmount = Mage::helper('weee')->getAmountForDisplay($product);
} else {
$weeeTaxAmount = 0;
}

$baseCurrencyCode = $store->getBaseCurrencyCode();

$groups = array();
Expand All @@ -472,12 +483,14 @@ protected function handlePrice(Mage_Catalog_Model_Product &$product, $sub_produc

$price = (double) $taxHelper->getPrice($product, $product->getPrice(), $with_tax, null, null, null, $product->getStore(), null);
$price = $directoryHelper->currencyConvert($price, $baseCurrencyCode, $currency_code);
$price += $weeeTaxAmount;

$customData[$field][$currency_code]['default'] = $price;
$customData[$field][$currency_code]['default_formated'] = $this->formatPrice($price, false, $currency_code);

$special_price = (double) $taxHelper->getPrice($product, $product->getFinalPrice(), $with_tax, null, null, null, $product->getStore(), null);
$special_price = $directoryHelper->currencyConvert($special_price, $baseCurrencyCode, $currency_code);
$special_price += $weeeTaxAmount;

if ($customer_groups_enabled) {
// If fetch special price for groups
Expand All @@ -488,6 +501,7 @@ protected function handlePrice(Mage_Catalog_Model_Product &$product, $sub_produc

$discounted_price = $product->getPriceModel()->getFinalPrice(1, $product);
$discounted_price = $directoryHelper->currencyConvert($discounted_price, $baseCurrencyCode, $currency_code);
$discounted_price += $weeeTaxAmount;

if ($discounted_price !== false) {
$customData[$field][$currency_code]['group_'.$group_id] = (double) $taxHelper->getPrice($product,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

class Algolia_Algoliasearch_Adminhtml_QueueController extends Mage_Adminhtml_Controller_Action
{
public function indexAction()
{
/** @var Algolia_Algoliasearch_Helper_Config $config */
$config = Mage::helper('algoliasearch/config');

/** @var Mage_Core_Model_Resource $resource */
$resource = Mage::getSingleton('core/resource');
$tableName = $resource->getTableName('algoliasearch/queue');

$readConnection = $resource->getConnection('core_read');

$size = (int) $readConnection->query('SELECT COUNT(*) as total_count FROM '.$tableName)->fetchColumn(0);
$maxJobsPerSingleRun = $config->getNumberOfJobToRun();

$etaMinutes = ceil($size / $maxJobsPerSingleRun) * 5; // 5 - assuming the queue runner runs every 5 minutes

$eta = $etaMinutes . ' minutes';
if ($etaMinutes > 60) {
$hours = floor($etaMinutes / 60);
$restMinutes = $etaMinutes % 60;

$eta = $hours . ' hours ' . $restMinutes . ' minutes';
}

$queueInfo = array(
'isEnabled' => $config->isQueueActive(),
'currentSize' => $size,
'eta' => $eta,
);

$this->sendResponse($queueInfo);
}

public function truncateAction()
{
/** @var Mage_Core_Model_Resource $resource */
$resource = Mage::getSingleton('core/resource');
$tableName = $resource->getTableName('algoliasearch/queue');

try {
$writeConnection = $resource->getConnection('core_write');
$writeConnection->query('TRUNCATE TABLE '.$tableName);

$status = array('status' => 'ok');
} catch (\Exception $e) {
$status = array('status' => 'ko', 'message' => $e->getMessage());
}

$this->sendResponse($status);
}

private function sendResponse($data)
{
$this->getResponse()->setHeader('Content-Type', 'application/json');
$this->getResponse()->setBody(json_encode($data));
}
}
13 changes: 12 additions & 1 deletion app/code/community/Algolia/Algoliasearch/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@
</modules>
</translate>
</adminhtml>
<admin>
<routers>
<adminhtml>
<args>
<modules>
<controller before="Mage_Adminhtml">Algolia_Algoliasearch_Adminhtml</controller>
</modules>
</args>
</adminhtml>
</routers>
</admin>
<global>
<helpers>
<algoliasearch>
Expand Down Expand Up @@ -214,7 +225,7 @@
<push_initial_search>0</push_initial_search>
</analytics>
<synonyms>
<enable_synonyms>1</enable_synonyms>
<enable_synonyms>0</enable_synonyms>
</synonyms>
<advanced>
<remove_words_if_no_result>allOptional</remove_words_if_no_result>
Expand Down
Loading

0 comments on commit 1ff3b45

Please sign in to comment.