473,385 Members | 1,312 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

reserving a product in an Ecommerce website

258 100+
Hi everyone
I'm sure there are many open source Ecommerce scripts out there but because of some reasons i'm building my own.

I'm having a problem with reserving products.

Here's what I need :
when the administrator of this webshop adds a new product he also need to choose the quantity of that product available in stock which is not so hard to do with PHP and MySQL. Each time a customer purchases a product the script will decrease the quantity in database and when all of them are purchased then the product will no longer be available on the website. But the problem occurs when several customers buy the same product at the same time.

Lets say there's a product with the quantity = 1 . what happens when 2 customers buy it at the same time? I mean there should be a way to reserve that product when ever a user adds it to his shopping cart.

I could come up with some ways to do this job, Like decreasing the quantity when a user adds that product to his shoping cart and increasing it when he cancels the payment. But these ways generate a high trafik to MySQL and this way might not be so safe. because if the user closes the browser without canceling the payment then the quantity will not be increased.

Any idea will be appreciated
Thanks
Oct 7 '09 #1
4 2074
TheServant
1,168 Expert 1GB
I don't think that the MySQL traffic will be overrun with updating a value when it's selected. I think you will need to add a few things because not only do you need to update the stock, if that's what you change, but you need to see if a user session has timed out.
So if you have three tables: Stock, Cart and User...
Stock columns: item_id, item_name, item_quantity
Cart columns: cart_id, user_id, item_id, item_quantity
User columns: user_id, user_name, last_activity
This means that everytime a user clicks on something (navigates) you need to update their last activity witha time stamp. So if a user doesn't move for say 30mins, then you can free whatever he has in his cart.

Now the tricky part is how often, or how you want to check if their activity has been longer than say 30mins. You could run a cron job every hour, or 30 mins which looks for any expired sessions and systematically checks carts to see if the user is still logged in (check activity has not expired) with some table JOINS and then release that stock.

You are probably thinking that this is a longa nd resource consuming way about it, and it could be if you run your crons *too* often, but the major problem is when a browser is closed it does not send a note to all the website it's visited to say, "I'm logging off", so the only real way to do it is with databases or sessions.

Having said that, there could be a way to attach a session_id to a the cart to avoid having to store last activity in the database, and simply check if the session is still considered active, or still exists. I haven;t done this before, so I can't comment, but I imagine it has it's own flaws as well.

MySQL is very good, so don't be scared to use it for resource reasons. You could cause issues, but a couple MySQL queries will not break the bank.
If you had a cron job running every 5mins, updating 10,000 rows 6 times, then we might advise a different route, but just try use it and if it's too resource consuming then think of a different way. Most things can be optimized, but you have to start somewhere.
Oct 7 '09 #2
Atli
5,058 Expert 4TB
Hey.

How do you store the shopping cart for your customers?

If you were to store the cart itself inside the database, you could count how many units of a particular item are currently in people's carts and reduce the available amount by that amount.

And you could have the carts "timeout" by adding a column that keeps track of when the user was last active, and only count items in carts that were active within a given time frame.
Oct 7 '09 #3
bnashenas1984
258 100+
Thank you TheServant and Atli for the answers.I realy appreciate it.

As I understand i need to have some tables to keep users activity and their reserved products.

I will work on it and if there is any problem i'll post another question.

Thanks again
Oct 8 '09 #4
TheServant
1,168 Expert 1GB
Glad we could help. That's the logic that I would start with, but come back with your code and we can try and help you optimize that.
Oct 8 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: deja | last post by:
Hi all, I am trying to create a product variants facility for an ecommerce site (php/mysql). Each of my products have options & option values stored in the db like this: ...
2
by: Alex_Bxl | last post by:
Hi to all I have to choose a DBMS and a database architecture for an Ebay like website about to be launched. The company wants to use a web hosting service and not host the database on...
1
by: Miguel Dias Moura | last post by:
Hello, in 2 months i will create an eCommerce web site in ASP.net. I have been creating web sites in Flash, ASP, ASP.net and PHP for quite sometime. However i never created an eCommerce web...
0
by: VB Programmer | last post by:
I installed IBuySpy ECommerce app and customized an ecommerce site. Now I want to make a 2nd ECommerce app, based on the Starter Kit. But, when I run Setup it asks if I want to repair or...
6
by: J Rieggle | last post by:
Hi there, I am stuck on a problem that relates to eCommerce sites, but isnt ASP.NET specific (sorry). The ecommerce site is working in the UK, and products will be sold in pounds stirling. ...
11
by: Greg | last post by:
How can C# be used for a website ? Would the person viewing a site need to have the .NET framework installed ? What other technologies would need to be used ? Would a database server be needed...
1
by: ss.morshedi | last post by:
Dear all; please answer my questions,tnx. 1.Explain the advantages of using XML with a database for ecommerce sites 2.Explain the functionalities of your website especially with regard to...
0
by: fiona | last post by:
Yucca Valley, CA, - November 2007: Catalyst Development Corporation, publisher of SocketTools, SocketWrench and LogicGem, today unveiled their new corporate website and Product Wizard Tool. The...
0
by: apedosmil8 | last post by:
For my .NET class I am making a T-shirt/Hoodie website. I would like it to be as dynamic as possible with a database backend. http://bustedtees.com/ I want to model it after this website...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.