3

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

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';
umask(0);
Mage::app();


Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);


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

// 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']);
    $product->setCategoryIds($categories);
    $product->save();
}
0

Zus, follow the instructions in this page:

https://trellis.co/blog/uploading-products-magento-product-excel/

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 '17 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 '17 at 12:36
0

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 '17 at 12:31
  • 1
    Import only cat1, then it will assign only for cat1. Other categoies are unassigned – Ranipriyanka Dec 12 '17 at 12:33
  • okay, let me check – zus Dec 12 '17 at 12:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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