Seguimos migrando Opencart a Prestashop, el tema que ocuparemos hoy será actualizar los datos de los productos vinculándolos con el fabricante.
Esta parte la debía haber puesto en el primer post de los que te recomiendo que leas (Más abajo lo verás). Pero no lo hice, se me paso por alto vincular el fabricante, bueno, más bien empece migrando los productos cuando debería haber empezado migrando los fabricantes, categorías, etc, Y por último los productos. El caso es que no lo hice así, no obstante tampoco hay ningún problema, sencillamente actualizaré con un UPDATE los datos de la tabla productos para que pueda queden vinculados al fabricante o marca que tenían en Opencart.
Si ves los otros tutos o post que he subido al blog verás que para migrar los datos he utilizado el mismo procedimiento, crear un cursor que recoge los datos basándonos en el id y diversos insert o insert a select para introducir los datos que nos ha devuelto el cursor, no tiene mucho misterio.
Y aquí te dejo el código, solo tienes que subirlo a tu base de datos y llamar a la funcion Call gotomanofacturer desde tu base de datos.
La primera entrada te valdría para migrar todos los productos, aunque obviamente tendrás que ver como está hecha tu base de datos Opencart y adaptarlo a tu base de datos.
La segunda entrada te valdría para crear la estructura de carpetas que tiene Prestashop para colocar las imágenes. Es un poco rara pero al final del post encontrarás un script para crear está estructura de 9999 carpetas para colocar adecuadamente las imágenes de Prestashop.
La tercera te valdrá para migrar las imágenes de un sitio a otro.
Aquí tienes la tercera parte
La cuarta y última serviria para migrar los fabricantes o marcas.
Aquí tienes la cuarta parte
Y aquí tienes el código de esta entrada, para que puedas vincular todos los fabricantes a tus productos o viceversa 🙂
Te lo dejo a cambio de una acción social, gracias!!
[sociallocker]
DROP PROCEDURE IF EXISTS gotomanofacturer;
DELIMITER $$
CREATE PROCEDURE gotomanofacturer (
) BEGIN
-- Variables para almcenar los valores de la SELECT
DECLARE v_product_id int(11);
DECLARE v_model varchar(64);
DECLARE v_sku varchar(64);
DECLARE v_upc varchar(12);
DECLARE v_location varchar(128);
DECLARE v_quantity int(4);
DECLARE v_stock_status_id int(11);
DECLARE v_image varchar(255);
DECLARE v_manufacturer_id int(11);
DECLARE v_shipping tinyint(1);
DECLARE v_price decimal(15,4);
DECLARE v_points int(8);
DECLARE v_tax_class_id int(11);
DECLARE v_date_available date;
DECLARE v_weight decimal(5,2);
DECLARE v_weight_class_id int(11) ;
DECLARE v_length decimal(5,2);
DECLARE v_width decimal(5,2);
DECLARE v_height decimal(5,2);
DECLARE v_length_class_id int(11);
DECLARE v_subtract tinyint(1);
DECLARE v_minimum int(11) ;
DECLARE v_sort_order int(11) ;
DECLARE v_status tinyint(1);
DECLARE v_date_added datetime;
DECLARE v_date_modified datetime;
DECLARE v_viewed int(5) ;
DECLARE v_language_id int(11);
DECLARE v_name varchar(255);
DECLARE v_description text;
DECLARE v_meta_description varchar(255);
DECLARE v_meta_keyword varchar(255);
DECLARE v_custom_title varchar(255);
-- Variable para controlar el fin del bucle
DECLARE findelbucle INTEGER DEFAULT 0;
-- La SELECT que queremos
DECLARE OpencartByeBye CURSOR FOR
SELECT p.`product_id` , `model` , `sku` , `upc` , `location` , `quantity` , `stock_status_id` , `image` ,
`manufacturer_id` , `shipping` , `price` , `points`, `tax_class_id` , `date_available` , `weight` , `weight_class_id` ,
`length` , `width` , `height`, `length_class_id`, `subtract` , `minimum` , `sort_order` , `status` ,
`date_added` , `date_modified`, `viewed` , `name` , `description` , `meta_description`, `meta_keyword` , `custom_title`
FROM `product` p, `product_description` d
WHERE d.product_id = p.product_id AND d.language_id=4;
-- Cuando no existan mas datos findelbucle se pondra a 1
DECLARE CONTINUE HANDLER FOR NOT FOUND SET findelbucle=1;
-- DECLARE CONTINUE HANDLER FOR NOT FOUND SET @hecho = TRUE;
OPEN OpencartByeBye;
bucle: LOOP
FETCH OpencartByeBye INTO
v_product_id , v_model , v_sku , v_upc , v_location , v_quantity ,
v_stock_status_id , v_image , v_manufacturer_id , v_shipping , v_price , v_points,
v_tax_class_id , v_date_available , v_weight ,v_weight_class_id , v_length , v_width ,
v_height , v_length_class_id , v_subtract , v_minimum , v_sort_order , v_status ,
v_date_added , v_date_modified , v_viewed , v_name , v_description ,v_meta_description,
v_meta_keyword ,v_custom_title ;
IF findelbucle = 1 THEN
LEAVE bucle;
END IF;
-- Hacemos los inserts en las tablas de Prestashop
-- Primero la tabla product
UPDATE `ps_product` SET `id_manufacturer` = V_manufacturer_id WHERE id_product= v_product_id;
END LOOP bucle;
CLOSE OpencartByeBye;
END$$
DELIMITER ;
[/sociallocker]
Si tienes dudas déjanos un comentario y te responderemos cuanto antes.
O si tienes muchas muchas dudas y quieres ponerte en contacto con nosotros puedes hacerlo a través del formulario de contacto.
¿Me echas una mano con la web? Solo te pido un +1 en Google, gracias