So I have an import/export module for OpenCart, but it's wiping the entire product option table before inserting new data...
I need to develop support for the 3rd party product options module I have, but in the meantime--I figure I'd just stop it from deleting an important column in my product options table.
In the product_option_value
table, I have 'product_option,' 'product_id,' 'quantity' etc., and there's one column named 'info' that I want to NOT wipe. The method is below:
function storeOptionsIntoDatabase( &$database, &$options )
{
// find the default language id
$languageId = $this->getDefaultLanguageId($database);
// start transaction, remove options
$sql = "START TRANSACTION;\n";
$sql .= "DELETE FROM `".DB_PREFIX."product_option`;\n";
$sql .= "DELETE FROM `".DB_PREFIX."product_option_description` WHERE language_id=$languageId;\n";
$sql .= "DELETE FROM `".DB_PREFIX."product_option_value`;\n";
$sql .= "DELETE FROM `".DB_PREFIX."product_option_value_description` WHERE language_id=$languageId;\n";
$this->import( $database, $sql );
...more code...
}
I'm not that familiar with MySQL, but I want something to the effect of:
$sql .= "DELETE FROM `".DB_PREFIX."product_option_value` WHERE column != 'info';\n";
Thanks!
Edit:
I tried Michael's suggestion to use UPDATE
and explicitly setting them all to NULL... but that returned this error:
Error: Duplicate entry '0' for key 1 Error No: 1062 UPDATE
oc_product_option_value
SET product_option_value_id=NULL, product_option_id=NULL, product_id=NULL, quantity=NULL, subtract=NULL, price=NULL, prefix=NULL, sort_order=NULL, weight=NULL, sku=NULL, image=NULL
I tried taking out the primary key:
$sql .= "UPDATE
".DB_PREFIX."product_option_value
SET product_option_id=NULL, product_id=NULL, quantity=NULL, subtract=NULL, price=NULL, prefix=NULL, sort_order=NULL, weight=NULL;\n";
but I get:
Error: Duplicate entry '1' for key 1 Error No: 1062 INSERT INTO `oc_product....
Edit:
Okay, so I removed the 'primary_key' field from the INSERT... and I got no error messages from the upload. But when I view a product that product options, I get this message the top of my page:
Notice: Undefined index: name in /httpdocs/ocart/catalog/model/catalog/product.php on line 418Notice: Undefined index: name in /httpdocs/ocart/catalog/model/catalog/product.php on line 418Notic.... it repeats
<>
rather than!=
. Go look up MySQL operator syntax in the manual. – Lightness Races in Orbit