Where, in zencart, are the calculations done for making the, ## of ## active, display next to the green/red buttons in admin/categories? That is the info I need to make a simple MySQL code work for this issue.
I've posted the post below at stackoverflow to try and help find a solution as well...http://stackoverflow.com/questions/17518068/change-category-status-to-0-in-zencart-when-all-products-in-a-category-are-zero
First off, let me say I am a NOVICE MySQL programmer. I appreciate any help I can get.
I am trying to update a record value in one table where the count of records in a separate table are equal to the count of records in another table where a certain criteria is met.
In real language: Within a specific category, if all of the products_status, in table products, are set to 0 (not active), then I want to set the category_status, in table category, to 0 (hidden).
I'll explain my thought process after I give you a little background info.
The relevant parts of my categories table are: categories_id (unique and autoincremented) categories_status (0 or 1) parent_id
The relevant parts of my products table are: products_id (autoincremented) products_status (O or 1) master_categories_id (I believe it is linked to the categories_id column n the categories table)
The products_to_categories table has two columns: products_id categories_id
Now, this is what I am attempting:
-
Go to the first record of categories.categories_id and set that as a variable (CategorySearchID).
-
Go to products.master_categories_id and count the number of records that match the CategorySearchID and set that to a variable (CategorySearchIDCount). This gives the total number of products in that CategorySearchID.
-
Go to products.products_status and count all records that have a product_status of 0 where the CategorySearchID is a match.
-
Compare the counts in step 2 and 3. If they are equal, the categories.category_status for the current CategorySearchId will be set to 0 (hidden).
-
Finally, I need a loop that will search through all categories.category_id (CategorySearchID) and do the count comparisons and status updates in steps 2, 3 and 4.
I have tried dozens of combinations of the following code but keep getting errors. I can get some of the individual element of the code to work but I can't seem to tie them all together.
For example:
UPDATE DATABASE.categories SET categories_status = 0
Sets all category_status' to 0 successfully
SELECT COUNT(products_id) FROM products WHERE products_status=0
Finds all of the products_status' set to 0 and returns the number in a temporary table.
AND parent_id != 0;
Prevents top level categories from being set to hidden
I'm not going to bore you with all of the combinations I've tried.
Again, I really would appreciate any help!
Mike