Forums / General Questions / For the sake of learning, How could I update a products quantity via the SQL Database

For the sake of learning, How could I update a products quantity via the SQL Database

Views: 1,225

Results 1 to 8 of 8
11 Feb 2023, 10:24 PM
#1
spanky avatar

spanky

New Zenner

Join Date:
May 2021
Location:
New York
Posts:
16
Plugin Contributions:
0

For the sake of learning, How could I update a products quantity via the SQL Database

Running the latest versions of everything.

I know there are plugins like EasyPopulate, but as I said in the title this is for the sake of learning. If I have a products public ID, and wanted to find its ID, and update its Quantity manually in PHPMyadmin, what database would I go to? I see many for products, but cannot figure out where quantity is kept or how the product ID's work. For example, in the product database, a given product will have an ID of 1, and a public ID of whatever I set it to. When I search the public ID in the back end of my site, the product ID it shows me is completely different. Just trying to wrap my head around this.

12 Feb 2023, 1:24 AM
#2
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,727
Plugin Contributions:
56

Re: For the sake of learning, How could I update a products quantity via the SQL Database

Zen Cart has a table called products that has a primary key of id.
So if you wanted to select product 1, you'd use

SELECT * FROM products WHERE products_id = 1

The database that your Zen Cart installation uses is shown on the Version screen in your admin.
See (d) in the large image on this page:
https://docs.zen-cart.com/user/admin_pages/tools/server_info/

It is not ideal to do things using phpMyAdmin though - you want to learn the Zen Cart admin. You can set a product's quantity on the product edit page:

https://docs.zen-cart.com/user/products/product_edit/

Does that make sense?

That Software Guy. My Store: Zen Cart Support
Available for hire - See my ad in Services
Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
Do you benefit from Zen Cart? Then please support the project.

12 Feb 2023, 1:27 AM
#3
balihr avatar

balihr

Totally Zenned

Join Date:
Oct 2008
Location:
Croatia
Posts:
1,807
Plugin Contributions:
22

Re: For the sake of learning, How could I update a products quantity via the SQL Database

Public ID whatever you set it to? I'm assuming you're mixing the term ID with model number. You can set the model number, but you can not set the product's ID - that's a unique identifier that is automatically assigned by the database with the auto_increment. The ID is completely out of your control.
If you look at your URL on the product_info page, you'll see ...index.php?main_page=product_info&products_id=1234 - the 1234 is the actual ID. You can NOT search for a product by it's ID in the backend. You can see the product's ID (first column in admin where your products are listed), but you can not search for the ID.
If the "public ID" is really products_model, then your search might be giving you different results because you're using the same model number for multiple products.

If you look at the database, you'll see the products_id in multiple tables. Quantity is kept in the products table (zen_products, zc_products or whatever prefix you may have) - field name is products_quantity.

My site - Pro ZC Help
My portfolio | My plugins

12 Feb 2023, 2:07 AM
#4
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: For the sake of learning, How could I update a products quantity via the SQL Database

balihr:

Public ID whatever you set it to? I'm assuming you're mixing the term ID with model number. You can set the model number, but you can not set the product's ID - that's a unique identifier that is automatically assigned by the database with the auto_increment. The ID is completely out of your control.
If you look at your URL on the product_info page, you'll see ...index.php?main_page=product_info&products_id=1234 - the 1234 is the actual ID. You can NOT search for a product by it's ID in the backend. You can see the product's ID (first column in admin where your products are listed), but you can not search for the ID.
If the "public ID" is really products_model, then your search might be giving you different results because you're using the same model number for multiple products.

If you look at the database, you'll see the products_id in multiple tables. Quantity is kept in the products table (zen_products, zc_products or whatever prefix you may have) - field name is products_quantity.

Ummm, products_id is part of the category product page search, so yes one can search in the admin using the products_id value.

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

12 Feb 2023, 12:09 PM
#5
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,727
Plugin Contributions:
56

Re: For the sake of learning, How could I update a products quantity via the SQL Database

@spanky not sure if your question has been answered - let us know if not.

If you want to learn more about the database schema for Zen Cart, see the file zc_install/sql/install/mysql_zencart.sql in a fresh download.

You can also view the schema here:
https://docs.zen-cart.com/dev/schema/schema_158/

That Software Guy. My Store: Zen Cart Support
Available for hire - See my ad in Services
Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
Do you benefit from Zen Cart? Then please support the project.

12 Feb 2023, 1:46 PM
#6
balihr avatar

balihr

Totally Zenned

Join Date:
Oct 2008
Location:
Croatia
Posts:
1,807
Plugin Contributions:
22

Re: For the sake of learning, How could I update a products quantity via the SQL Database

mc12345678:

Ummm, products_id is part of the category product page search, so yes one can search in the admin using the products_id value.

:blink: :lamo:
Live and learn... Yes, I stand corrected, you CAN search for the products_id (note to self: take 5 secs to test before replying). Thanks, mc!

My site - Pro ZC Help
My portfolio | My plugins

12 Feb 2023, 6:35 PM
#7
dbltoe avatar

dbltoe

Totally Zenned

Join Date:
Jan 2004
Location:
N of San Antonio TX
Posts:
9,858
Plugin Contributions:
18

Re: For the sake of learning, How could I update a products quantity via the SQL Database

Pobody's Nerfect! :cool:

Need a hand with Zen Cart? Hire the team at myZenCartZone.com for upgrades, repairs, and custom plugins.
Zen Cart Certified hosting at myZenCartHost.com

15 Feb 2023, 2:05 AM
#8
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: For the sake of learning, How could I update a products quantity via the SQL Database

balihr:

:blink: :lamo:
Live and learn... Yes, I stand corrected, you CAN search for the products_id (note to self: take 5 secs to test before replying). Thanks, mc!

dbltoe:

Pobody's Nerfect! :cool:

Certainly made me look considering the changes made in 1.5.8. I personally went to the code to see what was expected. Glad you went the other route to confirm. :)

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...