#84 Alpine Grouped Item Processor - Duplicate entry violation

Ingo F.


I think I have found a bug in the plugin alpine_groupedprocessor.php

We faced a major problem when importing simple an grouped products via CSV.
The first import went fine but all following imports showed the same errors - like:

error:6349:SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '45771-2043' for key 'PRIMARY' - INSERT INTO catalog_product_relation (parent_id,child_id)

SELECT cpec.entity_id as parent_id,cpes.entity_id as child_id

FROM catalog_product_entity as cpec

JOIN catalog_product_entity as cpes ON cpes.sku IN (?,?,?)

WHERE cpec.entity_id=?
error:6350:SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '45771-2043' for key 'PRIMARY' - ERROR ON RECORD #45766

We finally found out, that the groupedprocessor did not delete all relations from catalog_product_relation properly.

In our opinion the following SQL does work for configurable products BUT NOT for grouped and bundled products (we dont have bundled products anyway).


    public function dolink($pid, $cond, $conddata = array())
        $sql = "DELETE cpsl.*,cpsr.* FROM $catalog_product_super_link as cpsl
            JOIN $catalog_product_relation as cpsr ON cpsr.parent_id=cpsl.parent_id
            WHERE cpsl.parent_id=?";

catalog_product_super_link does manage the links for configurable products only.
catalog_product_relation contains the relation for grouped, bundled - and for some legacy architecture reason, also for configurable products.

So, when we import a grouped product which already has relations set, no relations are deleted because of the wrong SQL.

We think we solved the issue by rewriting it to a RIGHT JOIN.

        $sql = "DELETE cpsl.*,cpsr.* FROM $catalog_product_super_link as cpsl
            RIGHT JOIN $catalog_product_relation as cpsr ON cpsr.parent_id=cpsl.parent_id
            WHERE cpsr.parent_id=?";

Can you approove this solution?