Skip to content

Commit 1ff3b45

Browse files
author
Jan Petr
authored
Merge pull request #848 from algolia/develop
Develop
2 parents b3806dc + 8e7123f commit 1ff3b45

32 files changed

+523
-256
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,13 @@ public function getAttributesToRetrieve($group_id)
384384

385385
$attributes = array();
386386
foreach ($this->getProductAdditionalAttributes() as $attribute) {
387-
if ($attribute['attribute'] !== 'price') {
387+
if ($attribute['attribute'] !== 'price' && $attribute['retrievable'] === '1') {
388+
$attributes[] = $attribute['attribute'];
389+
}
390+
}
391+
392+
foreach ($this->getCategoryAdditionalAttributes() as $attribute) {
393+
if ($attribute['retrievable'] === '1') {
388394
$attributes[] = $attribute['attribute'];
389395
}
390396
}
@@ -416,6 +422,8 @@ public function getAttributesToRetrieve($group_id)
416422
$attributes[] = 'price.'.$currency.'.special_to_date';
417423
}
418424

425+
$attributes = array_unique($attributes);
426+
419427
return $attributes;
420428
}
421429

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -563,10 +563,13 @@ public function rebuildStoreProductIndexPage($storeId, $collectionDefault, $page
563563
$toRealRemove = $indexData['toRemove'];
564564
} else {
565565
$indexData['toRemove'] = array_map('strval', $indexData['toRemove']);
566-
$objects = $this->algolia_helper->getObjects($indexName, $indexData['toRemove']);
567-
foreach ($objects['results'] as $object) {
568-
if (isset($object['objectID'])) {
569-
$toRealRemove[] = $object['objectID'];
566+
567+
foreach (array_chunk($indexData['toRemove'], 1000) as $chunk) {
568+
$objects = $this->algolia_helper->getObjects($indexName, $chunk);
569+
foreach ($objects['results'] as $object) {
570+
if (isset($object['objectID'])) {
571+
$toRealRemove[] = $object['objectID'];
572+
}
570573
}
571574
}
572575
}

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,14 +316,18 @@ public function setSettings($storeId, $saveToTmpIndicesToo = false)
316316

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

319+
/** @var Mage_Core_Model_Store $store */
320+
$store = Mage::getModel('core/store')->load($storeId);
321+
$baseCurrencyCode = $store->getBaseCurrencyCode();
322+
319323
foreach ($sorting_indices as $values) {
320324
if ($this->config->isCustomerGroupsEnabled($storeId) && $values['attribute'] === 'price') {
321325
foreach ($groups = Mage::getModel('customer/group')->getCollection() as $group) {
322326
$group_id = (int) $group->getData('customer_group_id');
323327

324328
$suffix_index_name = 'group_'.$group_id;
325329

326-
$sort_attribute = $values['attribute'] === 'price' ? $values['attribute'].'.'.$currencies[0].'.'.$suffix_index_name : $values['attribute'];
330+
$sort_attribute = $values['attribute'] === 'price' ? $values['attribute'].'.'.$baseCurrencyCode.'.'.$suffix_index_name : $values['attribute'];
327331

328332
$mergeSettings['ranking'] = array(
329333
$values['sort'].'('.$sort_attribute.')',
@@ -340,7 +344,7 @@ public function setSettings($storeId, $saveToTmpIndicesToo = false)
340344
$mergeSettings);
341345
}
342346
} else {
343-
$sort_attribute = $values['attribute'] === 'price' ? $values['attribute'].'.'.$currencies[0].'.'.'default' : $values['attribute'];
347+
$sort_attribute = $values['attribute'] === 'price' ? $values['attribute'].'.'.$baseCurrencyCode.'.'.'default' : $values['attribute'];
344348

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

457+
if (Mage::helper('core')->isModuleEnabled('Mage_Weee') &&
458+
Mage::helper('weee')->getPriceDisplayType($product->getStore()) == 0) {
459+
$weeeTaxAmount = Mage::helper('weee')->getAmountForDisplay($product);
460+
} else {
461+
$weeeTaxAmount = 0;
462+
}
463+
453464
$baseCurrencyCode = $store->getBaseCurrencyCode();
454465

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

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

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

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

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

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

492506
if ($discounted_price !== false) {
493507
$customData[$field][$currency_code]['group_'.$group_id] = (double) $taxHelper->getPrice($product,
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
class Algolia_Algoliasearch_Adminhtml_QueueController extends Mage_Adminhtml_Controller_Action
4+
{
5+
public function indexAction()
6+
{
7+
/** @var Algolia_Algoliasearch_Helper_Config $config */
8+
$config = Mage::helper('algoliasearch/config');
9+
10+
/** @var Mage_Core_Model_Resource $resource */
11+
$resource = Mage::getSingleton('core/resource');
12+
$tableName = $resource->getTableName('algoliasearch/queue');
13+
14+
$readConnection = $resource->getConnection('core_read');
15+
16+
$size = (int) $readConnection->query('SELECT COUNT(*) as total_count FROM '.$tableName)->fetchColumn(0);
17+
$maxJobsPerSingleRun = $config->getNumberOfJobToRun();
18+
19+
$etaMinutes = ceil($size / $maxJobsPerSingleRun) * 5; // 5 - assuming the queue runner runs every 5 minutes
20+
21+
$eta = $etaMinutes . ' minutes';
22+
if ($etaMinutes > 60) {
23+
$hours = floor($etaMinutes / 60);
24+
$restMinutes = $etaMinutes % 60;
25+
26+
$eta = $hours . ' hours ' . $restMinutes . ' minutes';
27+
}
28+
29+
$queueInfo = array(
30+
'isEnabled' => $config->isQueueActive(),
31+
'currentSize' => $size,
32+
'eta' => $eta,
33+
);
34+
35+
$this->sendResponse($queueInfo);
36+
}
37+
38+
public function truncateAction()
39+
{
40+
/** @var Mage_Core_Model_Resource $resource */
41+
$resource = Mage::getSingleton('core/resource');
42+
$tableName = $resource->getTableName('algoliasearch/queue');
43+
44+
try {
45+
$writeConnection = $resource->getConnection('core_write');
46+
$writeConnection->query('TRUNCATE TABLE '.$tableName);
47+
48+
$status = array('status' => 'ok');
49+
} catch (\Exception $e) {
50+
$status = array('status' => 'ko', 'message' => $e->getMessage());
51+
}
52+
53+
$this->sendResponse($status);
54+
}
55+
56+
private function sendResponse($data)
57+
{
58+
$this->getResponse()->setHeader('Content-Type', 'application/json');
59+
$this->getResponse()->setBody(json_encode($data));
60+
}
61+
}

app/code/community/Algolia/Algoliasearch/etc/config.xml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,17 @@
6363
</modules>
6464
</translate>
6565
</adminhtml>
66+
<admin>
67+
<routers>
68+
<adminhtml>
69+
<args>
70+
<modules>
71+
<controller before="Mage_Adminhtml">Algolia_Algoliasearch_Adminhtml</controller>
72+
</modules>
73+
</args>
74+
</adminhtml>
75+
</routers>
76+
</admin>
6677
<global>
6778
<helpers>
6879
<algoliasearch>
@@ -214,7 +225,7 @@
214225
<push_initial_search>0</push_initial_search>
215226
</analytics>
216227
<synonyms>
217-
<enable_synonyms>1</enable_synonyms>
228+
<enable_synonyms>0</enable_synonyms>
218229
</synonyms>
219230
<advanced>
220231
<remove_words_if_no_result>allOptional</remove_words_if_no_result>

0 commit comments

Comments
 (0)