magento在类别中显示错误的产品计数 [英] magento showing wrong product count in category
问题描述
我有一个奇怪的问题,似乎很多人在互联网上都遇到了同样的问题.下图将定义我的问题,我的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.
推荐答案
高产品计数来自方法名称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_product
和catalog_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屋!