magento 在类别中显示错误的产品数量 [英] magento showing wrong product count in category

查看:27
本文介绍了magento 在类别中显示错误的产品数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个奇怪的问题,似乎很多人在互联网上都有同样的问题.下面的图片将定义我的问题,我的 magento 版本是 1.7

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

正如我所强调的,LEFT 表示该类别有 16 个产品,但实际上类别产品选项卡显示了 15 个产品.我所有的类别都搞砸了.请让我知道出了什么问题.我试过禁用缓存,但没有用.

As I have highlighted, LEFT says the category has 16 products, but in actual the Category Products Tab shows 15 products. All my categories are messed up. Please let me know what's going wrong. I've tried disabling the cache, but it didn't worked.

我尝试从类别中删除一个产品,然后左侧的数字变为 15,总记录数为 14.所以我认为可能是该类别中禁用的产品.但是当我搜索禁用产品时,没有.

I tried removing one-product from the category, then the number on the left went to 15 and total records 14. So I thought may be a product whose is disabled in there in this category. But when I searched for disabled products none were there.

推荐答案

Hi product count 来自方法名 loadProductCount 位于 code/core/Mage/Catalog/Model/Resource/Category/Collection.php

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

如果你深入挖掘,这个计数来自两个表之间的连接查询:catalog_category_productcatalog_category_entity

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;           
}   

config.xml 中使用的事件

Event used in config.xml

<events>
<catalog_product_delete_after> <!-- identifier of the event we want to catch -->
<observers>
<catalog_product_delete_after_handler> <!-- identifier of the event handler -->
<type>model</type> <!-- class method call type; valid are model, object and singleton -->
<class>countfix/observer</class> <!-- observers class alias -->
<method>deleteCountCategory</method>  <!-- observer's method to be called -->
<args></args> <!-- additional arguments passed to observer -->
</catalog_product_delete_after_handler>
</observers>
</catalog_product_delete_after>
</events>

这篇关于magento 在类别中显示错误的产品数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆