Results 1 to 6 of 6
  1. #1
    Join Date
    Aug 2007
    Location
    St. Louis
    Posts
    110
    Plugin Contributions
    0

    Default SQL Help - Need To Change Product Type

    Hello,

    I need to run a periodic SQL query which updates the 'product type' for all items that have a specific 'category_id'.

    Here's where my abbreviated thinking takes me...

    UPDATE products SET products_type ='3' WHERE category_id = '9'

    This would work but the 'products' table does not have 'category_id' as a field. The one table I can find which has both (and only) 'product_id' AND 'category_id' is 'products_to_categories'.

    I ASSume that I have to somehow incorporate 'products_to_categories' in the query to tie 'category_id' to 'products' to achieve what I need?

    Thanks

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

    Default Re: SQL Help - Need To Change Product Type

    Um ... what you're doing is VERY dangerous.

    Changing product types just because you can change the number in one of the many related database tables can cause you to end up with data seriously out of sync -- especially if you're switching it between product types which have additional field data which needs to be collected for them.

    Nevertheless, I'm sure you've got a reason why you're convinced that what you're doing is acceptable. Thus, yes, you need to incorporate the products_to_categories table as well.
    .

    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
    Aug 2007
    Location
    St. Louis
    Posts
    110
    Plugin Contributions
    0

    Default Re: SQL Help - Need To Change Product Type

    Ahhh... I very glad that you replied to this thread. First, I'll explain the reason I think I want to be able to do this...

    I'm working on a site which has both items for sale (products_type 1) and a 'gallery' of the site owner's personal items he wishes to display (Document - General/product_type 3)

    I'm using Easy Populate to add the 'items for sale' just fine however when I use it to populate the one and only category that is set to 'Document General' it forces the items as a product_type 1. Even though the category is set to clearly limit all items to 'Document General' it does not when using EP, in other words they appear 'for sale' which is exactly what I don't want. (If I add them manually it's fine)

    Soooo... I logged into phpMyAdmin and changed ONE of the item's product_type from 1 to 3 and it then looked fine on the front end. I thought just writing a simple query would be quicker?

    I would MUCH rather find a way to have it import correctly or at the very least have the items listed as product_type 1 and somehow trick it into looking like they aren't for sale as opposed to horsing with the database directly but I can't find any other way.

    Thanks for any help.

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

    Default Re: SQL Help - Need To Change Product Type

    You could rewrite EP to add support for a v_products_type field, but that's not exactly an easy task.



    *** FOR FUTURE READERS OF THIS THREAD ... I recommend that you be *VERY* sure that you understand all of what you're doing if you are messing around with this. ***

    In the case of products_type=1 and products_type=3, the structures are the same, and don't rely on extra fields in other tables (unless you've customized either of those product types in that way).
    Thus it's relatively safe to "just change" the products_type setting in *that* case.

    The SQL to do it manually would be:
    Code:
    UPDATE products p, products_to_categories ptc 
    SET products_type=3
    WHERE p.products_id = ptc.products_id 
    AND categories_id = 9;
    .

    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
    Aug 2007
    Location
    St. Louis
    Posts
    110
    Plugin Contributions
    0

    Default Re: SQL Help - Need To Change Product Type

    Hey there,

    Thank you very much. I was pretty sure under my specific circumstances that updating that field would be okay but I really didn't know.

    I'd love to know how to add the product_type to EP but that eclipses my knowledge. Seems like a handy thing to have doesn't it?

    Anyway thanks again :)

  6. #6
    Join Date
    Dec 2008
    Posts
    1
    Plugin Contributions
    0

    Default Re: SQL Help - Need To Change Product Type

    So, is there a way to use EP to update Document-General type, without hacking it? Pl. advise

    kiran

 

 

Similar Threads

  1. v139h Need help undoing this SQL change
    By StoreOwner in forum General Questions
    Replies: 10
    Last Post: 27 Dec 2014, 04:22 PM
  2. v1.5.1 Desperately need help installing Auction Product Type
    By tamber56 in forum Templates, Stylesheets, Page Layout
    Replies: 1
    Last Post: 23 Oct 2012, 10:24 AM
  3. Need help to SQL change the Product Add Date
    By explorer1979 in forum General Questions
    Replies: 2
    Last Post: 1 Sep 2012, 03:22 PM
  4. Sql Error using product book type
    By yosemirza in forum Setting Up Categories, Products, Attributes
    Replies: 0
    Last Post: 16 Nov 2009, 12:31 PM
  5. need help with new product type for download images
    By ashishgandhi in forum Setting Up Categories, Products, Attributes
    Replies: 11
    Last Post: 19 Feb 2008, 10:18 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