Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Migrating products data from opencart to magento

I have a opencart based shopping cart site..

Now I would like to convert it into a magento site..

I've done a fresh magento installation. Now i need to migrate the data from my opencart database to new magento database

So can anyone give me the table names and tell me what are the things i should do for successful migration?

Thanks

like image 540
Giri Avatar asked Jul 30 '12 16:07

Giri


1 Answers

First of all

Assess what you want to import to Magento. The clearer that qestion is answered, the easier it will be to evaluate your options.

Basically, these options include importing data via the built in import (the built-in way), importing data via a custom script (the script way), importing data via plain SQL (the terrible, terrible SQL way) and importing via external modules (the module way).


The built in way

First of all, you may import csv data via the backend, if you can bring your opencart based products/customers in a CSV format, which can then be reimported in the backend - see here or here (just products).

This solution depends on the fact how you can export data from open cart, which i am frankly no expert in. As long as you can export to XLS, CSV or similar, you should be fine.

The script way

If you cannot do that, I would advise writing an import script using Magento's own models. A very basic snippet to get you started:

<?php
//place this file in the Magento root, e.g. ./import.php, "." being you Magento root
//load the magento app with the admin store 
require_once('app/Mage.php');
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);

//data import, I assume you can write some sort of input for this $data like reading a zip file or some other format, i here, I assume, this $data array holds arrays of products ($new_product) containing information on a product from open cart
$data = ...

// loop over the data and create the Magento models, these can include products, customers, etc. - for simplicity this is done for products, but can be done for every other data object in magento
foreach ($data as $new_product) {
    //load an empty Magento product model
    $product = Mage::getModel('catalog/product');

    //set the attributes you want
    $product->setData('sku', $new_product['sku']);
    $product->setData('name', $new_product['name']);

    .
    .
    . 
    //save it
    try {
        $product->save();
    }
    catch(Exception $e) {
        Mage::logException($e);
        continue;
    }
}

This is an example utilizing Mage_Catalog_Model_Product, other data types could be Mage_Sales_Model_Order for orders or Mage_Customer_Model_Customer for customers. I can recall the code for some data object instantiation calls in the Magento-style from memory:

  • Mage_Catalog_Model_Product can be instantiated as Mage::getModel('catalog/product')
  • Mage_Catalog_Model_Category can be instantiated as Mage::getModel('catalog/category')
  • Mage_Customer_Model_Customer can be instantiated as Mage::getModel('customer/customer')
  • Mage_Sales_Model_Order can be instantiated as Mage::getModel('sales/order')

These calls can be looked for in the corresponding core modules - sometimes they vary across different Magento versions.

You can find them out by looking into ./app/code/core/Mage/ and look through the modules' Model folders, where you may find the classes above in the folder-based naming conventions, e.g. Mage_Catalog_Model_Product maps to ./app/code/core/Mage/Catalog/Model/Product.php.

A model usually has an init method called _construct (which is not PHP's __construct!) which defines the string a model may be instantiated with via Mage::getModel().

A more complete description for importing products can be found here. The style almost always stays the same across data objects in Magento.

This is the more lengthy option, but you can learn a great deal of Magento's internal data handling. Also, you do not neccessarily need to know the datatables in the background.

The're is a lot of help on the topic also in the Magento knowledgebases. Again, if you want to learn Magento, this is a good way to start.

The SQL way

You can also do plain SQL to fill Magento's tables.

Don't do that. You'll find yourself writing SQL for every other Magento version, if you do it via a script, do it via the framework Magento provides.

The module way

There are some modules we used in the past for importing larger amounts of data, as the script method I showed above is not very efficient for big amounts of data. I am not sure if some of those are actively maintained, but it's a good idea to poke around in Magento Connect. Depending on what you use, these modules may not be free of charge to you.

Final thoughts.

I would really advise you to built a custom script as it is a great way to learn Magento. If you do not care for programming, you should have a look in to the built-in importer.

If any further questions remain, ask away :)

like image 57
Florian Avatar answered Nov 03 '22 02:11

Florian