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

Refactor Mage_Rating_Model_Resource_Rating_Collection #292

Closed
ihor-sviziev opened this issue May 6, 2013 · 1 comment
Closed

Refactor Mage_Rating_Model_Resource_Rating_Collection #292

ihor-sviziev opened this issue May 6, 2013 · 1 comment

Comments

@ihor-sviziev
Copy link
Contributor

Class Mage_Rating_Model_Resource_Rating_Collection has method addStoresToCollection, that has code like this:

if (!$this->_isCollectionLoaded) {
    return $this;
}

I think it need be refactored like in Mage_Review_Model_Resource_Review_Collection::addStoreData:

public function addStoreData()
{
    $this->_addStoreDataFlag = true;
    return $this;
}

and Mage_Review_Model_Resource_Review_Collection::_addStoreDataFlag:

protected function _addStoreData()
{
    $adapter = $this->getConnection();

    $reviewsIds = $this->getColumnValues('review_id');
    $storesToReviews = array();
    if (count($reviewsIds)>0) {
        $inCond = $adapter->prepareSqlCondition('review_id', array('in' => $reviewsIds));
        $select = $adapter->select()
            ->from($this->_reviewStoreTable)
            ->where($inCond);
        $result = $adapter->fetchAll($select);
        foreach ($result as $row) {
            if (!isset($storesToReviews[$row['review_id']])) {
                $storesToReviews[$row['review_id']] = array();
            }
            $storesToReviews[$row['review_id']][] = $row['store_id'];
        }
    }

    foreach ($this as $item) {
        if (isset($storesToReviews[$item->getId()])) {
            $item->setStores($storesToReviews[$item->getId()]);
        } else {
            $item->setStores(array());
        }
    }
}

In load():

if ($this->_addStoreDataFlag) {
    $this->_addStoreData();
}
@ihor-sviziev
Copy link
Contributor Author

The code is available in the version dev56 recently released.

magento-team pushed a commit that referenced this issue May 15, 2015
magento-team pushed a commit that referenced this issue Jan 14, 2016
[Ogres] Bug fixes and vendor dir part 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant