selin Posted December 9, 2018 Share Posted December 9, 2018 Hello, I want to insert products to my new P.S store with their specific IDs. (XML import). Ex: X product's ID is 346, I want to save X product with 346, not autoincrement ID. (ofcourse the IDs are unique.) How can I do this? If you wonder, why? My original topic is this. My codes for insert: $product = New Product(); $name = (string)$xml->name; .. bla bla .. $product->save(); Thanks a lot! Link to comment Share on other sites More sharing options...
phinq1910 Posted December 10, 2018 Share Posted December 10, 2018 (edited) You have to turn off identity insert, insert the records then turn on identity insert back. Example: ALTER TABLE ps_product DROP PRIMARY KEY, MODIFY id_product INT PRIMARY KEY NOT NULL; --insert commmand here.... ALTER TABLE ps_product DROP PRIMARY KEY, MODIFY id_product INT AUTO_INCREMENT PRIMARY KEY NOT NULL; Edited December 10, 2018 by phinq1910 (see edit history) 1 Link to comment Share on other sites More sharing options...
selin Posted December 10, 2018 Author Share Posted December 10, 2018 23 minutes ago, phinq1910 said: You have to turn off identity insert, insert the records then turn on identity insert back. Example: ALTER TABLE ps_product DROP PRIMARY KEY, MODIFY id_product INT PRIMARY KEY NOT NULL; --insert commmand here.... ALTER TABLE ps_product DROP PRIMARY KEY, MODIFY id_product INT AUTO_INCREMENT PRIMARY KEY NOT NULL; Okay, Well, can I update a product's ID? Such as: name? Link to comment Share on other sites More sharing options...
phinq1910 Posted December 10, 2018 Share Posted December 10, 2018 Yes, try translate it on BO 1 Link to comment Share on other sites More sharing options...
selin Posted December 10, 2018 Author Share Posted December 10, 2018 18 minutes ago, phinq1910 said: Yes, try translate it on BO Sorry but, Your screen is not same with the standart B.O. ? Link to comment Share on other sites More sharing options...
phinq1910 Posted December 10, 2018 Share Posted December 10, 2018 Myself is presta 1.7. You can check same with 1.6 Link to comment Share on other sites More sharing options...
selin Posted December 10, 2018 Author Share Posted December 10, 2018 1 hour ago, phinq1910 said: You have to turn off identity insert, insert the records then turn on identity insert back. Example: ALTER TABLE ps_product DROP PRIMARY KEY, MODIFY id_product INT PRIMARY KEY NOT NULL; --insert commmand here.... ALTER TABLE ps_product DROP PRIMARY KEY, MODIFY id_product INT AUTO_INCREMENT PRIMARY KEY NOT NULL; Hmm.. at: phpMyadmin SQL error: ALTER TABLE ps_product DROP PRIMARY KEY, MODIFY id_product INT PRIMARY KEY NOT NULL MySQL error: #1292 - Incorrect date value: '0000-00-00' for column 'available_date' at row 1 UPDATED: This error is solved, source. About MySQL 5.7 Link to comment Share on other sites More sharing options...
selin Posted December 10, 2018 Author Share Posted December 10, 2018 (edited) 3 hours ago, phinq1910 said: You have to turn off identity insert, insert the records then turn on identity insert back. Example: ALTER TABLE ps_product DROP PRIMARY KEY, MODIFY id_product INT PRIMARY KEY NOT NULL; --insert commmand here.... ALTER TABLE ps_product DROP PRIMARY KEY, MODIFY id_product INT AUTO_INCREMENT PRIMARY KEY NOT NULL; Opps.. There is an error : INSERT QUERY does not have id_product INSERT INTO `ps_product` (`id_shop_default`, `id_manufacturer`, `id_supplier`, `reference`, `supplier_reference`, `location`, `width`, `height`, `depth`, `weight`, `quantity_discount`, `ean13`, `isbn`, `upc`, `cache_is_pack`, `cache_has_attachments`, `is_virtual`, `state`, `additional_delivery_times`, `id_category_default`, `id_tax_rules_group`, `on_sale`, `online_only`, `ecotax`, `minimal_quantity`, `low_stock_threshold`, `low_stock_alert`, `price`, `wholesale_price`, `unity`, `unit_price_ratio`, `additional_shipping_cost`, `customizable`, `text_fields`, `uploadable_files`, `active`, `redirect_type`, `id_type_redirected`, `available_for_order`, `available_date`, `show_condition`, `condition`, `show_price`, `indexed`, `visibility`, `cache_default_attribute`, `advanced_stock_management`, `date_add`, `date_upd`, `pack_stock_type`) VALUES ('1', '0', '2', '', '2', '', '0', '0', '0', '0', '0', '', '', '', '0', '0', '0', '1', '1', '0', '1', '0', '0', '0', '1', NULL, '0', '4', '0', '', '0', '0', '0', '0', '0', '1', '', '0', '1', '0000-00-00', '0', 'new', '1', '0', 'both', '0', '0', '2018-12-10 15:50:17', '2018-12-10 15:50:17', '3') THEN I updated classes/Product.php /** @var int default Shop id */ public $id_product; ... bla .. 'fields' => array( /* Classic fields */ 'id_product' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), 'id_shop_default' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), 'id_manufacturer' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), Then, I saved. but not listed in B.O Products page. Because, product's id is 1 at ps_product but, 0 at ps_product_lang table. Any ideas? Edited December 10, 2018 by selin (see edit history) Link to comment Share on other sites More sharing options...
ventura Posted December 30, 2018 Share Posted December 30, 2018 Keep in mind also the `ps_product_shop` table 1 Link to comment Share on other sites More sharing options...
musicmaster Posted January 3, 2019 Share Posted January 3, 2019 I am puzzled why you want to with the ID what the reference field was made for. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now