Tuesday, 27 May 2014

Import Position field from csv in magento


Import Position field from csv in magento

Go to app\code\core\Mage\Catalog\Model\Convert\Adapter\Product.php

First put this file on your local path then open it.

Fine the line unset($importData[$field]); in public function saveRow then comment it out like below

//unset($importData[$field]);

Now put the below code in SaveRow function exact after $product->save(); line

if($importData['category_ids']):

$catId = explode(",",$importData['category_ids']);
$write = Mage::getSingleton('core/resource')->getConnection('core_read');
foreach($catId as $_catId):
$write->query('update catalog_category_product set position = "'.

$importData['position'].'" where category_id = "'.$_catId.'" and product_id = "'.$product->getId().'"');
endforeach;
endif;



Make position field in your csv file and give the sorting number as per your choice and import it....


Thats it.. Enjoy Chandresh rana's Coding.... :)

3 comments:

Anonymous said...

I've tested this code, and it's not working for me

Anonymous said...

Hello...
i tried it and it worked for me....Great solution..Keep posting .Thanks a lot.

Link McGinnis said...

This was exactly what I was looking for and seems no one else has this solution.

But, it seems to have no effect when I import my csv file with "position" field added.

I wondered if you might be able to help figure out why it isn't working.

Things I've tried:
1. Edited directly in Mage to make sure it wasn't a problem with the local being active.
2. changed name of "position" to "_position" and "Position". Both failed the import check indicating that the "position" column is correct.
3. Our csv file has nested categories such as "Gifts/Pictures". The csv file doesn't have category_ids.
4. Cache is turned off.
5. Reindexing after each import.

What am I missing?!
Thanks,