Vinai / groupscatalog2

Magento extension to enable you to hide categories and products from customers depending on their customer group. This is a Magento 1.6 and newer compatible version of the Netzarbeiter Customer Groups Catalog extension.
139 stars 60 forks source link

Can't rewrite GroupsCatalog products indexes #15

Closed nrunde closed 11 years ago

nrunde commented 12 years ago

The following exception is thrown:

 Integrity constraint violation: 1062 Duplicate entry '64541-14-1' for key 'IDX_GROUPSCATALOG_PRODUCT_IDX_ENTITY_ID_GROUP_ID_STORE_ID' 

I think it's nearly the same problem like the one with categories you fixed yesterday.

Vinai commented 11 years ago

Thank you for the report! This must be a different issue since the issue you mention is fixed in the Abstract GroupsCatalog2 Indexer class, so the fix applies to categories and products alike. Can you please post a full stack trace of the exception?

nrunde commented 11 years ago
2012-10-22T08:01:12+00:00 DEBUG (7): Exception message: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '64554-13-1' for key 'IDX_GROUPSCATALOG_PRODUCT_IDX_ENTITY_ID_GROUP_ID_STORE_ID'
Trace: #0 /srv/www/vhosts/domain.de/www/lib/Varien/Db/Statement/Pdo/Mysql.php(110): Zend_Db_Statement_Pdo->_execute(Array)
#1 /srv/www/vhosts/domain.de/www/lib/Zend/Db/Statement.php(300): Varien_Db_Statement_Pdo_Mysql->_execute(Array)
#2 /srv/www/vhosts/domain.de/www/lib/Zend/Db/Adapter/Abstract.php(479): Zend_Db_Statement->execute(Array)
#3 /srv/www/vhosts/domain.de/www/lib/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('INSERT INTO `gr...', Array)
#4 /srv/www/vhosts/domain.de/www/lib/Varien/Db/Adapter/Pdo/Mysql.php(389): Zend_Db_Adapter_Pdo_Abstract->query('INSERT INTO `gr...', Array)
#5 /srv/www/vhosts/domain.de/www/lib/Varien/Db/Adapter/Pdo/Mysql.php(1953): Varien_Db_Adapter_Pdo_Mysql->query('INSERT INTO `gr...', Array)
#6 /srv/www/vhosts/domain.de/www/lib/Varien/Db/Adapter/Pdo/Mysql.php(1926): Varien_Db_Adapter_Pdo_Mysql->insertArray('groupscatalog_p...', Array, Array)
#7 /srv/www/vhosts/domain.de/www/app/code/community/Netzarbeiter/GroupsCatalog2/Model/Resource/Indexer/Abstract.php(260): Varien_Db_Adapter_Pdo_Mysql->insertMultiple('groupscatalog_p...', Array)
#8 /srv/www/vhosts/domain.de/www/app/code/community/Netzarbeiter/GroupsCatalog2/Model/Resource/Indexer/Abstract.php(187): Netzarbeiter_GroupsCatalog2_Model_Resource_Indexer_Abstract->_insertIndexRecords(Array)
#9 /srv/www/vhosts/domain.de/www/app/code/community/Netzarbeiter/GroupsCatalog2/Model/Resource/Indexer/Abstract.php(150): Netzarbeiter_GroupsCatalog2_Model_Resource_Indexer_Abstract->_reindexEntity()
#10 /srv/www/vhosts/domain.de/www/app/code/core/Mage/Index/Model/Indexer/Abstract.php(143): Netzarbeiter_GroupsCatalog2_Model_Resource_Indexer_Abstract->reindexAll()
#11 /srv/www/vhosts/domain.de/www/app/code/core/Mage/Index/Model/Process.php(207): Mage_Index_Model_Indexer_Abstract->reindexAll()
#12 /srv/www/vhosts/domain.de/www/app/code/core/Mage/Index/Model/Process.php(253): Mage_Index_Model_Process->reindexAll()
#13 /srv/www/vhosts/domain.de/www/app/code/core/Mage/Index/controllers/Adminhtml/ProcessController.php(124): Mage_Index_Model_Process->reindexEverything()
#14 /srv/www/vhosts/domain.de/www/app/code/core/Mage/Core/Controller/Varien/Action.php(420): Mage_Index_Adminhtml_ProcessController->reindexProcessAction()
#15 /srv/www/vhosts/domain.de/www/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(250): Mage_Core_Controller_Varien_Action->dispatch('reindexProcess')
#16 /srv/www/vhosts/domain.de/www/app/code/core/Mage/Core/Controller/Varien/Front.php(176): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#17 /srv/www/vhosts/domain.de/www/app/code/core/Mage/Core/Model/App.php(349): Mage_Core_Controller_Varien_Front->dispatch()
#18 /srv/www/vhosts/domain.de/www/app/Mage.php(640): Mage_Core_Model_App->run(Array)
#19 /srv/www/vhosts/domain.de/www/index.php(80): Mage::run('', 'store')
#20 {main}
Vinai commented 11 years ago

Does the exception only occur when you rebuild the whole GroupsCatalog2 products index, or does it also happen when you edit and save the product with the ID 64554 individually?

Vinai commented 11 years ago

Also, can you please give me the output of the SQL query

SELECT `e`.`entity_id`, `a`.`value` AS `group_ids`, `a`.`store_id`
    FROM `catalog_product_entity` AS `e`
    LEFT JOIN `eav_attribute` AS `eav`
        ON `eav`.`entity_type_id`=`e`.`entity_type_id` 
        AND `eav`.`attribute_code`='groupscatalog2_groups'
    LEFT JOIN `catalog_product_entity_text` AS `a`
        ON `e`.`entity_id`=`a`.`entity_id`
        AND `a`.`attribute_id`=`eav`.`attribute_id`
    WHERE (`e`.`entity_id` IN ('64554')) ORDER BY `e`.`entity_id` ASC, `a`.`store_id` ASC;
nrunde commented 11 years ago

If I edit the product itself there isn't a failure, but there's only the possibility to chose the customer groups once. In the products grid you can see one or more customer group is associated twice or more to some products. We ran a import script to get the products into database. But I don't get any multiple associated customer groups in my import dump, it always looks fine so far. After every import there are different products with this problem. Sometimes only one, sometimes more than fifty products.

Vinai commented 11 years ago

Thanks for the additional info. I just pushed a commit that should take care of the problem. https://github.com/Vinai/groupscatalog2/commit/562fde2c3bc7ced19affef454aeae87fb745efd7

Please let me know if that fixes the issue for you. Thanks!

nrunde commented 11 years ago

After implementing your fix rebuilding indexes works. Thank you very much!