magento在类别中显示错误的产品计数

标签 magento magento-1.7

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

正如我所强调的那样,LEFT表示该类别有16种产品,但实际上“类别产品”选项卡显示15种产品。我所有的类别都搞砸了。请让我知道怎么了。我曾尝试禁用缓存,但没有成功。

[编辑]

我尝试从类别中删除一个产品,然后左侧的数字为15,总记录为14。因此,我认为可能是该类别中该产品已被禁用的产品。但是当我搜索残疾人产品时,却没有。

最佳答案

嗨,产品数量来自方法名称loadProductCount,它位于code/core/Mage/Catalog/Model/Resource/Category/Collection.php位置

如果您要深入研究,则此计数来自两个表之间的联接查询:catalog_category_productcatalog_category_entity
我已经通过使用事件观察器解决了此问题。您暂时可以这样做。如果您有更好的解决方案,请告诉我。

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中使用的事件
<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在类别中显示错误的产品计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14777478/

相关文章:

php - 通过 ORM 将数据导入 Magento 的性能是否可以接受,或者直接 SQL 是唯一的选择吗?

css - Magento 在自定义主题之前查看基础

magento - 如何从页脚中删除 'Orders and Returns'?

mysql - Magento - 安装扩展错误

php - Magento - 购买可下载产品时删除账单和运输信息

php - magento 自定义支付模块用于多运

javascript - 当 magento 结帐页面中的国家不是美国和法国时,国家名称应该是文本框

magento - 通过 API 创建 Magento 优惠券

api - 如何在 Magento 中获取可配置属性的选项?

mysql - magento 注册用户详细信息存储在哪里