473,587 Members | 2,413 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

reserving a product in an Ecommerce website

258 Contributor
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
Oct 7 '09 #1
4 2088
1,168 Recognized Expert Top Contributor
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
5,058 Recognized Expert Expert

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
258 Contributor
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
1,168 Recognized Expert Top Contributor
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

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: -------------------- ------------------------- | product_options | | product_option_values |
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 dedicated servers at the office. The database will contain web-only information and lots of back end information that is not really needed to be stored...
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 site. So i have a few questions: 1. How an eCommerce web site works? Where can i find some information about it?
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 uninstall the current one. How do I create a 2nd ECommerce site based on this Starter Kit? (Including auto db setup, etc...) Thanks!
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. However, should I be presenting the currency figure in the currency of the visitor? I want to keep the site simple to begin with, so if I choose to...
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 for dynamic content ?
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 the database. Explain the mechanism of the accessing the database from your
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 new site makes it even easier for developers to find information about the products and about the company itself. The new Product wizard results in...
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 above. With a lot of the controls in Visual Studio 2005, would I be able to grab data from a database and display it in a similar fashion like the...
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.