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

How to reindex catalog_category_product_index for single entity? #4304

Open
Tomasz-Silpion opened this issue Oct 24, 2024 · 0 comments
Open

Comments

@Tomasz-Silpion
Copy link
Contributor

Summary (*)

There are a lot references in code to catalog_category_product_index action like catalogProductSave or catalogProductMassAction which seem to be obsolete as they are no longer called anywhere https://github.com/OpenMage/magento-lts/blob/main/app/code/core/Mage/Catalog/Model/Resource/Category/Indexer/Product.php or in https://github.com/OpenMage/magento-lts/blob/main/app/code/core/Mage/Catalog/Model/Resource/Product.php#L300 refreshIndex method.

Possibly, both of them can be marked as deprecated as Mage_Catalog_Model_Resource_Category_Indexer_Product _refreshRootRelations ends with FK_CAT_CTGR_PRD_IDX_CTGR_ID_CAT_CTGR_ENTT_ENTT_ID exception due try to insert category_id 0 as given in fresh installed core_store_group.store_id join and the Mage_Catalog_Model_Resource_Product refreshIndex function breaks on non existing $categoryObject->refreshProductIndex($indexCategoryIds, $indexProductIds); call.

Examples (*)

Call

Mage::getResourceModel('catalog/category_indexer_product')->catalogProductMassAction($event);

SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`catalog_category_product_index`, CONSTRAINT `FK_CAT_CTGR_PRD_IDX_CTGR_ID_CAT_CTGR_ENTT_ENTT_ID` FOREIGN KEY (`category_id`)

or

Mage::getResourceModel('catalog/product')->refreshIndex($product);

Call to undefined method Mage_Catalog_Model_Resource_Category::refreshProductIndex()

Proposed solution

  1. refreshProductIndex method should be added to Mage_Catalog_Model_Resource_Category class
  2. Entire method, second half or at least insertFromSelect method should be removed from https://github.com/OpenMage/magento-lts/blob/main/app/code/core/Mage/Catalog/Model/Resource/Category/Indexer/Product.php#L739 _refreshRootRelations function.
  3. Both catalogProductMassAction and refreshIndex should be marked as deprecated.
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