Page 1 of 2 12 LastLast
Results 1 to 10 of 14
  1. #1
    Join Date
    Apr 2010
    Posts
    897
    Plugin Contributions
    0

    Default SQL Patch question - help please!

    Hi,

    I have a huge # of products (too many to do manually) that need to be moved to new categories. I will then go back and delete the old categories, there are about 40 categories that need to go.

    Can somebody show me how I could write a little script I could send thru the SQL Patch that would change the Category ID for all prod in a specific category to a different Category ID?

    And maybe a second script that would erase the soon to be empty categories?

    ++++
    My preference would be to search the product DB and do like a Find/Replace.
    FIND: Category ID xxx
    REPLACE WITH: Category ID yyy

    It would be lovely if I could wrap numerous Find/Replace strings into a single statement! If you did a sample that changed 2, I could replicate the syntax to get them all done in one shot.
    ++++

    ++++
    Alternatively, I have all my Product IDs. So if, because of table relationships, it was necessary to lookup the product first, then alter the associated Category ID, that would work, too. A bit messier, but it could be done, np. Again, if your sample showed how to change 2, I could replicate your syntax to do all the products.
    ++++

    Thank you in advanced! I'm totally desperate here, back against the wall with a huge deadline. I really appreciate you looking at this for me!

    Thanks,
    Mike

  2. #2
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: SQL Patch question - help please!

    First, if the category you're wanting to move all these products to DOES NOT YET EXIST, you can just move that category to another parent, and rename it if necessary. Bam, done!

    But if the destination category already exists and its category-id is important to retain as-is, then you'll need something more complex, like the following:

    The category is stored in a couple ways:
    1. In the products table there is the master_categories_id ... which basically says which primary/main category the product belongs to
    2. And in the products_to_categories table there is an entry for EVERY Product + Category relationship. So if a product appears in multiple categories (ie: is linked to more than one category) then there will be multiple entries in this table, one for each product+category combination.

    So, before doing such a mass change, you need to first make sure that the products whose categories you want to make mass changes to are NOT ALREADY "linked" to the destination category you intend to move them to.
    One way to do that is to use your Admin and go to that destination category and check whether any of the "linked" products (denoted by the yellow bubble) show there. If they are, then you may want to manually change those by using your Admin to edit that product and change its master and then unlink it (delete it from the other category).

    Once your inspection confirms that none of those products are already linked to the destination category, you can do something like the following to MASS MOVE products out of one category and into another;
    Code:
    update products_to_categories set categories_id=NEWNUMBER where categories_id=OLDNUMBER;
    update products set master_categories_id=NEWNUMBER where master_categories_id=OLDNUMBER;
    You'll get duplicate-key errors if you run that first statement and it finds any of those products already linked to the new category.

    Then go and manually delete the empty/obsolete categories using your Admin screen. It's better to do this from your Admin because it does more than just SQL cleanup (ie: also cleans up images, descriptions, languages, related restrictions, and more).
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  3. #3
    Join Date
    Apr 2010
    Posts
    897
    Plugin Contributions
    0

    Default Re: SQL Patch question - help please!

    Yippee, thanks Doc!

    I just double checked, no linked products. In every case, I will simply be moving products up one level (combining 10 or so subcategories at a time into single higher category). The categories already exist, but I could easily create new categories, then rename them after I have deleted the originals if you think that's the best way to do it. But I'm unclear how to accomplish that... though your summary is very appealing (Bam, done!)!

    On the other hand, your mass move instructions seem pretty simple, too. Can I just string a bunch of them together like and past them into the SQL patch like this:
    Code:
    update products_to_categories set categories_id=NEWNUMBER where categories_id=OLDNUMBER;
    update products set master_categories_id=NEWNUMBER where master_categories_id=OLDNUMBER;
    update products_to_categories set categories_id=NEWNUMBER where categories_id=OLDNUMBER;
    update products set master_categories_id=NEWNUMBER where master_categories_id=OLDNUMBER;
    update products_to_categories set categories_id=NEWNUMBER where categories_id=OLDNUMBER;
    update products set master_categories_id=NEWNUMBER where master_categories_id=OLDNUMBER;

  4. #4
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: SQL Patch question - help please!

    Quote Originally Posted by Feznizzle View Post
    In every case, I will simply be moving products up one level (combining 10 or so subcategories at a time into single higher category). The categories already exist, but I could easily create new categories, then rename them after I have deleted the originals if you think that's the best way to do it. But I'm unclear how to accomplish that... though your summary is very appealing (Bam, done!)!
    "combining" categories can't be done by the simple "move" I was talking about above.

    Quote Originally Posted by Feznizzle View Post
    On the other hand, your mass move instructions seem pretty simple, too. Can I just string a bunch of them together like and past them into the SQL patch like this:
    Code:
    update products_to_categories set categories_id=NEWNUMBER where categories_id=OLDNUMBER;
    update products set master_categories_id=NEWNUMBER where master_categories_id=OLDNUMBER;
    update products_to_categories set categories_id=NEWNUMBER where categories_id=OLDNUMBER;
    update products set master_categories_id=NEWNUMBER where master_categories_id=OLDNUMBER;
    update products_to_categories set categories_id=NEWNUMBER where categories_id=OLDNUMBER;
    update products set master_categories_id=NEWNUMBER where master_categories_id=OLDNUMBER;
    Yes.

    Here's hoping Ajeh doesn't tell me otherwise!
    But she's offline today, so we'll have to play without her.

    Of course, always make backups before doing these kinds of things!
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  5. #5
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: SQL Patch question - help please!

    Addendum: After doing this, if you have any pricing features (discounts, sales, specials, etc) specific to the categories you're moving "from" or "to" (or the parents under which they are found), then you'll want to use the Store Manager screen to "Update All Products Price Sorter" so that it recalculates pricing cache data for searches and sorts. Otherwise product price info may be outdated on the storefront.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  6. #6
    Join Date
    Apr 2010
    Posts
    897
    Plugin Contributions
    0

    Default Re: SQL Patch question - help please!

    None of the products are subject to category specific features. However, all have qty based discounting and most have cross sells attached to them. Doesn't *seem* like any of that will be effected.

    Of course, always make backups before doing these kinds of things!
    Haha. Man, I should earn frequent flyer miles on your Backup mySQL mod, as heavily as I lean on that thing!

  7. #7
    Join Date
    Apr 2010
    Posts
    897
    Plugin Contributions
    0

    Default Re: SQL Patch question - help please!

    Worked like a charm, DrByte! Thank you so much!!!

    Now I'm just hoping Ajeh doesn't come back and say this did terrible damage to the db! hahaha

  8. #8
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: SQL Patch question - help please!

    I asked her to double-check, and she said I did good.

    Plus I double-checked the actual PHP code that handles that stuff for one-off cases in the admin ;)
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  9. #9
    Join Date
    Apr 2010
    Posts
    897
    Plugin Contributions
    0

    Default Re: SQL Patch question - help please!

    Never a doubt in my mind. Thanks again, Chris!

  10. #10
    Join Date
    Apr 2010
    Posts
    897
    Plugin Contributions
    0

    Default Re: SQL Patch question - help please!

    NEW QUESTION:

    I'm trying to remove some problems by doing a find/replace. Is this correct?

    Code:
    	update categories_description set categories_name = REPLACE( `categories_name` ,  '&',  '&' )

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. v139h Upload SQL Patch via phpMyAdmin in MySQL INSTEAD OF Amin-Tools-Install AQL patch ????
    By shags38 in forum Customization from the Admin
    Replies: 11
    Last Post: 20 Aug 2012, 04:19 AM
  2. v139h SQL question... help please!
    By Feznizzle in forum General Questions
    Replies: 4
    Last Post: 3 Mar 2012, 10:31 PM
  3. SQL Patch Help
    By seeinteriors in forum All Other Contributions/Addons
    Replies: 1
    Last Post: 24 Jan 2012, 04:34 PM
  4. Product listing - colunms sql patch help
    By viatell in forum Templates, Stylesheets, Page Layout
    Replies: 0
    Last Post: 5 Jun 2009, 04:26 PM
  5. Application of SQL Patch question
    By brad512 in forum Upgrading from 1.3.x to 1.3.9
    Replies: 4
    Last Post: 17 Sep 2006, 12:52 AM

Bookmarks

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
Zen-Cart, Internet Selling Services, Klamath Falls, OR