/** * Intercept query. */ public function addSearchFilter($query) { /** @var Algolia_Algoliasearch_Helper_Config $config */ $config = Mage::helper('algoliasearch/config'); $storeId = Mage::app()->getStore()->getId(); if (!$config->getApplicationID() || !$config->getAPIKey() || $config->isEnabledFrontEnd($storeId) === false) { return parent::addSearchFilter($query); } $data = array(); if ($config->isInstantEnabled($storeId) === false || $config->makeSeoRequest($storeId)) { $algolia_query = $query !== '__empty__' ? $query : ''; try { /** @var Algolia_Algoliasearch_Helper_Data $helper */ $helper = Mage::helper('algoliasearch'); $data = $helper->getSearchResult($algolia_query, $storeId); } catch (\Exception $e) { /** @var Algolia_Algoliasearch_Helper_Logger $logger */ $logger = Mage::helper('algoliasearch/logger'); $logger->log($e->getMessage(), true); $logger->log($e->getTraceAsString(), true); return parent::addSearchFilter($query); } } $sortedIds = array_reverse(array_keys($data)); $this->getSelect()->columns(array('relevance' => new Zend_Db_Expr("FIND_IN_SET(e.entity_id, '" . implode(',', $sortedIds) . "')"))); $this->getSelect()->where('e.entity_id IN (?)', $sortedIds); return $this; }
/** * Add the groupscatalog filter to the select object so the number of search * results on the pager is correct. * * @return Varien_Db_Select */ public function getSelectCountSql() { $select = parent::getSelectCountSql(); if (Mage::helper('netzarbeiter_groupscatalog2')->isModuleActive()) { $customerGroupId = Mage::helper('netzarbeiter_groupscatalog2')->getCustomerGroupId(); Mage::getResourceSingleton('netzarbeiter_groupscatalog2/filter')->addGroupsCatalogFilterToSelectCountSql($select, $customerGroupId, $this->getStoreId()); } return $select; }
/** * Retrieve loaded category collection * * @return Mage_CatalogSearch_Model_Resource_Fulltext_Collection */ protected function _getProductCollection() { if (is_null($this->_productCollection)) { $this->_productCollection = $this->getListBlock()->getLoadedProductCollection(); } $this->_productCollection->addAttributeToFilter('attribute_set_id', 25); $this->_productCollection->addAttributeToFilter('type_id', 'ofertefurnizori'); //Zend_Debug::dump($this->_productCollection->getData()); return $this->_productCollection; }
/** * Retrieve loaded category collection * * @return Mage_CatalogSearch_Model_Resource_Fulltext_Collection */ protected function _getProductCollection() { if (is_null($this->_productCollection)) { $this->_productCollection = $this->getListBlock()->getLoadedProductCollection(); $userid = Mage::getSingleton('customer/session')->getId(); $user_id = $userid ? $userid : 0; $this->_productCollection1 = $this->_productCollection->addAttributeToFilter('customer_id', $user_id); } return $this->_productCollection1; }
/** * Retrieve collection last page number * * @return int */ public function getLastPageNumber() { if (!Mage::helper('searchanise/ApiSe')->checkSearchaniseResult(true)) { return parent::getLastPageNumber(); } if (!$this->checkSearchaniseResult()) { return parent::getLastPageNumber(); } $collectionSize = (int) $this->getSearchaniseRequest()->getTotalProduct(); if (0 === $collectionSize) { return 1; } elseif ($this->_pageSize) { return ceil($collectionSize / $this->_pageSize); } else { return 1; } }
/** * Intercept query */ public function addSearchFilter($query) { $config = Mage::helper('algoliasearch/config'); $storeId = Mage::app()->getStore()->getId(); if (!$config->getApplicationID() || !$config->getAPIKey() || $config->isEnabledFrontEnd($storeId) === false) { return parent::addSearchFilter($query); } $data = array(); if ($config->isInstantEnabled($storeId) === false || $config->makeSeoRequest($storeId)) { $algolia_query = $query !== '__empty__' ? $query : ''; $data = Mage::helper('algoliasearch')->getSearchResult($algolia_query, $storeId); } $sortedIds = array_reverse(array_keys($data)); $this->getSelect()->columns(array('relevance' => new Zend_Db_Expr("FIND_IN_SET(e.entity_id, '" . implode(',', $sortedIds) . "')"))); $this->getSelect()->where('e.entity_id IN (?)', $sortedIds); return $this; }
/** * Add search query filter without preparing result since result table causes lots of lock contention. * * @param string $query * @throws Exception * @return Mage_CatalogSearch_Model_Resource_Fulltext_Collection */ public function addSearchFilter($query) { if (!Mage::helper('algoliasearch')->isEnabled() || Mage::helper('algoliasearch')->useResultCache()) { return parent::addSearchFilter($query); } // This method of filtering the product collection by the search result does not use the catalogsearch_result table try { $data = Mage::helper('algoliasearch')->getSearchResult($query, Mage::app()->getStore()->getId()); } catch (Exception $e) { Mage::getSingleton('catalog/session')->addError(Mage::helper('algoliasearch')->__('Search failed. Please try again.')); $this->getSelect()->columns(['relevance' => new Zend_Db_Expr("e.entity_id")]); $this->getSelect()->where('e.entity_id = 0'); return $this; } $sortedIds = array_reverse(array_keys($data)); $this->getSelect()->columns(['relevance' => new Zend_Db_Expr("FIND_IN_SET(e.entity_id, '" . implode(',', $sortedIds) . "')")]); $this->getSelect()->where('e.entity_id IN (?)', $sortedIds); return $this; }
/** * Retrieve collection last page number * * @return int */ public function getLastPageNumberParent() { return parent::getLastPageNumber(); }