Solution to bug regarding SQL error when duplicating product with child products

Started by Fable, July 07, 2008, 15:46:54 PM

Previous topic - Next topic

Fable

I found a bug in classes/ps_product.php

Line 412 through 414 contains a mysql query for copying product attributes.

Faulty code:

$q = "INSERT INTO #__{vm}_product_attribute
                  SELECT '$new_product_id', attribute_name, attribute_value
                  FROM #__{vm}_product_attribute WHERE product_id='$child_id'";
$db->query( $q );


Correct code:

$q = "INSERT INTO #__{vm}_product_attribute
                  SELECT NULL,'$new_product_id', attribute_name, attribute_value
                  FROM #__{vm}_product_attribute WHERE product_id='$child_id'";
$db->query( $q );

(The change is SELECT NULL,......)

Or you could specify which attributes to add. You got a illegal column count with the original code since it doesn't specify the attribute_id column (which is auto_incrementing)

Soeren

The future of eCommerce: VirtueMart & Joomla!
http://virtuemart.net

Fable