更新时间:2021-10-31 06:52:31
高产品计数来自方法名称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>