Skip to content

Instantly share code, notes, and snippets.

@venomjke
Created July 27, 2012 15:30
Show Gist options
  • Save venomjke/3188682 to your computer and use it in GitHub Desktop.
Save venomjke/3188682 to your computer and use it in GitHub Desktop.
Утилита, для объединения каталогов virtuemart joomla. Версия virtuemart 1.1.8
<?php
header("Content-Type: text/html; charset=UTF-8");
try{
$dommebeli = new PDO('mysql:host=localhost;dbname=yahoch_b0_domm', 'yahoch_b0_domm', 'cegthvtufgfhjkm',array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
$mebeless = new PDO('mysql:host=localhost;dbname=yahoch_mergedb','yahoch_mergedb','12345678',array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
$parentCategory = 51;
/*
* Перемещение производителей
*/
$domStmt = $dommebeli->query("SELECT * FROM jos_vm_manufacturer");
$manufacturer = $domStmt->fetchAll();
$manufacturer_keys = array();
$sqlInsertManufacturer = 'INSERT INTO jos_vm_manufacturer(manufacturer_id,mf_name,mf_email,mf_desc,mf_category_id,mf_url)VALUES(NULL,:mf_name,:mf_email,:mf_desc,:mf_category,:mf_url)';
$mebStmt = $mebeless->prepare($sqlInsertManufacturer);
foreach($manufacturer as $manufac){
$mebStmt->bindParam(':mf_name',$manufac['mf_name']);
$mebStmt->bindParam(':mf_email',$manufac['mf_email']);
$mebStmt->bindParam(':mf_desc',$manufac['mf_desc']);
$mebStmt->bindParam(':mf_category',$manufac['mf_category_id']);
$mebStmt->bindParam(':mf_url',$manufac['mf_url']);
$mebStmt->execute();
$manufac['new_manufacturer_id'] = $mebeless->lastInsertId();
$manufacturer_keys[$manufac['manufacturer_id']] = $manufac['new_manufacturer_id'];
}
/*
* Перемещение категорий jos_vm_category
*/
$domStmt = $dommebeli->query("SELECT * FROM jos_vm_category");
$categories = $domStmt->fetchAll();
$category_keys = array(); // массив для хранения старых -> новый идентификаторов
$sqlInsertCategory = 'INSERT INTO jos_vm_category(category_id,vendor_id,category_name,category_description,category_thumb_image,category_full_image,category_publish,cdate,mdate,category_browsepage,products_per_row,category_flypage,list_order) VALUES(NULL,:vendor_id,:category_name,:category_description,:category_thumb_image,:category_full_image,:category_publish,:cdate,:mdate,:category_browsepage,:products_per_row,:category_flypage,:list_order)';
$mebStmt = $mebeless->prepare($sqlInsertCategory);
foreach($categories as $category){
$mebStmt->bindParam(':vendor_id',$category['vendor_id']);
$mebStmt->bindParam(':category_name',$category['category_name']);
$mebStmt->bindParam(':category_description',$category['category_description']);
$category_thumb_image = "dommebeli/".$category['category_thumb_image'];
$category_full_image = "dommebeli/".$category['category_full_image'];
$mebStmt->bindParam(':category_thumb_image',$category_thumb_image);
$mebStmt->bindParam(':category_full_image',$category_full_image);
$mebStmt->bindParam(':category_publish',$category['category_publish']);
$mebStmt->bindParam(':cdate',$category['cdate']);
$mebStmt->bindParam(':mdate',$category['mdate']);
$mebStmt->bindParam(':category_browsepage',$category['category_browsepage']);
$mebStmt->bindParam(':products_per_row',$category['products_per_row']);
$mebStmt->bindParam(':category_flypage',$category['category_flypage']);
$mebStmt->bindParam(':list_order',$category['list_order']);
$mebStmt->execute();
$category['new_category_id'] = $mebeless->lastInsertId();
$category_keys[$category['category_id']] = $category['new_category_id'];
echo 'old $category_id: '.$category['category_id'].' '.'new $category_id: '.$category['new_category_id'].'<br/>';
}
/*
* Перемещение зависимостей категорий jos_vm_category_xref
*/
$domStmt = $dommebeli->query("SELECT * FROM jos_vm_category_xref");
$categories_xref = $domStmt->fetchAll();
$sqlInsertCategoryXref = 'INSERT INTO jos_vm_category_xref(category_parent_id,category_child_id,category_list)VALUES(?,?,?)';
$mebStmt = $mebeless->prepare($sqlInsertCategoryXref);
foreach($categories_xref as $categoryXref){
$category_parent_id = $categoryXref['category_parent_id'] == 0?$parentCategory:$category_keys[$categoryXref['category_parent_id']];
$category_child_id = $category_keys[$categoryXref['category_child_id']];
$mebStmt->execute(array($category_parent_id,$category_child_id,$categoryXref['category_list']));
}
/*
* Перемещение товаров
*/
$domStmt = $dommebeli->query('SELECT * FROM jos_vm_product');
$products = $domStmt->fetchAll();
$products_keys = array();
$sqlInsertProduct = 'INSERT INTO jos_vm_product(product_id,vendor_id,product_parent_id,product_sku,product_s_desc,product_desc,product_thumb_image,product_full_image,product_publish,product_weight,product_weight_uom,product_length,product_width,product_height,product_lwh_uom,product_url,product_in_stock,product_available_date,product_availability,product_special,product_discount_id,ship_code_id,cdate,mdate,product_name,product_sales,attribute,custom_attribute,product_tax_id,product_unit,product_packaging,child_options,quantity_options,child_option_ids,product_order_levels)
VALUES(NULL,:vendor_id,:product_parent_id,:product_sku,:product_s_desc,:product_desc,:product_thumb_image,:product_full_image,:product_publish,:product_weight,:product_weight_uom,:product_length,:product_width,:product_height,:product_lwh_uom,:product_url,:product_in_stock,:product_available_date,:product_availability,:product_special,:product_discount_id,:ship_code_id,:cdate,:mdate,:product_name,:product_sales,:attribute,:custom_attribute,:product_tax_id,:product_unit,:product_packaging,:child_options, :quantity_options, :child_option_ids, :product_order_levels)';
$mebStmt = $mebeless->prepare($sqlInsertProduct);
foreach($products as $product){
$mebStmt->bindParam(':vendor_id',$product['vendor_id']);
$mebStmt->bindParam(':product_parent_id',$product['product_parent_id']);
$mebStmt->bindParam(':product_sku',$product['product_sku']);
$mebStmt->bindParam(':product_s_desc',$product['product_s_desc']);
$mebStmt->bindParam(':product_desc',$product['product_desc']);
$product_thumb_image = "dommebeli/".$product['product_thumb_image'];
$product_full_image = "dommebeli/".$product['product_full_image'];
$mebStmt->bindParam(':product_thumb_image',$product_thumb_image);
$mebStmt->bindParam(':product_full_image',$product_full_image);
$mebStmt->bindParam(':product_publish',$product['product_publish']);
$mebStmt->bindParam(':product_weight',$product['product_weight']);
$mebStmt->bindParam(':product_weight_uom',$product['product_weight_uom']);
$mebStmt->bindParam(':product_length',$product['product_length']);
$mebStmt->bindParam(':product_width',$product['product_width']);
$mebStmt->bindParam(':product_height',$product['product_height']);
$mebStmt->bindParam(':product_lwh_uom',$product['product_lwh_uom']);
$mebStmt->bindParam(':product_url',$product['product_url']);
$mebStmt->bindParam(':product_in_stock',$product['product_in_stock']);
$mebStmt->bindParam(':product_available_date',$product['product_available_date']);
$mebStmt->bindParam(':product_availability',$product['product_availability']);
$mebStmt->bindParam(':product_special',$product['product_special']);
$mebStmt->bindParam(':product_discount_id',$product['product_discount_id']);
$mebStmt->bindParam(':ship_code_id',$product['ship_code_id']);
$mebStmt->bindParam(':cdate',$product['cdate']);
$mebStmt->bindParam(':mdate',$product['mdate']);
$mebStmt->bindParam(':product_name',$product['product_name']);
$mebStmt->bindParam(':product_sales',$product['product_sales']);
$mebStmt->bindParam(':attribute',$product['attribute']);
$mebStmt->bindParam(':custom_attribute',$product['custom_attribute']);
$mebStmt->bindParam(':product_tax_id',$product['product_tax_id']);
$mebStmt->bindParam(':product_unit',$product['product_unit']);
$mebStmt->bindParam(':product_packaging',$product['product_packaging']);
$mebStmt->bindParam(':child_options',$product['child_options']);
$mebStmt->bindParam(':quantity_options',$product['quantity_options']);
$mebStmt->bindParam(':child_option_ids',$product['child_option_ids']);
$mebStmt->bindParam(':product_order_levels',$product['product_order_levels']);
$mebStmt->execute();
$product['new_product_id'] = $mebeless->lastInsertId();
$products_keys[$product['product_id']]=$product['new_product_id'];
echo 'old $product_id: '.$product['product_id'].' '.'new $product_id: '.$product['new_product_id'].'<br/>';
}
/*
* Перемещаем атрибуты товаров
*/
$domStmt = $dommebeli->query('SELECT * FROM jos_vm_product_attribute');
$product_attribute = $domStmt->fetchAll();
$product_attribute_keys = array();
$sqlInsertProductAttribute = 'INSERT INTO jos_vm_product_attribute(`attribute_id`, `product_id`, `attribute_name`, `attribute_value`)VALUES (NULL,:product_id,:attribute_name,:attribute_value)';
$mebStmt = $mebeless->prepare($sqlInsertProductAttribute);
foreach($product_attribute as $prod_attr){
$mebStmt->bindParam(':product_id',$products_keys[$prod_attr['product_id']]);
$mebStmt->bindParam(':attribute_name',$prod_attr['attribute_name']);
$mebStmt->bindParam(':attribute_value',$prod_attr['attribute_value']);
$mebStmt->execute();
$prod_attr['new_attribute_id'] = $mebeless->lastInsertId();
$product_attribute_keys[$prod_attr['attribute_id']] = $prod_attr['new_attribute_id'];
echo 'old $attribute_id: '.$prod_attr['attribute_id'].' '.'new $attribute_id: '.$prod_attr['new_attribute_id'].'<br/>';
}
/*
* Перемещаем что-то связанное с атрибутами товаров
*/
$domStmt = $dommebeli->query('SELECT * FROM jos_vm_product_attribute_sku');
$product_attribute_sku = $domStmt->fetchAll();
$sqlInsertProductAttributeSku = 'INSERT INTO jos_vm_product_attribute_sku(product_id,attribute_name,attribute_list) VALUES (:product_id,:attribute_name,:attribute_list)';
$mebStmt = $mebeless->prepare($sqlInsertProductAttributeSku);
foreach($product_attribute_sku as $prod_attr_sku){
$mebStmt->bindParam(':product_id',$products_keys[$prod_attr_sku['product_id']]);
$mebStmt->bindParam(':attribute_name',$prod_attr_sku['attribute_name']);
$mebStmt->bindParam(':attribute_list',$prod_attr_sku['attribute_list']);
$mebStmt->execute();
}
/*
* Перемещаем связи продуктов с категорями
*/
$domStmt = $dommebeli->query('SELECT * FROM jos_vm_product_category_xref');
$product_category_xref = $domStmt->fetchAll();
$sqlInsertProductCategoryXref = 'INSERT INTO jos_vm_product_category_xref(category_id,product_id,product_list)VALUES(:category_id,:product_id,:product_list)';
$mebStmt = $mebeless->prepare($sqlInsertProductCategoryXref);
foreach($product_category_xref as $prod_cat_xref){
$mebStmt->bindParam(':category_id',$category_keys[$prod_cat_xref['category_id']]);
$mebStmt->bindParam(':product_id',$products_keys[$prod_cat_xref['product_id']]);
$mebStmt->bindParam(':product_list',$prod_cat_xref['product_list']);
$mebStmt->execute();
}
/*
* Перемещаем связи файлов с товарами
*/
$domStmt = $dommebeli->query('SELECT * FROM jos_vm_product_files');
$product_files = $domStmt->fetchAll();
$sqlInsertProductFile = 'INSERT INTO jos_vm_product_files(`file_id`, `file_product_id`, `file_name`, `file_title`, `file_description`, `file_extension`, `file_mimetype`, `file_url`, `file_published`, `file_is_image`, `file_image_height`, `file_image_width`, `file_image_thumb_height`, `file_image_thumb_width`)VALUES(NULL,:file_product_id,:file_name,:file_title,:file_description,:file_extension,:file_mimetype,:file_url,:file_published,:file_is_image,:file_image_height,:file_image_width,:file_image_thumb_height);';
$mebStmt = $mebeless->prepare($sqlInsertProductFile);
foreach($product_files as $prod_file){
$mebStmt->bindParam(':file_product_id',$products_keys[$prod_file['file_product_id']]);
$mebStmt->bindParam(':file_name',$prod_file['file_name']);
$mebStmt->bindParam(':file_title',$prod_file['file_title']);
$mebStmt->bindParam(':file_description',$prod_file['file_description']);
$mebStmt->bindParam(':file_extension',$prod_file['file_extension']);
$mebStmt->bindParam(':file_mimetype',$prod_file['file_mimetype']);
$mebStmt->bindParam(':file_url',$prod_file['file_url']);
$mebStmt->bindParam(':file_published',$prod_file['file_published']);
$mebStmt->bindParam(':file_is_image',$prod_file['file_is_image']);
$mebStmt->bindParam(':file_image_height',$prod_file['file_image_height']);
$mebStmt->bindParam(':file_image_width',$prod_file['file_image_width']);
$mebStmt->bindParam(':file_image_thumb_height',$prod_file['file_image_thumb_height']);
$mebStmt->execute();
}
/*
* Перемещаем mf_href
*/
$domStmt = $dommebeli->query('SELECT * FROM jos_vm_product_mf_xref');
$product_mf_xref = $domStmt->fetchAll();
$sqlInsertProductMfXref = 'INSERT INTO jos_vm_product_mf_xref(product_id,manufacturer_id)VALUES(:product_id,:manufacturer_id)';
$mebStmt = $mebeless->prepare($sqlInsertProductMfXref);
foreach($product_mf_xref as $prod_mf_xref){
$mebStmt->bindParam(':product_id',$products_keys[$prod_mf_xref['product_id']]);
$mebStmt->bindParam(':manufacturer_id',$manufacturer_keys[$prod_mf_xref['manufacturer_id']]);
$mebStmt->execute();
}
/*
* Перемещаем цены
*/
$domStmt = $dommebeli->query('SELECT * FROM jos_vm_product_price');
$product_price = $domStmt->fetchAll();
//$sqlInsertProductPrice = 'INSERT INTO jos_vm_product_price( product_price_id,product_id,product_price,product_currency,product_price_vdate,product_price_edate,cdate,mdate,shopper_group_id,price_quantity_start,price_quantity_end)
//VALUES(:product_price_id,:product_id,:product_price,:product_currency,:product_price_vdate,:product_price_edate,$:cdate,:mdate,:shopper_group_id,:price_quantity_start,:price_quantity_end)';
$sqlInsertProductPrice = 'INSERT INTO jos_vm_product_price(product_price_id,product_id,product_price,product_currency,product_price_vdate,product_price_edate,cdate,mdate,shopper_group_id,price_quantity_start,price_quantity_end)VALUES(:product_price_id,:product_id,:product_price,:product_currency,:product_price_vdate,:product_price_edate,:cdate,:mdate,:shopper_group_id,:price_quantity_start,:price_quantity_end)';
$mebStmt = $mebeless->prepare($sqlInsertProductPrice);
foreach($product_price as $prod_price){
$mebStmt->bindParam(':product_price_id',$products_keys[$prod_price['product_price_id']]);
$mebStmt->bindParam(':product_id',$products_keys[$prod_price['product_id']]);
$mebStmt->bindParam(':product_price',$prod_price['product_price']);
$mebStmt->bindParam(':product_currency',$prod_price['product_currency']);
$mebStmt->bindParam(':product_price_vdate',$prod_price['product_price_vdate']);
$mebStmt->bindParam(':product_price_edate',$prod_price['product_price_edate']);
$mebStmt->bindParam(':cdate',$prod_price['cdate']);
$mebStmt->bindParam(':mdate',$prod_price['mdate']);
$mebStmt->bindParam(':shopper_group_id',$prod_price['shopper_group_id']);
$mebStmt->bindParam(':price_quantity_start',$prod_price['price_quantity_start']);
$mebStmt->bindParam(':price_quantity_end',$prod_price['price_quantity_end']);
$mebStmt->execute();
echo '$product_price: '.$products_keys[$prod_price['product_price_id']].'<br/>';
}
/*
* Перемещаем отношения продуктов
*/
$domStmt = $dommebeli->query('SELECT * FROM jos_vm_product_relations');
$product_relations = $domStmt->fetchAll();
$sqlInsertProductRelation = 'INSERT INTO jos_vm_product_relations(product_id,related_products)VALUES(:product_id,:related_products)';
$mebStmt = $mebeless->prepare($sqlInsertProductRelation);
foreach($product_relations as $prod_rel){
$mebStmt->bindParam(':product_id',$products_keys[$prod_rel['product_id']]);
$related_products = explode('|',$prod_rel['related_products']);
$related_products = array_map("update_array",$related_products);
$related_products = implode("|",$related_products);
$mebStmt->bindParam(':related_products',$related_products);
$mebStmt->execute();
}
}catch(PDOException $objException){
echo $objException->getMessage();
}
function update_array($id){
global $products_keys;
return $products_keys[$id];
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment