Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for issue #292 #299

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 68 additions & 18 deletions app/code/Mage/Rating/Model/Resource/Rating/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ class Mage_Rating_Model_Resource_Rating_Collection extends Mage_Core_Model_Resou
*/
protected $_app;

/**
* Add store data flag
* @var bool
*/
protected $_addStoreDataFlag = false;

/**
* Collection constructor
*
Expand Down Expand Up @@ -99,7 +105,7 @@ public function addEntityFilter($entity)
}

/**
* set order by position field
* Set order by position field
*
* @param string $dir
* @return Mage_Rating_Model_Resource_Rating_Collection
Expand All @@ -113,7 +119,7 @@ public function setPositionOrder($dir='ASC')
/**
* Set store filter
*
* @param int_type $storeId
* @param int $storeId
* @return Mage_Rating_Model_Resource_Rating_Collection
*/
public function setStoreFilter($storeId)
Expand Down Expand Up @@ -252,19 +258,74 @@ public function addRatingPerStoreName($storeId)
return $this;
}

/**
* Add stores data to collection
*
* @return Mage_Rating_Model_Resource_Rating_Collection
*/
public function addStoreData() {
if (!$this->_app->isSingleStoreMode()) {
if (!$this->_isCollectionLoaded) {
$this->_addStoreDataFlag = true;
} elseif (!$this->_addStoreDataFlag) {
$this->_addStoreData();
}
}

return $this;
}

/**
* Add stores to collection
*
* @todo mate method deprecated
*
* @return Mage_Rating_Model_Resource_Rating_Collection
*/
public function addStoresToCollection()
{
if ($this->_app->isSingleStoreMode()) {
return $this->addStoreData();
}

/**
* Set Active Filter
*
* @param bool $isActive
* @return Mage_Rating_Model_Resource_Rating_Collection
*/
public function setActiveFilter($isActive = true)
{
$this->getSelect()->where('main_table.is_active=?', $isActive);
return $this;
}

/**
* Load data
*
* @param boolean $printQuery
* @param boolean $logQuery
* @return Mage_Review_Model_Resource_Review_Collection
*/
public function load($printQuery = false, $logQuery = false)
{
if ($this->isLoaded()) {
return $this;
}
if (!$this->_isCollectionLoaded) {
return $this;
Mage::dispatchEvent('rating_rating_collection_load_before', array('collection' => $this));
parent::load($printQuery, $logQuery);
if ($this->_addStoreDataFlag) {
$this->_addStoreData();
}
return $this;
}

/**
* Add store data
*
* @return Mage_Review_Model_Resource_Review_Collection
*/
protected function _addStoreData()
{
$ratingIds = array();
foreach ($this as $item) {
$ratingIds[] = $item->getId();
Expand All @@ -275,14 +336,14 @@ public function addStoresToCollection()
}
$adapter = $this->getConnection();

$inCond = $adapter->prepareSqlCondition('rating_id', array(
$inCondition = $adapter->prepareSqlCondition('rating_id', array(
'in' => $ratingIds
));

$this->_select = $adapter
->select()
->from($this->getTable('rating_store'))
->where($inCond);
->where($inCondition);

$data = $adapter->fetchAll($this->_select);
if (is_array($data) && count($data) > 0) {
Expand All @@ -291,18 +352,7 @@ public function addStoresToCollection()
$item->setStores(array_merge($item->getStores(), array($row['store_id'])));
}
}
return $this;
}

/**
* Set Active Filter
*
* @param bool $isActive
* @return Mage_Rating_Model_Resource_Rating_Collection
*/
public function setActiveFilter($isActive = true)
{
$this->getSelect()->where('main_table.is_active=?', $isActive);
return $this;
}
}