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

Invalid attribute name: main_table.store_id #939

Closed
vovayatsyuk opened this issue Apr 30, 2020 · 9 comments · Fixed by #951
Closed

Invalid attribute name: main_table.store_id #939

vovayatsyuk opened this issue Apr 30, 2020 · 9 comments · Fixed by #951

Comments

@vovayatsyuk
Copy link
Contributor

Looks like there is an incorrect method declared in Category/Collection:

public function addStoreFilter()
{
    $this->addFieldToFilter('main_table.store_id', $this->getStoreId());
    return $this;
}

When trying to use it:

echo Mage::getResourceModel('catalog/category_collection')
    ->addStoreFilter()
    ->getSize();

The following exception is thrown:

Invalid attribute name: main_table.store_id

Trace:
app/code/core/Mage/Eav/Model/Entity/Collection/Abstract.php(1295): Mage::exception('Mage_Eav', 'Invalid attribu...')
app/code/core/Mage/Eav/Model/Entity/Collection/Abstract.php(1388): Mage_Eav_Model_Entity_Collection_Abstract->_addAttributeJoin('main_table.stor...', 'inner')
app/code/core/Mage/Eav/Model/Entity/Collection/Abstract.php(322): Mage_Eav_Model_Entity_Collection_Abstract->_getAttributeConditionSql('main_table.stor...', 1, 'inner')
app/code/core/Mage/Eav/Model/Entity/Collection/Abstract.php(342): Mage_Eav_Model_Entity_Collection_Abstract->addAttributeToFilter('main_table.stor...', 1)
app/code/core/Mage/Catalog/Model/Resource/Category/Collection.php(384): Mage_Eav_Model_Entity_Collection_Abstract->addFieldToFilter('main_table.stor...', 1)
app/code/core/Mage/Cms/controllers/IndexController.php(45): Mage_Catalog_Model_Resource_Category_Collection->addStoreFilter()
app/code/core/Mage/Core/Controller/Varien/Action.php(418): Mage_Cms_IndexController->indexAction()
app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(254): Mage_Core_Controller_Varien_Action->dispatch('index')
app/code/core/Mage/Core/Controller/Varien/Front.php(174): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
app/code/core/Mage/Core/Model/App.php(381): Mage_Core_Controller_Varien_Front->dispatch()
app/Mage.php(737): Mage_Core_Model_App->run(Array)
index.php(78): Mage::run('', 'store')

Original Magento doesn't have this method in a regular category collection (Only in Flat collection).

@vovayatsyuk
Copy link
Contributor Author

This method was added to the collection in PR-884.

I'm not sure. Should it work somehow?

@vovayatsyuk
Copy link
Contributor Author

JFYI, an error was triggered with the following code: https://github.com/tmhub/easycatalogimg/blob/master/app/code/community/TM/EasyCatalogImg/Block/List.php#L116-L118

if (method_exists($collection, 'addStoreFilter')) {
    $collection->addStoreFilter();
}

@colinmollenhour
Copy link
Member

I think the problem is likely that the category collection class is different depending on if flat mode is currently enabled. Even if it is enabled it can be temporarily disabled automatically during indexing so you might see this problem come and go. So it probably needs some sort of "if" condition to run different code depending on if flat mode is in use or not.

@vovayatsyuk
Copy link
Contributor Author

What about the method itself? Is there any way to run it without error?

@colinmollenhour
Copy link
Member

Ahh, I see now.. The method should be fixed in #951. Can you give it a try?

@vovayatsyuk
Copy link
Contributor Author

Thank you! It helps.

@colinmollenhour
Copy link
Member

Merged. Thanks for testing!

@sreichel
Copy link
Contributor

sreichel commented Feb 4, 2025

@all-contributors add @vovayatsyuk bug

Copy link
Contributor

@sreichel

I've put up a pull request to add @vovayatsyuk! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants