
Originally Posted by
twitchtoo
Clean install 1.54 of most recent EasyPopulate 1.2.6.1 released Oct 21, 2015 results in this error:
PHP Fatal error: 1062
uplicate entry '1-1' for key 'PRIMARY' :: INSERT INTO products_description SET
out of the box.
I'm working on the fix.
Problem...
The original code here is saying, if you find products_description - INSERT INTO the database if not UPDATE the database. This assumes that it's a new product and attempts to insert the same data into the same fields with the INSERT INTO command.
Solution...
Switch the INSERT INTO code with the UPDATE code and if it finds a match it will UPDATE the data, if not it assumes it's a new product and INSERT INTO the database.
In admin/easypopulate.php replace this line 1954 - 2046 :
PHP Code:
//*************************
// Products Descriptions Start
//*************************
// the following is common in both the updating an existing product and creating a new product
if (isset($v_products_name)){
foreach( $v_products_name as $key => $name){
if ($name != ''){
$ep_supported_mods_sql = "";
if ($ep_supported_mods['psd'] == true) {
$ep_supported_mods_sql = " products_short_desc = '".zen_db_input($v_products_short_desc[$key])."', ";
}
$sql = "SELECT * FROM ".TABLE_PRODUCTS_DESCRIPTION." WHERE products_id = $v_products_id AND language_id = " . $key . " LIMIT 1 ";
$result = $db->Execute($sql);
if( $result->RecordCount() > 0 ){
// new product description
//$result = ep_query($sql);
$sql ="INSERT INTO ".TABLE_PRODUCTS_DESCRIPTION." SET
products_id = '".$v_products_id."',
language_id = '".$key."',
products_name = '".zen_db_input($name)."',
products_description = '".zen_db_input($v_products_description[$key])."',
".$ep_supported_mods_sql."
products_url = '".zen_db_input($v_products_url[$key])."'
";
// langer - the following is redundant - one SQL string is now contructed with various optional mods
// support for Linda's Header Controller 2.0
if (isset($v_products_head_title_tag)){
// override the sql if we're using Linda's contrib
$sql =
"INSERT INTO ".TABLE_PRODUCTS_DESCRIPTION."
(products_id,
language_id,
products_name,
products_description,
products_url,
products_head_title_tag,
products_head_desc_tag,
products_head_keywords_tag)
VALUES (
'" . $v_products_id . "',
" . $key . ",
'" . zen_db_input($name) . "',
'" . zen_db_input($v_products_description[$key]) . "',
'". $v_products_url[$key] . "',
'". $v_products_head_title_tag[$key] . "',
'". $v_products_head_desc_tag[$key] . "',
'". $v_products_head_keywords_tag[$key] . "')";
}
// end support for Linda's Header Controller 2.0
//echo 'New product desc:'.$sql.'<br />';
$result = $db->Execute($sql);
} else {
// already in the description, let's just update it
$sql ="UPDATE ".TABLE_PRODUCTS_DESCRIPTION." SET
products_name = '".zen_db_input($name)."',
products_description = '".zen_db_input($v_products_description[$key])."',
".$ep_supported_mods_sql."
products_url = '".zen_db_input($v_products_url[$key])."'
WHERE products_id = '$v_products_id' AND language_id = '$key'";
// langer - below is redundant.
// support for Lindas Header Controller 2.0
if (isset($v_products_head_title_tag)){
// override the sql if we're using Linda's contrib
$sql =
"UPDATE ".TABLE_PRODUCTS_DESCRIPTION." SET
products_name='" . zen_db_input($name) . "',
products_description = '" . zen_db_input($v_products_description[$key]) . "',
products_url = '" . $v_products_url[$key] ."',
products_head_title_tag = '" . $v_products_head_title_tag[$key] ."',
products_head_desc_tag = '" . $v_products_head_desc_tag[$key] ."',
products_head_keywords_tag = '" . $v_products_head_keywords_tag[$key] ."'
WHERE
products_id = '$v_products_id' AND
language_id = '$key'";
}
// end support for Linda's Header Controller 2.0
//echo 'existing product desc:'.$sql.'<br />';
$result = $db->Execute($sql);
}
}
}
}
//*************************
// Products Descriptions End
//*************************
with this:
PHP Code:
//*************************
// Products Descriptions Start
//*************************
// the following is common in both the updating an existing product and creating a new product
if (isset($v_products_name)){
foreach( $v_products_name as $key => $name){
if ($name != ''){
$ep_supported_mods_sql = "";
if ($ep_supported_mods['psd'] == true) {
$ep_supported_mods_sql = " products_short_desc = '".zen_db_input($v_products_short_desc[$key])."', ";
}
$sql = "SELECT * FROM ".TABLE_PRODUCTS_DESCRIPTION." WHERE products_id = $v_products_id AND language_id = " . $key . " LIMIT 1 ";
$result = $db->Execute($sql);
if( $result->RecordCount() > 0 ){
//Twitch fix - match products and update - else - product is new so add new product.
// already in the description, let's just update it
$sql ="UPDATE ".TABLE_PRODUCTS_DESCRIPTION." SET
products_name = '".zen_db_input($name)."',
products_description = '".zen_db_input($v_products_description[$key])."',
".$ep_supported_mods_sql."
products_url = '".zen_db_input($v_products_url[$key])."'
WHERE products_id = '$v_products_id' AND language_id = '$key'";
// langer - below is redundant.
// support for Lindas Header Controller 2.0
if (isset($v_products_head_title_tag)){
// override the sql if we're using Linda's contrib
$sql =
"UPDATE ".TABLE_PRODUCTS_DESCRIPTION." SET
products_name='" . zen_db_input($name) . "',
products_description = '" . zen_db_input($v_products_description[$key]) . "',
products_url = '" . $v_products_url[$key] ."',
products_head_title_tag = '" . $v_products_head_title_tag[$key] ."',
products_head_desc_tag = '" . $v_products_head_desc_tag[$key] ."',
products_head_keywords_tag = '" . $v_products_head_keywords_tag[$key] ."'
WHERE
products_id = '$v_products_id' AND
language_id = '$key'";
}
// end support for Linda's Header Controller 2.0
//echo 'existing product desc:'.$sql.'<br />';
$result = $db->Execute($sql);
} else {
// new product description
//$result = ep_query($sql);
$sql ="INSERT INTO ".TABLE_PRODUCTS_DESCRIPTION." SET
products_id = '".$v_products_id."',
language_id = '".$key."',
products_name = '".zen_db_input($name)."',
products_description = '".zen_db_input($v_products_description[$key])."',
".$ep_supported_mods_sql."
products_url = '".zen_db_input($v_products_url[$key])."'
";
// langer - the following is redundant - one SQL string is now contructed with various optional mods
// support for Linda's Header Controller 2.0
if (isset($v_products_head_title_tag)){
// override the sql if we're using Linda's contrib
$sql =
"INSERT INTO ".TABLE_PRODUCTS_DESCRIPTION."
(products_id,
language_id,
products_name,
products_description,
products_url,
products_head_title_tag,
products_head_desc_tag,
products_head_keywords_tag)
VALUES (
'" . $v_products_id . "',
" . $key . ",
'" . zen_db_input($name) . "',
'" . zen_db_input($v_products_description[$key]) . "',
'". $v_products_url[$key] . "',
'". $v_products_head_title_tag[$key] . "',
'". $v_products_head_desc_tag[$key] . "',
'". $v_products_head_keywords_tag[$key] . "')";
}
// end support for Linda's Header Controller 2.0
//echo 'New product desc:'.$sql.'<br />';
$result = $db->Execute($sql);
}
}
}
}
//*************************
// Products Descriptions End
//*************************
I have tested this by manipulating the .csv file imported as well as making changes from the admin to break it, so far no errors!
Test Conditions:
- existing product
- new product
- update existing product
- remove product
Note: From what I could see EP doesn't delete or manage products that have been removed from the database essentially it does not perform a 'sync' only import and export.
Bookmarks