I need to remove Multiple Assigned Categories of products remove from selected Category. Eg. Product1 assigned to cat1, cat2, cat3. I need my product remove from the category cat3. How can I do it by CSV or MYSQL

  • 1
    please use csv for that. Dec 12, 2017 at 12:01

3 Answers 3


You can do it by creating csv file as below

sku , categories

test1, 1|3

test2 , 2|3

and then you can create file on magento root folder with below code

require_once 'app/Mage.php';


$file = fopen('product_rename1.csv', 'r'); // file path of csv
$all_rows = array();
$header = null;
while ($row = fgetcsv($file)) {
    if ($header === null) {
        $header = $row;
    $all_rows[] = array_combine($header, $row);

// above code used to convert csv to array

foreach ($all_rows as $row) {
    $product = Mage::getModel('catalog/product')->loadByAttribute('sku',$row['sku']);
    $categories = explode('|', $row['categories']);

Zus, follow the instructions in this page:


If you need to remove the category, just specify the one you want the product in only (cat3 in the _category field).

I would test with a single product before uploading the entire catalogue just to confirm it works ok.

  • i need, supposed the sku -> cat1, cat2, cat3. I need to remove cat2, but retain cat1 and cat3, how can i do like this.
    – zus
    Dec 12, 2017 at 12:32
  • 1
    Review the link I shared - specifically the part where it shows the excel sheet half way down the page. You will notice that categories will be on separate rows in _category column. In this case you would have the cat1 and ca3 on separate rows, and cat2 should be removed. If you follow the instructions and do an export of your catalogue - then delete all but a couple of products and delete some of the category rows you will be able to confirm that it is working OK before updating all products.
    – BAF
    Dec 12, 2017 at 12:36

Import the .csv file without the remove category. For Example, the csv file columns will be sku => sku and category_ids => cat1,cat2(These category Ids).

  • In my case, i need to remove cat2, but retain cat1. How can i do this.
    – zus
    Dec 12, 2017 at 12:31
  • 1
    Import only cat1, then it will assign only for cat1. Other categoies are unassigned Dec 12, 2017 at 12:33
  • okay, let me check
    – zus
    Dec 12, 2017 at 12:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.