Results 1 to 10 of 11

Hybrid View

  1. #1
    Join Date
    Aug 2005
    Location
    Vic, Oz
    Posts
    1,905
    Plugin Contributions
    5

    Default Mass unlink all Categories from one particular category

    On one store I manage
    When products are sold out I "disable" them
    They are "moved" to a particular "disabled" category for storage
    This changes their "master categories id" to this storage category
    I would then like to "unlink" all other categories from products in this category
    I can do this for particular categories, category by category in Multiple Categories Link Manager

    Can anyone suggest a sql to do this in one go?

  2. #2
    Join Date
    Jul 2012
    Posts
    16,816
    Plugin Contributions
    17

    Default Re: Mass unlink all Categories from one particular category

    Sounds like this "move" process doesn't move the product to a new category so much as link it to the category. I say that because if it were truly moved, there should be no remnant/reference of the product to a previous category.


    The table that contains the information I think you are trying to remove is the products_to_categories table.
    Thinking:
    Code:
    delete from products_to_categories where products_id in (select products_id from products_to_categories where categories_id=15) and categories_id != 15;
    Where the categories_id of the "disabled" category is 15.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  3. #3
    Join Date
    Aug 2007
    Location
    Gijón, Asturias, Spain
    Posts
    2,826
    Plugin Contributions
    31

    Default Re: Mass unlink all Categories from one particular category

    I think this mod will do it:
    http://www.zen-cart.com/showthread.p...py-Move-Delete

    and this has also some useful features along the same lines:
    http://www.zen-cart.com/showthread.p...Manager-Sorted

    and yes I think they should both be added to the core!
    Steve
    github.com/torvista: BackupMySQL, Structured Data, Multiple Copy-Move-Delete, Google reCaptcha, Image Checker, Spanish Language Pack and more...

  4. #4
    Join Date
    Aug 2005
    Location
    Vic, Oz
    Posts
    1,905
    Plugin Contributions
    5

    Default Re: Mass unlink all Categories from one particular category

    Quote Originally Posted by mc12345678 View Post
    Sounds like this "move" process doesn't move the product to a new category so much as link it to the category. I say that because if it were truly moved, there should be no remnant/reference of the product to a previous category.


    The table that contains the information I think you are trying to remove is the products_to_categories table.
    Thinking:
    Code:
    delete from products_to_categories where products_id in (select products_id from products_to_categories where categories_id=15) and categories_id != 15;
    Where the categories_id of the "disabled" category is 15.
    No the "move" moves the master_categories_id from where it is now to the specified category. Other linked categories remain the same.

    Your code inspired me but would not work as written, had to create an alias before it worked :)
    Code:
    delete from products_to_categories
    where products_id 
    in (select * from 
          (select products_id 
           from products_to_categories 
           where categories_id=15) 
        as old_table) 
    and categories_id != 15;
    If run from the admin you need to add the table prefix to the second instance of the table reference.
    If run from phpmyadmin you need to add the table prefix to both instances of the table reference.





    Quote Originally Posted by torvista View Post
    This is one of my favorite "must have" mods but unfortunately won't do what I need in this case

    Quote Originally Posted by torvista View Post
    and this has also some useful features along the same lines:
    http://www.zen-cart.com/showthread.p...Manager-Sorted

    and yes I think they should both be added to the core!
    I have never tried this but will check it out.

    Thanks to you both.
    Last edited by gilby; 14 Nov 2014 at 01:27 PM.

  5. #5
    Join Date
    Jul 2012
    Posts
    16,816
    Plugin Contributions
    17

    Default Re: Mass unlink all Categories from one particular category

    Well the reason I stated that it doesn't completely move the product is evidenced by the issue being encountered as a change of master_category_id doesn't fully move the product away from it's current category otherwise the issue encountered wouldn't occur.

    Interesting the difference in implementation needed for the SQL. The provided SQL works in a $db->Execute() without an additional temporary table. Glad it worked though. (Known to work as have used in further development of Stock By Attributes.)
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  6. #6
    Join Date
    Aug 2005
    Location
    Vic, Oz
    Posts
    1,905
    Plugin Contributions
    5

    Default Re: Mass unlink all Categories from one particular category

    Quote Originally Posted by mc12345678 View Post
    Interesting the difference in implementation needed for the SQL. The provided SQL works in a $db->Execute() without an additional temporary table. Glad it worked though. (Known to work as have used in further development of Stock By Attributes.)
    I didn't try it as part of a php file
    I ran it as a sql file
    I will keep that in mind if I need to add to my website code

 

 

Similar Threads

  1. how do mass delete all products from one manufacturer?
    By alibaba99 in forum Setting Up Categories, Products, Attributes
    Replies: 18
    Last Post: 17 Feb 2013, 09:36 AM
  2. Replies: 68
    Last Post: 4 Feb 2011, 09:38 PM
  3. Replies: 0
    Last Post: 10 Nov 2010, 11:52 AM
  4. Code to show all categories on a particular category page?
    By davemehta in forum General Questions
    Replies: 3
    Last Post: 5 Jul 2010, 07:45 PM
  5. All Zones EXCEPT particular one
    By PJD in forum Built-in Shipping and Payment Modules
    Replies: 0
    Last Post: 25 Apr 2008, 07:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg