Prepare SQL
This commit is contained in:
parent
f7ba2465bf
commit
e417aa0b0f
88
scripts/import_products.php
Normal file
88
scripts/import_products.php
Normal file
@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
|
||||
require_once dirname(__FILE__).'/../www/config/config.inc.php';
|
||||
|
||||
// Old database
|
||||
$dbOld = new PDO($dsn);
|
||||
|
||||
// New database
|
||||
$dbNew = new PDO($dsn);
|
||||
|
||||
// Get all categories import in new DB
|
||||
$categories = array();
|
||||
$sql = "SELECT id_category FROM ps_category";
|
||||
$stmt = $dbOld->query($statement);
|
||||
if ($stmt->rowCount() > 0) {
|
||||
while ($item = $stmt->fetch(PDO::FETCH_OBJ)) {
|
||||
$categories[] = $item->id_category;
|
||||
}
|
||||
}
|
||||
|
||||
// Truncate
|
||||
$tables = array(
|
||||
'ps_category_product',
|
||||
'ps_product',
|
||||
'ps_product_lang',
|
||||
'ps_product_shop',
|
||||
'ps_stock_available',
|
||||
);
|
||||
foreach($tables as $table) {
|
||||
$dbNew->query('TRUNCATE TABLE '.$table);
|
||||
}
|
||||
|
||||
// Get products in category (old db)
|
||||
$sql = "SELECT DISTINCT(id_product) AS id_product FROM ps_category_product WHERE id_category IN (".join(',', $categories).")";
|
||||
$stmt = $dbNew->query($sql);
|
||||
if ($stmt->rowCount() > 0) {
|
||||
while($item = $stmt->fetch(PDO::FETCH_OBJ)) {
|
||||
$products[] = $item->id_product;
|
||||
}
|
||||
}
|
||||
|
||||
// New ps_category_product
|
||||
$cols = array(
|
||||
|
||||
);
|
||||
$sql = "SELECT * FROM ps_category_product WHERE id_product IN (".join(',', $products).")";
|
||||
$stmt = $dbNew->query($sql);
|
||||
if ($stmt->rowCount() > 0) {
|
||||
try {
|
||||
$dbNew->beginTransaction();
|
||||
while($item = $stmt->fetch(PDO::FETCH_OBJ)) {
|
||||
$stmt = $dbNew->prepare("INSERT INTO ps_category_product (id_category, id_product, position) VALUES (:id_category, :id_product, :position)");
|
||||
$stmt->bindParam('id_category', $item->id_category);
|
||||
$stmt->bindParam('id_product', $item->id_product);
|
||||
$stmt->bindParam('position', $item->position);
|
||||
$stmt->execute();
|
||||
}
|
||||
$dbNew->commit();
|
||||
} catch(Exception $e) {
|
||||
$dbNew->rollBack();
|
||||
echo "Error on ps_category_product\n";
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// New ps_product
|
||||
/*
|
||||
* id_product
|
||||
* id_supplier
|
||||
* id_manufacturer
|
||||
* id_category_default
|
||||
* id_shop_default
|
||||
* id_tax_rules_group
|
||||
* on_sale
|
||||
* onlie
|
||||
*/
|
||||
|
||||
// ps_product => id_category_default
|
||||
// ps_product_lang => from id_product
|
||||
// ps_product_shop => from id_product
|
||||
// ps_stock_available => from id_product
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user