entername — 2010-11-11T09:17:04-05:00 — #1
ahoy, i am currently developing a cart for a website at my company.
What i am attempting to do is update the grand total field dynamically as the
product total (determined by quantity & price) are being populated.
Each product in the cart is being generated by a foreach (php) reading from a mysql database.
As the total values are not being prepopulated im not exactly sure what the logic would be to get the desired values.
I will also mention im relatively new to the whole web development area, i started begining of this year and feel i could still learn alot about the 'logic' of a computer.
If anything is unclear about what i stated above feel free to request additional information.
Thanks in advance
system — 2010-11-11T20:06:21-05:00 — #2
My suggestion would be to build a shopping cart class.
The class could include the following
1) an associative array with the product_id as key and the quantity for that product as the value
2) an associative array with the product_id as key and the price of the product when it was added to the cart as the value
3) class method to calculate the total value of the cart from the arrays in 1)
4) class methods to add/delete/change quantitiies for items in the cart
5) class method to empty the cart
6) class methods to retrieve the cart contents for display purposes.
If you post the code you have so far, it will be easier to help you.
entername — 2010-11-12T03:34:16-05:00 — #3
Hi Kalon, thanks for the speedy and helpfull reply!
You actually gave me exactly the information i needed - i just really needed the logic, i believe i should look into arrays more in the future:rolleyes:
Your input is much appretiated.