update category programmatically from csv using magento

update category programmatically from csv using magento

In this post we will show you update category programmatically from csv using magento, hear for update category programmatically from csv using magento we will give you demo and example for implement.

how to update category programmatically in csv using magento

we will show you how to update category programmatically from csv using magento. For update category programmatically in csv using magento you need this code.

<?php
// if call is come form external file
set_time_limit(0);
ini_set('memory_limit','1024M');
require_once '../app/Mage.php';
Mage::app();

//read data from csv file
$row_count = 1;
$categorys_arr = array();
if (($handle = fopen("categorys.csv", "r")) !== FALSE)
{
while (($datas = fgetcsv($handle, 1000000, ",")) !== FALSE)
{
if($row_count > 1)
{
// $datas[0] is csv column in csv file
// $datas[1],$datas[2],$datas[3],$datas[4] is category Id column
$categorys_arr[trim($datas[0])] = $datas[1].",".$datas[2].",".$datas[3].",".$datas[4].",".$datas[5].",".$datas[6].",".$datas[7];
}

$row_count++;
}
fclose($handle);
}

$products = Mage::getResourceModel('catalog/product_collection');
$i = 1 ;
foreach ( $products as $product_model )
{
$_product = Mage::getModel('catalog/product')->load($product_model->getId());
$cnid = $categorys_arr[$_product->getSku()];
$get_ids = explode(",",$cnid);
$_product->setCategoryIds($get_ids);
$_product->save();
$i++;
}

echo "update category programmatically from csv using magento added successfully ";
?>

Hope this code and post will helped you for implement update category programmatically in csv using magento. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve onlincode. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs onlincode.org

Leave a Comment

Your email address will not be published. Required fields are marked *

  +  82  =  90

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US