Version Notes
- UPDATED: improve indexing performance
- FIX: Issue with importing AlgoliaSearch
- FIX: CSS issue
- FIX: Prevent purchase from crashing if Algolia account is blocked
Download this release
Release Info
| Developer | Algolia Team |
| Extension | algoliasearch |
| Version | 1.4.3 |
| Comparing to | |
| See all releases | |
Code changes from version 1.4.2 to 1.4.3
- app/code/community/Algolia/Algoliasearch/Helper/Data.php +6 -8
- app/code/community/Algolia/Algoliasearch/Helper/Entity/Producthelper.php +35 -28
- app/code/community/Algolia/Algoliasearch/Model/Observer.php +9 -1
- app/code/community/Algolia/Algoliasearch/etc/system.xml +1 -1
- app/design/frontend/base/default/template/algoliasearch/topsearch.phtml +6 -1
- package.xml +8 -5
- skin/frontend/base/default/algoliasearch/algoliasearch.css +6 -3
app/code/community/Algolia/Algoliasearch/Helper/Data.php
CHANGED
|
@@ -2,11 +2,11 @@
|
|
| 2 |
|
| 3 |
if (class_exists('AlgoliaSearch\Client', false) == false)
|
| 4 |
{
|
| 5 |
-
require_once 'AlgoliaSearch/Version.php';
|
| 6 |
-
require_once 'AlgoliaSearch/AlgoliaException.php';
|
| 7 |
-
require_once 'AlgoliaSearch/ClientContext.php';
|
| 8 |
-
require_once 'AlgoliaSearch/Client.php';
|
| 9 |
-
require_once 'AlgoliaSearch/Index.php';
|
| 10 |
}
|
| 11 |
|
| 12 |
class Algolia_Algoliasearch_Helper_Data extends Mage_Core_Helper_Abstract
|
|
@@ -23,7 +23,7 @@ class Algolia_Algoliasearch_Helper_Data extends Mage_Core_Helper_Abstract
|
|
| 23 |
|
| 24 |
public function __construct()
|
| 25 |
{
|
| 26 |
-
\AlgoliaSearch\Version::$custom_value = " Magento (1.4.
|
| 27 |
|
| 28 |
$this->algolia_helper = Mage::helper('algoliasearch/algoliahelper');
|
| 29 |
|
|
@@ -338,8 +338,6 @@ class Algolia_Algoliasearch_Helper_Data extends Mage_Core_Helper_Abstract
|
|
| 338 |
|
| 339 |
public function rebuildStoreProductIndexPage($storeId, $collectionDefault, $page, $pageSize)
|
| 340 |
{
|
| 341 |
-
set_time_limit(0);
|
| 342 |
-
|
| 343 |
$collection = clone $collectionDefault;
|
| 344 |
$collection->setCurPage($page)->setPageSize($pageSize);
|
| 345 |
$collection->load();
|
| 2 |
|
| 3 |
if (class_exists('AlgoliaSearch\Client', false) == false)
|
| 4 |
{
|
| 5 |
+
require_once Mage::getBaseDir('lib').'/AlgoliaSearch/Version.php';
|
| 6 |
+
require_once Mage::getBaseDir('lib').'/AlgoliaSearch/AlgoliaException.php';
|
| 7 |
+
require_once Mage::getBaseDir('lib').'/AlgoliaSearch/ClientContext.php';
|
| 8 |
+
require_once Mage::getBaseDir('lib').'/AlgoliaSearch/Client.php';
|
| 9 |
+
require_once Mage::getBaseDir('lib').'/AlgoliaSearch/Index.php';
|
| 10 |
}
|
| 11 |
|
| 12 |
class Algolia_Algoliasearch_Helper_Data extends Mage_Core_Helper_Abstract
|
| 23 |
|
| 24 |
public function __construct()
|
| 25 |
{
|
| 26 |
+
\AlgoliaSearch\Version::$custom_value = " Magento (1.4.3)";
|
| 27 |
|
| 28 |
$this->algolia_helper = Mage::helper('algoliasearch/algoliahelper');
|
| 29 |
|
| 338 |
|
| 339 |
public function rebuildStoreProductIndexPage($storeId, $collectionDefault, $page, $pageSize)
|
| 340 |
{
|
|
|
|
|
|
|
| 341 |
$collection = clone $collectionDefault;
|
| 342 |
$collection->setCurPage($page)->setPageSize($pageSize);
|
| 343 |
$collection->load();
|
app/code/community/Algolia/Algoliasearch/Helper/Entity/Producthelper.php
CHANGED
|
@@ -59,26 +59,18 @@ class Algolia_Algoliasearch_Helper_Entity_Producthelper extends Algolia_Algolias
|
|
| 59 |
return false;
|
| 60 |
}
|
| 61 |
|
| 62 |
-
|
| 63 |
-
{
|
| 64 |
-
$report = Mage::getResourceModel('reports/product_collection')
|
| 65 |
-
->addOrderedQty()
|
| 66 |
-
->addAttributeToFilter('sku', $product->getSku())
|
| 67 |
-
->setOrder('ordered_qty', 'desc')
|
| 68 |
-
->getFirstItem();
|
| 69 |
-
|
| 70 |
-
return $report;
|
| 71 |
-
}
|
| 72 |
-
|
| 73 |
-
public function getProductCollectionQuery($storeId, $productIds = null)
|
| 74 |
{
|
| 75 |
/** @var $products Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection */
|
| 76 |
$products = Mage::getResourceModel('catalog/product_collection');
|
| 77 |
|
| 78 |
$products = $products->setStoreId($storeId)
|
| 79 |
-
->addStoreFilter($storeId)
|
| 80 |
-
|
| 81 |
-
|
|
|
|
|
|
|
|
|
|
| 82 |
->addAttributeToSelect('special_from_date')
|
| 83 |
->addAttributeToSelect('special_to_date')
|
| 84 |
->addAttributeToFilter('status', Mage_Catalog_Model_Product_Status::STATUS_ENABLED);
|
|
@@ -377,6 +369,8 @@ class Algolia_Algoliasearch_Helper_Entity_Producthelper extends Algolia_Algolias
|
|
| 377 |
$additionalAttributes = $this->config->getProductAdditionalAttributes($product->getStoreId());
|
| 378 |
|
| 379 |
$sub_products = null;
|
|
|
|
|
|
|
| 380 |
|
| 381 |
if ($product->getTypeId() == 'configurable' || $product->getTypeId() == 'grouped')
|
| 382 |
{
|
|
@@ -386,16 +380,21 @@ class Algolia_Algoliasearch_Helper_Entity_Producthelper extends Algolia_Algolias
|
|
| 386 |
if ($product->getTypeId() == 'configurable')
|
| 387 |
$sub_products = $product->getTypeInstance(true)->getUsedProducts(null, $product);
|
| 388 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 389 |
$min = PHP_INT_MAX;
|
| 390 |
$max = 0;
|
| 391 |
|
| 392 |
$min_with_tax = PHP_INT_MAX;
|
| 393 |
$max_with_tax = 0;
|
| 394 |
|
|
|
|
| 395 |
foreach ($sub_products as $sub_product)
|
| 396 |
{
|
| 397 |
-
$sub_product = Mage::getModel('catalog/product')->load($sub_product->getId());
|
| 398 |
-
|
| 399 |
$price = $sub_product->getPrice();
|
| 400 |
$price_with_tax = Mage::helper('tax')->getPrice($sub_product, $price, true, null, null, null, null, false);
|
| 401 |
|
|
@@ -422,13 +421,14 @@ class Algolia_Algoliasearch_Helper_Entity_Producthelper extends Algolia_Algolias
|
|
| 422 |
// skip default calculation if we have provided these attributes via the observer in $defaultData
|
| 423 |
if (false === isset($defaultData['ordered_qty']) && false === isset($defaultData['stock_qty']))
|
| 424 |
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 425 |
|
| 426 |
-
$ordered_qty =
|
| 427 |
-
->addOrderedQty()
|
| 428 |
-
->addAttributeToFilter('sku', $product->getSku())
|
| 429 |
-
->setOrder('ordered_qty', 'desc')
|
| 430 |
-
->getFirstItem()
|
| 431 |
-
->ordered_qty;
|
| 432 |
|
| 433 |
$customData['ordered_qty'] = (int) $ordered_qty;
|
| 434 |
$customData['stock_qty'] = (int) Mage::getModel('cataloginventory/stock_item')->loadByProduct($product)->getQty();
|
|
@@ -442,20 +442,29 @@ class Algolia_Algoliasearch_Helper_Entity_Producthelper extends Algolia_Algolias
|
|
| 442 |
{
|
| 443 |
$stock_qty += (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($sub_product)->getQty();
|
| 444 |
|
| 445 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 446 |
}
|
| 447 |
|
| 448 |
$customData['ordered_qty'] = $ordered_qty;
|
| 449 |
$customData['stock_qty'] = $stock_qty;
|
| 450 |
}
|
| 451 |
|
| 452 |
-
|
|
|
|
| 453 |
unset($customData['ordered_qty']);
|
| 454 |
|
| 455 |
-
if ($this->isAttributeEnabled($additionalAttributes, 'stock_qty')
|
| 456 |
unset($customData['stock_qty']);
|
| 457 |
}
|
| 458 |
|
|
|
|
| 459 |
if ($this->isAttributeEnabled($additionalAttributes, 'rating_summary'))
|
| 460 |
{
|
| 461 |
$summaryData = Mage::getModel('review/review_summary')
|
|
@@ -488,8 +497,6 @@ class Algolia_Algoliasearch_Helper_Entity_Producthelper extends Algolia_Algolias
|
|
| 488 |
|
| 489 |
foreach ($sub_products as $sub_product)
|
| 490 |
{
|
| 491 |
-
$sub_product = Mage::getModel('catalog/product')->load($sub_product->getId());
|
| 492 |
-
|
| 493 |
$value = $sub_product->getData($attribute['attribute']);
|
| 494 |
|
| 495 |
if ($value)
|
| 59 |
return false;
|
| 60 |
}
|
| 61 |
|
| 62 |
+
public function getProductCollectionQuery($storeId, $productIds = null, $only_visible = true)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
{
|
| 64 |
/** @var $products Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection */
|
| 65 |
$products = Mage::getResourceModel('catalog/product_collection');
|
| 66 |
|
| 67 |
$products = $products->setStoreId($storeId)
|
| 68 |
+
->addStoreFilter($storeId);
|
| 69 |
+
|
| 70 |
+
if ($only_visible)
|
| 71 |
+
$products = $products->addAttributeToFilter('visibility', array('in' => Mage::getSingleton('catalog/product_visibility')->getVisibleInSearchIds()));
|
| 72 |
+
|
| 73 |
+
$products = $products->addFinalPrice()
|
| 74 |
->addAttributeToSelect('special_from_date')
|
| 75 |
->addAttributeToSelect('special_to_date')
|
| 76 |
->addAttributeToFilter('status', Mage_Catalog_Model_Product_Status::STATUS_ENABLED);
|
| 369 |
$additionalAttributes = $this->config->getProductAdditionalAttributes($product->getStoreId());
|
| 370 |
|
| 371 |
$sub_products = null;
|
| 372 |
+
$ids = null;
|
| 373 |
+
|
| 374 |
|
| 375 |
if ($product->getTypeId() == 'configurable' || $product->getTypeId() == 'grouped')
|
| 376 |
{
|
| 380 |
if ($product->getTypeId() == 'configurable')
|
| 381 |
$sub_products = $product->getTypeInstance(true)->getUsedProducts(null, $product);
|
| 382 |
|
| 383 |
+
$ids = array_map(function ($product) {
|
| 384 |
+
return $product->getId();
|
| 385 |
+
}, $sub_products);
|
| 386 |
+
|
| 387 |
+
$sub_products = $this->getProductCollectionQuery($product->getStoreId(), $ids, false)->load();
|
| 388 |
+
|
| 389 |
$min = PHP_INT_MAX;
|
| 390 |
$max = 0;
|
| 391 |
|
| 392 |
$min_with_tax = PHP_INT_MAX;
|
| 393 |
$max_with_tax = 0;
|
| 394 |
|
| 395 |
+
|
| 396 |
foreach ($sub_products as $sub_product)
|
| 397 |
{
|
|
|
|
|
|
|
| 398 |
$price = $sub_product->getPrice();
|
| 399 |
$price_with_tax = Mage::helper('tax')->getPrice($sub_product, $price, true, null, null, null, null, false);
|
| 400 |
|
| 421 |
// skip default calculation if we have provided these attributes via the observer in $defaultData
|
| 422 |
if (false === isset($defaultData['ordered_qty']) && false === isset($defaultData['stock_qty']))
|
| 423 |
{
|
| 424 |
+
$query = Mage::getResourceModel('sales/order_item_collection');
|
| 425 |
+
$query->getSelect()->reset(Zend_Db_Select::COLUMNS)
|
| 426 |
+
->columns(array('sku','SUM(qty_ordered) as ordered_qty'))
|
| 427 |
+
->group(array('sku'))
|
| 428 |
+
->where('sku = ?',array($product->getSku()))
|
| 429 |
+
->limit(1);
|
| 430 |
|
| 431 |
+
$ordered_qty = (int) $query->getFirstItem()->ordered_qty;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 432 |
|
| 433 |
$customData['ordered_qty'] = (int) $ordered_qty;
|
| 434 |
$customData['stock_qty'] = (int) Mage::getModel('cataloginventory/stock_item')->loadByProduct($product)->getQty();
|
| 442 |
{
|
| 443 |
$stock_qty += (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($sub_product)->getQty();
|
| 444 |
|
| 445 |
+
$query = Mage::getResourceModel('sales/order_item_collection');
|
| 446 |
+
$query->getSelect()->reset(Zend_Db_Select::COLUMNS)
|
| 447 |
+
->columns(array('sku','SUM(qty_ordered) as ordered_qty'))
|
| 448 |
+
->group(array('sku'))
|
| 449 |
+
->where('sku = ?',array($sub_product->getSku()))
|
| 450 |
+
->limit(1);
|
| 451 |
+
|
| 452 |
+
$ordered_qty += (int) $query->getFirstItem()->ordered_qty;
|
| 453 |
}
|
| 454 |
|
| 455 |
$customData['ordered_qty'] = $ordered_qty;
|
| 456 |
$customData['stock_qty'] = $stock_qty;
|
| 457 |
}
|
| 458 |
|
| 459 |
+
|
| 460 |
+
if ($this->isAttributeEnabled($additionalAttributes, 'ordered_qty') === false)
|
| 461 |
unset($customData['ordered_qty']);
|
| 462 |
|
| 463 |
+
if ($this->isAttributeEnabled($additionalAttributes, 'stock_qty') === false)
|
| 464 |
unset($customData['stock_qty']);
|
| 465 |
}
|
| 466 |
|
| 467 |
+
|
| 468 |
if ($this->isAttributeEnabled($additionalAttributes, 'rating_summary'))
|
| 469 |
{
|
| 470 |
$summaryData = Mage::getModel('review/review_summary')
|
| 497 |
|
| 498 |
foreach ($sub_products as $sub_product)
|
| 499 |
{
|
|
|
|
|
|
|
| 500 |
$value = $sub_product->getData($attribute['attribute']);
|
| 501 |
|
| 502 |
if ($value)
|
app/code/community/Algolia/Algoliasearch/Model/Observer.php
CHANGED
|
@@ -60,7 +60,15 @@ class Algolia_Algoliasearch_Model_Observer
|
|
| 60 |
if ( ! $store->getIsActive())
|
| 61 |
continue;
|
| 62 |
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
}
|
| 65 |
}
|
| 66 |
|
| 60 |
if ( ! $store->getIsActive())
|
| 61 |
continue;
|
| 62 |
|
| 63 |
+
try
|
| 64 |
+
{
|
| 65 |
+
$this->helper->rebuildStoreProductIndex($storeId, array($product_id));
|
| 66 |
+
}
|
| 67 |
+
catch(\Exception $e)
|
| 68 |
+
{
|
| 69 |
+
Mage::log($e->getMessage());
|
| 70 |
+
Mage::log($e->getTraceAsString());
|
| 71 |
+
}
|
| 72 |
}
|
| 73 |
}
|
| 74 |
|
app/code/community/Algolia/Algoliasearch/etc/system.xml
CHANGED
|
@@ -4,7 +4,7 @@
|
|
| 4 |
<algoliasearch translate="label" module="algoliasearch">
|
| 5 |
<label>
|
| 6 |
<