lakombrada Posted January 7, 2015 Share Posted January 7, 2015 !!!!!!!!!!! WARNING !!!!!!!!!!!!! !! this script delete few tables on target database please create a backup !!! !!!!!!!!!!! WARNING !!!!!!!!!!!!! This is my script to transfer products from 1.4 to 1.6 without image files.The database must be on the same server.1. Delete the tables in the new database2. copy the cell column of the tables from the old to the newabout 30 000 products - 45 sec.... maybe it helps someone;) <?phpecho "Start - " .date("Y-m-d H:i:s")."<br>"; $servername = "localhost"; $username = "root"; $password = ""; // Create connection $conn = new mysqli($servername, $username, $password); // Check connection if ($conn->connect_error) { die("Connection failed: <br>".$conn->connect_error); } echo "Connected successfully<br>"; function runQuery($query, $conn) { if ($conn->query($query) === true) { echo "New record created successfully<br>"; } else { echo "Error: ".$query."<br>".$conn->error."<br>"; } } $DB_source = "`presta`"; $DB_target = "`prestashop_1.6.0.9`"; $id_lang_source = 6; $id_lang_target = 2; $tabs = array( "ps_product", "ps_product_shop", "ps_product_supplier", "ps_product_lang", "ps_stock_available", "ps_category_product", "ps_image", "ps_image_lang", "ps_image_shop"); for ($i = 0; $i < count($tabs); $i++) { $query = "DELETE FROM ".$DB_target.".".$tabs[$i].";"; runQuery($query, $conn); $query = "ALTER TABLE ".$DB_target.".".$tabs[$i]." AUTO_INCREMENT = 0;"; runQuery($query, $conn); }//////////////////////////////////////////// $columns = "id_product,id_supplier,id_manufacturer,id_category_default, id_tax_rules_group,ean13,ecotax,quantity,price,wholesale_price, reference,supplier_reference,active,date_add,date_upd"; $columns2 = "id_product,id_supplier,id_manufacturer,id_category_default+1, id_tax_rules_group,ean13,ecotax,quantity,price,wholesale_price, reference,supplier_reference,active,date_add,date_upd"; $query = " INSERT INTO ".$DB_target.".`ps_product` (".$columns.") SELECT ".$columns2." FROM ".$DB_source.".`ps_product`";runQuery($query, $conn);//////////////////////////////////////////// $columns = "`id_product`, `id_shop`, `id_category_default`, `id_tax_rules_group`, `ecotax`, `price`, `wholesale_price`, `active`, `date_add`, `date_upd`"; $columns2 = "`id_product`, 1, `id_category_default`, `id_tax_rules_group`, `ecotax`, `price`, `wholesale_price`, `active`, `date_add`, `date_upd`"; $query = " INSERT INTO ".$DB_target.".`ps_product_shop` (".$columns.") SELECT ".$columns2." FROM ".$DB_target.".`ps_product`";runQuery($query, $conn); //////////////////////////////////////////// $columns = "`id_product`, `id_supplier`, `product_supplier_reference`, `product_supplier_price_te`, `id_currency`"; $columns2 = "`id_product`, `id_supplier`, `supplier_reference`, `wholesale_price`, 1"; $query = " INSERT INTO ".$DB_target.".`ps_product_supplier` (".$columns.") SELECT ".$columns2." FROM ".$DB_target.".`ps_product`";runQuery($query, $conn); //////////////////////////////////////////// $columns = "id_product,id_lang,description,description_short,link_rewrite,meta_description, meta_keywords,meta_title,name,available_now,available_later"; $columns2 = "id_product,".$id_lang_target.",description,description_short,link_rewrite,meta_description, meta_keywords,meta_title,name,available_now,available_later"; $query = " INSERT INTO ".$DB_target.".`ps_product_lang` (".$columns.") SELECT ".$columns2." FROM ".$DB_source.".`ps_product_lang` WHERE `id_lang`=".$id_lang_source;runQuery($query, $conn); //////////////////////////////////////////// $columns = "`id_product`, `id_product_attribute`, `id_shop`, `id_shop_group`, `quantity`, `out_of_stock`"; $columns2 = "`id_product`, 0, 1, 0, `quantity`, 2"; $query = " INSERT INTO ".$DB_target.".`ps_stock_available` (".$columns.") SELECT ".$columns2." FROM ".$DB_target.".`ps_product`";runQuery($query, $conn); //////////////////////////////////////////// $columns = "`id_category`, `id_product`"; $columns2 = "`id_category_default`, `id_product`"; $query = " INSERT INTO ".$DB_target.".`ps_category_product` (".$columns.") SELECT ".$columns2." FROM ".$DB_target.".`ps_product`";runQuery($query, $conn);//////////////////////////////////////////// $columns = "`id_image`, `id_product`,`position`,`cover`"; $query = " INSERT INTO ".$DB_target.".`ps_image` (".$columns.") SELECT ".$columns." FROM ".$DB_source.".`ps_image`";runQuery($query, $conn);//////////////////////////////////////////// $columns = "`id_image`, `id_lang`,`legend`"; $columns2 = "`id_image`, ".$id_lang_target.",`legend`"; $query = " INSERT INTO ".$DB_target.".`ps_image_lang` (".$columns.") SELECT ".$columns2." FROM ".$DB_source.".`ps_image_lang` WHERE `id_lang`=".$id_lang_source;runQuery($query, $conn);//////////////////////////////////////////// $columns = "`id_image`, `id_shop`,`cover`"; $columns2 = "`id_image`, 1,1"; $query = " INSERT INTO ".$DB_target.".`ps_image_shop` (".$columns.") SELECT ".$columns2." FROM ".$DB_source.".`ps_image`";runQuery($query, $conn); if ($product["image"] != "" && $_SESSION["insert_images"] == true) $this->insertProductImage($pid, $product["image"], 'add'); $conn->close();echo "End - " .date("Y-m-d H:i:s"); ?> Link to comment Share on other sites More sharing options...
webxtor Posted June 18, 2015 Share Posted June 18, 2015 Great script! Was it written by you? The only thing it seems to be missing the product features. 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