Search code examples
pythondjangodjango-oscardjango-import-export

oscarcommerce catalogue import


I have a magento2 project. I want to import product catalog in magento 2 into django oscarcommerce. The official documentaion explains an importer (http://django-oscar.readthedocs.io/en/releases-1.1/howto/importing_a_catalogue.html). But that they are not supporting because its buggy. I tried to figure out how it works. But I couldn't find the source csv file to test with.

Is there any module/scripts which convert data in magento2 to oscar commerce? I checked This thread, but didn't get any idea about it.


Solution

  • It's not too difficult to write custom importer code if you check the source code for the django-oscar importer. I have done this myself, and here are the most important steps:

    1/ Get or create a ProductClass instance

    product_class = ProductClass.objects.get_or_create(name='<some_name>')
    

    2/ Create a category string for your next product. This string is in the format 'main_category>sub_category>even_deeper_category'. Eg: 'Books>Fiction>Thriller'

    category_string = create_from_breadcrumbs('some>string>here')
    

    3/ Create your product

    product = Product.objects.get_or_create(upc=upc)
    
    product.product_class = product_class
    product.title = ...
    ...
    
    product.save()
    

    4/ Update ProductCategory for this new product (it is made out of a category string and a product)

    ProductCategory.objects.update_or_create(product=product, category=category_string)
    

    5/ Next you need to update Partner info (every product needs a Partner record, this is where the pricing info is stored). If you create the products yourself and don't use partners, just make up some random name.

    partner = Partner.objects.get_or_create(name='Partner_Name')
    
    importer = CatalogueImporter(logger=None)
    
    importer._create_stockrecord(
            item=product,
            partner_name=partner.name,
            partner_sku='ProductReferenceFromPartner'>,
            price_excl_tax=<SELLING_PRICE>,
            num_in_stock=<STOCK_COUNT>,
            stats=None
            )
    

    You can check my source code here, but some of it is in Dutch. You can always ask me if you have any questions. I am also using a csv file to populate my database, through a custom Django management command.