Saltar al contenido
Codifíca.me | Desarrollo web | Programación

Migrar Opencart to Prestashop | Cart to Cart

16 febrero, 2015

Deprecated: Function create_function() is deprecated in /home/nekdyruf/public_html/codi/wp-content/plugins/wp-syntax/geshi/geshi.php on line 4751

Recientemente estoy migrando una tienda Opencart a Prestashop, y la verdad que parece bastante complicado migrar los productos de una tienda a la otra, pero te mostraré como lo he hecho yo.

Para hacer este proceso más simple existen muchas webs como la famosa Cart2cart que previo desembolso te ayuda con la migración, aunque no migra opciones ni variaciones de productos. Por lo que la migración no es tan exitosa como parece. Yo tampoco voy a migrar esta parte porque la tienda a penas utiliza este componente.

El precio que he encontrado para realizar la migración no está mal, desde 80 Euros a 300 Euros te valen para migrar unos 1000 productos, aunque si tienes 6000, como es mi caso el precio se sube bastante más.

opencart to prestashop

Todos estos procesos son un poco engorrosos, ya que tienes que facilitar tus datos, de ambas webs y subir unos ficheros que ellos utilizan para no tener que darte el Script y que puedas migrar más webs por el mismo precio. Y bueno, no funcionan muy bien con la codificación de caracteres, por ejemplo ñ y acentos, aunque se puede resolver fácilmente.

Si tienes que repetir el proceso con varias tiendas tendrás que gastarte este dinero más veces.

Aunque no es un problema de precio, sino que realmente me apetece ver como puedo migrar estos productos desde una tienda Opencart a una tienda Prestashop, y ya de paso voy explicar el proceso que he hecho en este post.

Este proceso lo tendrás que adaptar para tu tienda y tambien para tu versión tanto de Opencart como de Prestashop.

Primero quiero enseñarte el procedimiento que he hecho, por si quieres modificarlo. Bueno si vas a usarlo siempre debes modificarlo si quieres que funcione con tu base de datos, de todas maneras voy a mostrártelo por partes.

Si quieres bajarte el código y ahorrarte este paso lo puedes hacer desde el final del post. Ahí tienes el código que he utilizado.

Vamos a ello, la migración está un pasito más cerca :).

Primero he declarado las variables de los productos que quiero migrar de mi base de datos Opencart.

Son los campos que necesito de las tablas de productos y descripción de productos de Opencart.

    -- 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;

Después preparamos el cursor que va a recuperar los datos de mi tabla Opencart.

  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;

Después indico al cursor en que variables voy a meter los datos de los productos que quiero que recupere mi cursor.

 
  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;

Y por último voy a meter todos los datos que he recuperado y que me interesan en las diferentes tablas que utiliza Prestashop.

INSERT INTO `ps_product` (`id_product`, `id_supplier`  , `id_manufacturer`, `id_category_default`, `id_shop_default` , `id_tax_rules_group`, `on_sale`        , `online_only`, 
                          `ean13`     ,`upc`           , `ecotax`         , `quantity`           , `minimal_quantity`, `price`             , `wholesale_price`, `unity`      ,
                           `reference`,`supplier_reference`, `location`   , `width`              , `height`          , `weight`            , `out_of_stock`   ,  `customizable`, 
                           `active`   ,`redirect_type` ,`available_for_order`, `available_date`  , `condition`       , `show_price`        , `indexed`        , `visibility`  ) VALUES
                         (v_product_id,    v_model     ,          1       ,                2     ,         1         ,  1                  ,      1           ,      1       , 
                            v_sku     , v_upc          , 0.000000         , v_quantity           , 1                 , v_price             , 0.000000         ,     ''       ,
                            v_model   , ''             , ''               , v_width              , v_length          , 100.000000          , 2                ,    0         ,  
                            1         , '404'          ,  1               , '0000-00-00'         , 'new'             , 1                   , 1                ,  'both'     );
 
INSERT INTO `ps_product_shop` (`id_product`, `id_shop`, `id_category_default`, `id_tax_rules_group`, `on_sale`, `online_only`, `ecotax`, `minimal_quantity`, `price`, `wholesale_price`, `unity`, `unit_price_ratio`, `additional_shipping_cost`, `customizable`,  `text_fields`, `active`, `redirect_type`, `id_product_redirected`, `available_for_order`, `available_date`, `condition`, `show_price`, `indexed`, `visibility`,  `date_add`, `date_upd`) VALUES
                              (v_product_id, 1        ,               2      ,      1              ,    1     ,      1       , 0.000000,         1         , v_price,          0.000000,     '' , 0.000000          ,          0.00             ,    0          ,    0          ,    1    , '404'          , 0                      , 1                    , '0000-00-00'    , 'new'      , 1           ,        1 , 'both'     ,  '2014-02-08 17:03:30', '2015-02-12 14:55:54');
 
 
 
INSERT INTO `ps_product_lang` (`id_product`, `id_shop`, `id_lang`, `description`, `description_short`, `link_rewrite`, `meta_description`, `meta_keywords`, `meta_title`, `name`) VALUES
                              (v_product_id, 1        ,     4    , v_description , v_meta_description, ''            , ''                , ''             , 'El Titulo' , v_name);
 
 
INSERT INTO `ps_image` (id_product,POSITION,cover) VALUES 
                       (v_product_id    , 1                     ,           1) ;
 
 
 
INSERT INTO `ps_image_lang`(`id_image`, `id_lang`, `legend`) SELECT MAX(ID_IMAGE),4,'' FROM ps_image;

Bien, pues si has visto todo esto, solo tienes que montar tu propio Script con los datos de tu tienda y ejecutarlo en tu base de datos.
Creo que se entiende muy bien, y si tienes conocimientos de bases de datos y SQL pues facilmente migrarás los datos de tu Opencart a Prestashop.

Consideraciones para migrar Opencart a Prestashop

Consideraciones a tener en cuenta, pues está hecho para una tienda Opencart en un idioma, por eso están puestos los números de idiomas a fuego en el código, por lo que si tienes varios idiomas tendrás que modificar el Script.

El id_product no te hace falta ponerlo como lo he hecho yo, debería ser una variable que vaya cambiando cuando se va añadiendo un producto, aunque yo los he puesto a fuego en el código y como no tengo problemas por ello, ya que comprobé anteriormente que ningún id_product se pisaba con otro.

Te dejo el Script entero aquí, para descargártelo solo tienes que hacer click en una acción social. Gracias.

[sociallocker]

 
 
DROP PROCEDURE IF EXISTS OpencartToPrestashop;
DELIMITER $$
CREATE PROCEDURE OpencartToPrestashop (
) 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;
 
-- Limpiamos las tablas anteriores de la instalación prestashop
   DELETE FROM `ps_product` WHERE ID_PRODUCT>18;
   DELETE FROM `ps_product_lang` WHERE ID_PRODUCT>18;
   DELETE FROM `ps_image` WHERE ID_IMAGE>50;
   DELETE FROM `ps_image_lang` WHERE ID_IMAGE>50;
   DELETE FROM `ps_product_shop` WHERE ID_PRODUCT>18;  
 
 
  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
 
INSERT INTO `ps_product` (`id_product`, `id_supplier`  , `id_manufacturer`, `id_category_default`, `id_shop_default` , `id_tax_rules_group`, `on_sale`        , `online_only`, 
                          `ean13`     ,`upc`           , `ecotax`         , `quantity`           , `minimal_quantity`, `price`             , `wholesale_price`, `unity`      ,
                           `reference`,`supplier_reference`, `location`   , `width`              , `height`          , `weight`            , `out_of_stock`   ,  `customizable`, 
                           `active`   ,`redirect_type` ,`available_for_order`, `available_date`  , `condition`       , `show_price`        , `indexed`        , `visibility`  ) VALUES
                         (v_product_id,    v_model     ,          1       ,                2     ,         1         ,  1                  ,      1           ,      1       , 
                            v_sku     , v_upc          , 0.000000         , v_quantity           , 1                 , v_price             , 0.000000         ,     ''       ,
                            v_model   , ''             , ''               , v_width              , v_length          , 100.000000          , 2                ,    0         ,  
                            1         , '404'          ,  1               , '0000-00-00'         , 'new'             , 1                   , 1                ,  'both'     );
 
INSERT INTO `ps_product_shop` (`id_product`, `id_shop`, `id_category_default`, `id_tax_rules_group`, `on_sale`, `online_only`, `ecotax`, `minimal_quantity`, `price`, `wholesale_price`, 
                               `unity`, `unit_price_ratio`, `additional_shipping_cost`, `customizable`,  `text_fields`, `active`, `redirect_type`, `id_product_redirected`,
                               `available_for_order`, `available_date`, `condition`, `show_price`, `indexed`, `visibility`,  `date_add`, `date_upd`) VALUES
                              (v_product_id, 1        ,               2      ,      1              ,    1     ,      1       , 0.000000,         1         , v_price,      
                              0.000000,     '' , 0.000000          ,          0.00             ,    0          ,    0          ,    1    , '404'        ,          0   , 
                              1                    , '0000-00-00'    , 'new'      , 1           ,        1 , 'both'     ,  '2014-02-08 17:03:30', '2015-02-12 14:55:54');
 
 
INSERT INTO `ps_product_lang` (`id_product`, `id_shop`, `id_lang`, `description`, `description_short`, `link_rewrite`, `meta_description`, `meta_keywords`, `meta_title`, `name`) VALUES
                              (v_product_id, 1        ,     4    , v_description , v_meta_description, id_product    , v_meta_description, v_meta_keyword , v_custom_title, v_name);
 
 
INSERT INTO `ps_image` (id_image    , id_product      ,POSITION,cover) VALUES 
                       (v_product_id, v_product_id    , 1      ,  1) ;
 
 
--INSERT INTO `ps_image_lang`(`id_image`, `id_lang`, `legend`) SELECT MAX(ID_IMAGE),4,v_name FROM ps_image;
INSERT INTO `ps_image_lang`(`id_image`, `id_lang`, `legend`) VALUES
                             (v_product_id, 4    , v_name);
 
--SELECT MAX(ID_IMAGE),4,v_name FROM ps_image;                         
 
  END LOOP bucle;
 
  CLOSE OpencartByeBye;
END$$
DELIMITER ;

[/sociallocker]

Si tienes cualquier duda deja un comentario y te las intento resovler 🙂

Si todo esto te parece un jaleo, y quieres migrar tu tienda de Opencart a Prestashop, o quieres contactar con nosotros puedes hacerlo desde aquí.

Cómo todo este proceso no va a acabar aquí, ya que siempre encontraré cosas que mejorar, iré actualizando este post, para que se migren también las imágenes de los productos y se renombren tal y como Prestashop lo hace.

Por último, si te ha parecido útil y quieres ayudarme con la web y así poder seguir liberando código, me gustaría que me dieses un +1 en Google plus Gracias!!