且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Magento SQLSTATE错误(如果产品库存中剩余一项)

更新时间:2023-11-30 12:59:22

我们以前在magento 1.7上也遇到过类似的问题,这是因为我们引入了新"类型的产品,该产品是一堆可配置的产品. 在这种情况下,当reindexProductIds调用_copyRelationIndexData时,我们同时拥有某些产品的父项和其他产品(捆绑的子项)的子目录catalog_product_index_price_tmp表中填充了一些属于复合产品"的行,从而导致调用reindexEntity时,违反完整性约束". 长话短说,我们以此方式覆盖_copyRelationIndexData方法:

We used to have a similar problem on magento 1.7, it happened because we introduced a "new" type of product that is a bundle of configurable products. In this case we had some products that were at the same time parent of some products and children of some other (the bundle ones) that way when _copyRelationIndexData was called by reindexProductIds catalog_product_index_price_tmp table was filled with some rows belonging to "composite products" causing the "Integrity constraint violation" when reindexEntity is called. Long story short we overrode _copyRelationIndexData method this way :

protected function _copyRelationIndexData($parentIds, $excludeIds = null)
    {
        if(!is_null($excludeIds) && is_array($excludeIds)){
            $excludeIds = array_merge($excludeIds,$parentIds);
        }
        return parent::_copyRelationIndexData($parentIds, $excludeIds);
    }