public function testGetSetCustomerGroupId() { $this->assertEquals(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID, $this->_model->getCustomerGroupId()); $customerGroupId = 123; $this->_model->setCustomerGroupId($customerGroupId); $this->assertEquals($customerGroupId, $this->_model->getCustomerGroupId()); }
/** * Retrieve clean select with joined price index table * * @param Mage_Catalog_Model_Layer_Filter_Price $filter * @return Varien_Db_Select */ protected function _getSelect($filter) { $collection = $filter->getLayer()->getProductCollection(); $collection->addPriceData($filter->getCustomerGroupId(), $filter->getWebsiteId()); if (!is_null($collection->getCatalogPreparedSelect())) { $select = clone $collection->getCatalogPreparedSelect(); } else { $select = clone $collection->getSelect(); } // reset columns, order and limitation conditions $select->reset(Zend_Db_Select::COLUMNS); $select->reset(Zend_Db_Select::ORDER); $select->reset(Zend_Db_Select::LIMIT_COUNT); $select->reset(Zend_Db_Select::LIMIT_OFFSET); // remove join with main table $fromPart = $select->getPart(Zend_Db_Select::FROM); if (!isset($fromPart[Mage_Catalog_Model_Resource_Product_Collection::INDEX_TABLE_ALIAS]) || !isset($fromPart[Mage_Catalog_Model_Resource_Product_Collection::MAIN_TABLE_ALIAS])) { return $select; } // processing FROM part $priceIndexJoinPart = $fromPart[Mage_Catalog_Model_Resource_Product_Collection::INDEX_TABLE_ALIAS]; $priceIndexJoinConditions = explode('AND', $priceIndexJoinPart['joinCondition']); $priceIndexJoinPart['joinType'] = Zend_Db_Select::FROM; $priceIndexJoinPart['joinCondition'] = null; $fromPart[Mage_Catalog_Model_Resource_Product_Collection::MAIN_TABLE_ALIAS] = $priceIndexJoinPart; unset($fromPart[Mage_Catalog_Model_Resource_Product_Collection::INDEX_TABLE_ALIAS]); $select->setPart(Zend_Db_Select::FROM, $fromPart); foreach ($fromPart as $key => $fromJoinItem) { $fromPart[$key]['joinCondition'] = $this->_replaceTableAlias($fromJoinItem['joinCondition']); } $select->setPart(Zend_Db_Select::FROM, $fromPart); // processing WHERE part $wherePart = $select->getPart(Zend_Db_Select::WHERE); $excludedWherePart = Mage_Catalog_Model_Resource_Product_Collection::MAIN_TABLE_ALIAS . '.status'; foreach ($wherePart as $key => $wherePartItem) { if (strpos($wherePartItem, $excludedWherePart) !== false) { $wherePart[$key] = new Zend_Db_Expr('1=1'); continue; } $wherePart[$key] = $this->_replaceTableAlias($wherePartItem); } $select->setPart(Zend_Db_Select::WHERE, $wherePart); $excludeJoinPart = Mage_Catalog_Model_Resource_Product_Collection::MAIN_TABLE_ALIAS . '.entity_id'; foreach ($priceIndexJoinConditions as $condition) { if (strpos($condition, $excludeJoinPart) !== false) { continue; } $select->where($this->_replaceTableAlias($condition)); } $select->where($this->_getPriceExpression($filter, $select) . ' IS NOT NULL'); return $select; }
/** * Apply attribute filter to product collection * * @param Mage_Catalog_Model_Layer_Filter_Price $filter * @param int $range * @param int $index the range factor * @return Mage_Catalog_Model_Resource_Layer_Filter_Price */ public function applyFilterToCollection($filter, $range, $index) { $collection = $filter->getLayer()->getProductCollection(); $collection->addPriceData($filter->getCustomerGroupId(), $filter->getWebsiteId()); $select = $collection->getSelect(); $response = $this->_dispatchPreparePriceEvent($filter, $select); $table = $this->_getIndexTableAlias(); $additional = join('', $response->getAdditionalCalculations()); $rate = $filter->getCurrencyRate(); $priceExpr = new Zend_Db_Expr("(({$table}.min_price {$additional}) * {$rate})"); $filters = $filter->getPriceRangeCustom(); if ($filters) { $select->where($priceExpr . ' >= ?', (int) $filters[0])->where($priceExpr . ' < ?', (int) $filters[1]); } else { $select->where($priceExpr . ' >= ?', $range * ($index - 1))->where($priceExpr . ' < ?', $range * $index); } return $this; }
/** * Prepare filter apply * * @param Mage_Catalog_Model_Layer_Filter_Price $filter * @return array */ protected function _prepareApply($filter) { $collection = $filter->getLayer()->getProductCollection(); $collection->addPriceData($filter->getCustomerGroupId(), $filter->getWebsiteId()); $select = $collection->getSelect(); $response = $this->_dispatchPreparePriceEvent($filter, $select); $table = $this->_getIndexTableAlias(); $additional = join('', $response->getAdditionalCalculations()); $rate = $filter->getCurrencyRate(); $priceExpr = new Zend_Db_Expr("(({$table}.min_price {$additional}) * {$rate})"); return array($select, $priceExpr); }