Example #1
0
 /**
  * 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;
     }
 }
Example #2
0
 /**
  * Prepare product collection
  *
  * @param Mage_CatalogSearch_Model_Resource_Advanced_Collection $collection
  * @return Mage_Catalog_Model_Layer
  */
 public function prepareProductCollection($collection)
 {
     $collection->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())->setStore(Mage::app()->getStore())->addMinimalPrice()->addTaxPercents()->addStoreFilter();
     Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
     Mage::getSingleton('catalog/product_visibility')->addVisibleInSearchFilterToCollection($collection);
     return $this;
 }
 /**
  * Add filter by indexable attribute
  *
  * @param Mage_CatalogSearch_Model_Resource_Advanced_Collection $collection
  * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute
  * @param string|array $value
  * @return bool
  */
 public function addIndexableAttributeModifiedFilter($collection, $attribute, $value)
 {
     if ($attribute->getIndexType() == 'decimal') {
         $table = $this->getTable('catalog/product_index_eav_decimal');
     } else {
         $table = $this->getTable('catalog/product_index_eav');
     }
     $tableAlias = 'a_' . $attribute->getAttributeId();
     $storeId = Mage::app()->getStore()->getId();
     $select = $collection->getSelect();
     if (is_array($value)) {
         if (isset($value['from']) && isset($value['to'])) {
             if (empty($value['from']) && empty($value['to'])) {
                 return false;
             }
         }
     }
     $select->distinct(true);
     $select->join(array($tableAlias => $table), "e.entity_id={$tableAlias}.entity_id " . " AND {$tableAlias}.attribute_id={$attribute->getAttributeId()}" . " AND {$tableAlias}.store_id={$storeId}", array());
     if (is_array($value) && (isset($value['from']) || isset($value['to']))) {
         if (isset($value['from']) && !empty($value['from'])) {
             $select->where("{$tableAlias}.value >= ?", $value['from']);
         }
         if (isset($value['to']) && !empty($value['to'])) {
             $select->where("{$tableAlias}.value <= ?", $value['to']);
         }
         return true;
     }
     $select->where("{$tableAlias}.value IN(?)", $value);
     return true;
 }
 /**
  * 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();
     $result = $this->getSearchEngineQuery()->search();
     $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;
     $this->_isSpellChecked = isset($result['is_spellchecked']) ? $result['is_spellchecked'] : false;
     if (empty($ids)) {
         $ids = array(0);
         // Fix for no result
     }
     $this->addIdFilter($ids);
     $this->_searchedEntityIds = $ids;
     $this->_pageSize = false;
     return parent::_beforeLoad();
 }
Example #5
0
 /**
  * Prepare product collection
  *
  * @param Mage_CatalogSearch_Model_Resource_Advanced_Collection $collection
  * @return Mage_Catalog_Model_Layer
  */
 public function prepareProductCollection($collection)
 {
     $collection->addAttributeToSelect(Mage::getSingleton('Mage_Catalog_Model_Config')->getProductAttributes())->setStore(Mage::app()->getStore())->addMinimalPrice()->addTaxPercents()->addStoreFilter()->setVisibility(Mage::getSingleton('Mage_Catalog_Model_Product_Visibility')->getVisibleInSearchIds());
     return $this;
 }
Example #6
0
 /**
  * Retrieve collection last page number
  *
  * @return int
  */
 public function getLastPageNumberParent()
 {
     return parent::getLastPageNumber();
 }
Example #7
0
 /**
  * Add filter by indexable attribute
  *
  * @param Mage_CatalogSearch_Model_Resource_Advanced_Collection $collection
  * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute
  * @param string|array $value
  * @return bool
  */
 public function addCustomIndexableAttributeModifiedFilter($collection, $attribute, $value)
 {
     if ($attribute->getIndexType() == 'decimal') {
         $table = $this->getTable('catalog/product_index_eav_decimal');
     } else {
         $table = $this->getTable('catalog/product_entity_int');
     }
     $tableAlias = 'a_' . $attribute->getAttributeId();
     $storeId = Mage::app()->getStore()->getId();
     $select = $collection->getSelect();
     if (is_array($value)) {
         if (isset($value['from']) && isset($value['to'])) {
             if (empty($value['from']) && empty($value['to'])) {
                 return false;
             }
         }
     }
     // $select->distinct(true);
     $select->join(array($tableAlias => $table), "cp.child_id={$tableAlias}.entity_id " . " AND {$tableAlias}.attribute_id={$attribute->getAttributeId()}" . " AND {$tableAlias}.store_id={$storeId}", array());
     /*$select->joinLeft(
           array( 'catalog_product_entity_int'),
           "catalog_product_entity_int.attribute_id={$attribute->getAttributeId()} ",
           array()
       );
       $select->join(
           array( 'catalog_product_bundle_selection'),
           "catalog_product_entity_int.entity_id=catalog_product_bundle_selection.product_id "
               . " AND e.entity_id=catalog_product_bundle_selection.parent_product_id",
           array("other_product_id"=>"catalog_product_bundle_selection.product_id")
       ); */
     if (is_array($value) && (isset($value['from']) || isset($value['to']))) {
         if (isset($value['from']) && !empty($value['from'])) {
             $select->where("{$tableAlias}.value >= ?", $value['from']);
         }
         if (isset($value['to']) && !empty($value['to'])) {
             $select->where("{$tableAlias}.value <= ?", $value['to']);
         }
         return true;
     }
     $select->where("{$tableAlias}.value", $value);
     return true;
 }