/**
  * Add tax class id attribute to select and join price rules data if needed
  *
  * @return Mage_Catalog_Model_Resource_Product_Collection
  */
 protected function _beforeLoad()
 {
     if (isset($this->_productLimitationFilters['category_id']) && is_array($this->_productLimitationFilters['category_id'])) {
         $this->getSelect()->group('e.entity_id');
     }
     return parent::_beforeLoad();
 }
Beispiel #2
0
 /**
  * Redeclare parent method for store filters applying
  *
  * @return Mage_Review_Model_Resource_Review_Product_Collection
  */
 protected function _beforeLoad()
 {
     parent::_beforeLoad();
     $this->_applyStoresFilterToSelect();
     return $this;
 }
 /**
  * Handles collection filtering by ids retrieves from search engine.
  * Will also stores faceted data and total records.
  *
  * @return Mage_Catalog_Model_Resource_Product_Collection
  */
 protected function _beforeLoad()
 {
     $this->_prepareQuery();
     $ids = array();
     if (!empty($this->_facets)) {
         $this->getSearchEngineQuery()->resetFacets();
     }
     $result = $this->getSearchEngineQuery()->search();
     $ids = isset($result['ids']) ? $result['ids'] : array();
     if (isset($result['facets'])) {
         $this->_facets = array_merge($this->_facets, $result['facets']);
     }
     $this->_totalRecords = isset($result['total_count']) ? $result['total_count'] : null;
     $this->_isSpellChecked = $this->getSearchEngineQuery()->isSpellchecked();
     if (empty($ids)) {
         $ids = array(0);
         // Fix for no result
     }
     $this->addIdFilter($ids);
     $this->_searchedEntityIds = $ids;
     $this->_pageSize = false;
     return parent::_beforeLoad();
 }
 /**
  * Join linked products when specified link model
  *
  * @return Mage_Catalog_Model_Resource_Product_Link_Product_Collection
  */
 protected function _beforeLoad()
 {
     if ($this->getLinkModel()) {
         $this->_joinLinks();
     }
     return parent::_beforeLoad();
 }
Beispiel #5
0
 /**
  * Search documents by query
  * Set found ids and number of found results
  *
  * @return Enterprise_Search_Model_Resource_Collection
  */
 protected function _beforeLoad()
 {
     $ids = array();
     if ($this->_engine) {
         list($query, $params) = $this->_prepareBaseParams();
         if ($this->_sortBy) {
             $params['sort_by'] = $this->_sortBy;
         }
         if ($this->_pageSize !== false) {
             $page = $this->_curPage > 0 ? (int) $this->_curPage : 1;
             $rowCount = $this->_pageSize > 0 ? (int) $this->_pageSize : 1;
             $params['offset'] = $rowCount * ($page - 1);
             $params['limit'] = $rowCount;
         }
         $needToLoadFacetedData = !$this->_facetedDataIsLoaded && !empty($this->_facetedConditions);
         if ($needToLoadFacetedData) {
             $params['solr_params']['facet'] = 'on';
             $params['facet'] = $this->_facetedConditions;
         }
         $result = $this->_engine->getIdsByQuery($query, $params);
         $ids = (array) $result['ids'];
         if ($needToLoadFacetedData) {
             $this->_facetedData = $result['faceted_data'];
             $this->_facetedDataIsLoaded = true;
         }
     }
     $this->_searchedEntityIds =& $ids;
     $this->getSelect()->where('e.entity_id IN (?)', $this->_searchedEntityIds);
     /**
      * To prevent limitations to the collection, because of new data logic.
      * On load collection will be limited by _pageSize and appropriate offset,
      * but third party search engine retrieves already limited ids set
      */
     $this->_storedPageSize = $this->_pageSize;
     $this->_pageSize = false;
     return parent::_beforeLoad();
 }
Beispiel #6
0
 /**
  * Handles collection filtering by ids retrieves from search engine.
  * Will also stores faceted data and total records.
  *
  * @return Mage_Catalog_Model_Resource_Product_Collection
  */
 protected function _beforeLoad()
 {
     $ids = array();
     if ($this->_engine) {
         $result = $this->_engine->getIdsByQuery($this->_getQuery(), $this->_getParams());
         $ids = isset($result['ids']) ? $result['ids'] : array();
         $this->_facetedData = isset($result['faceted_data']) ? $result['faceted_data'] : array();
         $this->_totalRecords = isset($result['total_count']) ? $result['total_count'] : null;
     }
     if (empty($ids)) {
         $ids = array(0);
         // Fix for no result
     }
     $this->addIdFilter($ids);
     $this->_searchedEntityIds = $ids;
     $this->_pageSize = false;
     return parent::_beforeLoad();
 }
Beispiel #7
0
 /**
  * Apply MongoDB filtering before loading the collection
  *
  * @return Smile_MongoCore_Model_Resource_Override_Catalog_Product_Collection Self reference
  */
 protected function _beforeLoad()
 {
     parent::_beforeLoad();
     $documentFilter = array();
     foreach ($this->_documentFilters as $attribute => $filter) {
         $filter = $this->_buildDocumentFilter($attribute, $filter);
         if (!is_null($filter)) {
             $documentFilter[] = $filter;
         }
     }
     if (!empty($documentFilter)) {
         $productIds = null;
         if ($this->_hasSqlFilter !== false) {
             $productIds = $this->getAllIds();
         }
         $documentIds = array();
         if (!is_null($productIds) && !empty($productIds)) {
             $documentFilter = array('$and' => array($this->getResource()->getIdsFilter($productIds), array('$and' => $documentFilter)));
         } else {
             $documentFilter = array('$and' => array_values($documentFilter));
         }
         $storeFilter = array_unique(array('attr_' . $this->getDefaultStoreId(), 'attr_' . $this->getStoreId()));
         $cursor = $this->_getDocumentCollection()->find($documentFilter, $storeFilter)->limit($this->getPageSize());
         while ($cursor->hasNext()) {
             $document = $cursor->getNext();
             $documentIds[] = $document['_id'];
         }
         $this->getSelect()->where('e.entity_id IN(?)', $documentIds);
     }
 }
 /**
  * @return Mage_Catalog_Model_Resource_Product_Collection|void
  */
 protected function _beforeLoad()
 {
     $query = $this->_getQuery();
     $fQuery = $this->_getFQuery($query);
     $result = $this->_engine->search($fQuery);
     $ids = $this->_getResultIds($result);
     $this->getSelect()->where('e.entity_id IN (?)', $ids);
     $this->_storedPageSize = $this->_pageSize;
     $this->_pageSize = false;
     return parent::_beforeLoad();
 }
Beispiel #9
0
 /**
  * Filters collection by id.
  * Will also stores faceted data and total records.
  *
  * @return Mage_Catalog_Model_Resource_Product_Collection
  */
 protected function _beforeLoad()
 {
     if (Mage::helper('nanowebg_elasticsearch')->isLog()) {
         Mage::log('NanoWebG_ElasticSearch_Model_Resource_Catalog_Product_Collection _beforeLoad', null, 'elasticsearch_debug.log');
     }
     $ids = $this->getSearchResultIds();
     if (empty($ids)) {
         $ids = array(0);
         // Fix for no result
     }
     $page_ids = array();
     $params = $this->_getParams();
     $limit = (int) $params['limit'] ? (int) $params['limit'] : count($ids);
     $offset = (int) $params['offset'] ? (int) $params['offset'] : 0;
     // $max_offset = floor(count($ids)/$limit);
     $max = $offset + $limit;
     $max = $max > count($ids) ? count($ids) : $max;
     $offset = $offset + $limit > $max ? (int) floor($max / $limit) * $limit : $offset;
     foreach ($ids as $key => $value) {
         if ($key < $offset) {
             continue;
         }
         if ($key > $max) {
             break;
         }
         if ($key >= $offset && $key < $max) {
             $page_ids[] = $value;
         }
     }
     $this->addIdFilter($page_ids);
     $this->_entityIds = $page_ids;
     $this->_pageSize = false;
     Mage::dispatchEvent('nanowebg_elasticsearch_product_collection_before', array('collection' => $this));
     return parent::_beforeLoad();
 }
Beispiel #10
0
 /**
  * Search documents by query
  * Set found ids and number of found results
  *
  * @return Celebros_Conversionpro_Model_Resource_Collection
  */
 protected function _beforeLoad()
 {
     $ids = array();
     if ($this->_engine) {
         list($query, $params) = $this->_prepareBaseParams();
         if ($this->_sortBy) {
             $params['sort_by'] = $this->_sortBy;
         }
         if ($this->_pageSize !== false) {
             $page = $this->_curPage > 0 ? (int) $this->_curPage : 1;
             $rowCount = $this->_pageSize > 0 ? (int) $this->_pageSize : 1;
             $params['offset'] = $rowCount * ($page - 1);
             $params['limit'] = $rowCount;
         }
         $result = $this->_engine->getIdsByQuery($query, $params);
         $ids = (array) $result['ids'];
         $this->_facetedData = array();
     }
     $this->_searchedEntityIds =& $ids;
     $this->getSelect()->where('e.entity_id IN (?)', $this->_searchedEntityIds);
     $this->_totalRecords = $this->_engine->getLastNumFound();
     //In case Quiser tells us to, we should cancel conversionpro and re-run the search.
     //Right now this feature isn't in use, but we're leaving it here just in case.
     if (false) {
         $status = Mage::getSingleton('conversionpro/session')->getConversionproDisabler();
         //This prevents the redirect from looping forever. We'll only redirect in case we haven't already enabled the disabler.
         if (!isset($status) || !$status) {
             Mage::helper('conversionpro')->enableConversionproDisabler();
             Mage::app()->getResponse()->setRedirect(Mage::helper('core/url')->getCurrentUrl());
         }
     }
     //Handle the case of a single search result (only when not in an ajax request).
     if ($this->_totalRecords == 1 && Mage::getStoreConfig('conversionpro/display_settings/go_to_product_on_one_result') && !Mage::app()->getRequest()->isXmlHttpRequest()) {
         $searchResults = Mage::helper('conversionpro')->getSearchResults();
         Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getModel('catalog/product')->load($ids[0])->getProductUrl());
     }
     /**
      * To prevent limitations to the collection, because of new data logic.
      * On load collection will be limited by _pageSize and appropriate offset,
      * but third party search engine retrieves already limited ids set
      */
     $this->_storedPageSize = $this->_pageSize;
     $this->_pageSize = false;
     return parent::_beforeLoad();
 }