magento showing wrong product count in category

前端 未结 3 803
甜味超标
甜味超标 2021-01-02 04:32

I have a strange issue and seems many are having the same on internet. Below picture will define my issue and also my magento version is 1.7

3条回答
  •  一个人的身影
    2021-01-02 05:31

    Hi product count comes from method name loadProductCount which is located at location code/core/Mage/Catalog/Model/Resource/Category/Collection.php

    If you will dig in deep this count is coming from a join query between two tables: catalog_category_product and catalog_category_entity

    I have fixed this issue by using event observer. you can do the same for time being. And let me know if you find any better solution.

    public function deleteCountCategory (Varien_Event_Observer $observer) {
        try {
        $product = $observer->getEvent()->getProduct();
        $productId = $product->getId();                     
        $resource = Mage::getSingleton('core/resource');    
        $writeConnection = $resource->getConnection('core_write');
        $tableName = $resource->getTableName('catalog_category_product');
        $query = "DELETE FROM {$tableName} WHERE product_id = ".(int)$productId;            
        $writeConnection->query($query);            
        } catch (Exception $e) {
            throw $e;                   
        }
        return $this;           
    }   
    

    Event used in config.xml

    
     
    
     
    model 
    countfix/observer 
    deleteCountCategory  
     
    
    
    
    
    

提交回复
热议问题