How to create a POS system

Hello.

I am going to get off-track writing this post (I just know it) so I’ll state my basic points now before I start explaining.
I put this in “General Web Dev” because…
My main question is what technology/language would I use to create the system I want to create?

So this POS system is super simple, utilizing just a few database tables, they are as follow.

  1. Products (Contains rows “Product_Name, Product_Price, Product_ID, Product_Catagory)
  2. Sales (Contains rows “Order_ID, Product_Price, Product_Catagory)

Obviously, the “Products” table contains the products. These will be added to the table via a PHP interface (Not what I need help with, just providing as background).

UI outline (If you want to visualize it):

On the left, the product ID in added to the “cart” and it appears on the right. As each product is added, the list on the right grows, and the “Total” goes up. When the “Checkout” button is clicked, information is added to the “Sales” table.

What I need help with is the adding products to the list, then adding the information to the “Sales” table when the “Checkout” button is clicked. So the system would have to pull from the database when a new product is added to the cart, and information will have to be added to the database when the “Checkout” button is clicked.

I though about using PHP, and it would work fine, except I only want the page to reload when the “Checkout” button is clicked, not when a new item is added to the cart. The other limitation is that is must run on PHP shared hosting, on an Apache web server.

Is there a way I could make this work with PHP, or is there a different/better way to do this?

Thanks!

You would use ajax to submit the item to add to the cart and update the display of the items in the cart.

The item id and the quantity (or an implied quantity of one) would be submitted and added to a session based cart array, using the item id as the array’s index and the quantity as the stored value. By using the item id as the array index, you are enforcing uniqueness. If another quantity of the same item id is added to the cart, you would add the new quantity to the the existing quantity.

For displaying the items in the cart, you need to decide if you are going to just append new items as they are added to the cart, which would result in duplicates if the same item is added later, or redraw the whole section, based on the current contents of the cart whenever an item is added, which would just show a single entry for each item.

To get the product information (name, price), for the cart display you would use the item id(s) and query the database to get the values.

Have to run to an appointment. If no one else addresses the checkout, will reply later.

1 Like

I mean maybe just add the number before the name, then update the price? Like:

2 Hat              $10

And when it is inserted into “Sales”, just have the name be “2 Hat” instead.

Sorry if this is a stupid statement (I don’t really know JavaScrpt), but I thought only PHP could query the database, and it forced a page-reload if it did?

EDIT: Is this what you are referencing? https://stackoverflow.com/a/5610430

Thanks so much for the responce!

Think probably the trouble you’re having is that you’re thinking there’s A language that you should be using.

Use the best tools for the job. Whatever the given job at the time is.

You need something backend that’ll talk to databases quietly without the user seeing? You’ll want something server-side, like PHP.

You want the user’s experience to do a thing, like reloading at a certain time or action? You’ll want something client-side, like Javascript.

You want to style it all pretty? Some flavor of CSS.

You need an environment, rather than a language.

This part does occur on the server. The result of doing that would be to send a response back to the browser with that information in it so that it can be used to modify the displayed information.

Back to the checkout. The submit button would just indicate to go to the check processing. Since the cart information is already on the server in the session based cart, you would -

  1. insert a row in a ‘sales’ table with the unique/one-time information about the sale. This will result in a sale id (auto-increment primary index in the sale table.)
  2. You would get this id and use it when inserting the details about the items making up the sale into a sale_item table. You would have columns for an id, sale_id, item_id, quantity, price (at the time of the sale), and any other columns you might need.
1 Like

I wanted to know A language to run the cart, not the entire thing. It seems that I need 2, JS and PHP.

Thanks for the tips @mabismad, I think I understand it a bit more now. I’ll do some looking into the JS side of things that I will need (And should probably learn it as well). If there are any tutorials or SO posts that you think would be helpful with the ‘adding products to the list’ part, or the ‘add the final list to the database part’ it would be greatly appreciated if you share, otherwise, I’ll figure it out even eventually (After the 5 million other things on my “let’s code this!” list).

It will be PHP (if indeed you do decide on PHP for the back-end) that queries the DB, but for dynamic page updates (without refresh) you can have JS make a request to the back-end (PHP) to fetch DB data, then display it once received.
This is what Ajax does. Though I’m no expert in JS, I believe there are more modern methods now that have superseded Ajax, but a JS expert will tell you more.

Since your profile says you are already comfortable in PHP, that would be a natural choice for the back end, it’s quite capable of that. But for any interactivity without refresh front-end, you are going to need JS and some means of communication back and forth between client and sever.

1 Like

That would be the way to go. You could probably bodge it, but bodged code tends to be flaky and have security flaws - and you don’t want that when you’re dealing with an ordering system.

1 Like

Yep. I have been working with PHP for a few months now, and have learned a lot about it (Also why I suggested it in the beginning). The issue really is with the AJAX, as well, I could never really understand JS (I also never really tried since the client can manipulate it, and that would be a horrible security issue with the other project I am working on).

Well, the system is only for myself, and the only other people that will have access to it have little knowledge about computers, let alone programming, and it will always be used under my supervision. It will be heavily protected by PHP and password authentication, so I will probably attempt to just get it done. If I do decide to let it out, I would obviously have to fix it.

It is just meant to replace some free (horrible) product that I am using now.

Thanks for the info!

To be honest, a few month is not really much. You are still at the beginning of becoming a software developer.
Your statement about JavaScript and security shows that you have many gaps in basic knowledge required to develop web applications.
You should start and learn more about the basics. What is a front, what a backend and why do we have to separate them (in fact something you do not do the way you are developing your application at the moment).
How can I divide me application into different independent layers and how is the communication between this layers and what is the right way to make this secure (what in the end is not so complicated and much more secure then having all layers in one like you do at the moment)

Type Product ID

Going back to the user interface, you shouldn’t expect a person to know and type in complete values, unless there are only a few. The user interface should allow a person to narrow down and select from existing Products, so that only a product that exists in the database can be selected.

If you were doing this in a Retail environment, you would have a UPC barcode scanner to supply the input. You would need a backup way for a user to manually input a UPC code, for those cases where the scanner cannot read the one on the Product.

You would also need a way of searching for products, optionally by first selecting a category, then typing part of the product name, using Autocomplete/Typeahead, until the displayed choices are narrowed down to the point where an existing product can be selected.

1 Like

Normally, yes, those would all, be needed, I agree. However, I don’t really require it for what I am going to be doing with it.


Not to be rude @Thallius, but I know the difference between frontend and backend, and I know how to make something secure (A friend who does vulnerability testing confirms this) if I really want to. My lack of knowledge is in JavaScript, and it’s communication with other languages. My knowledge in PHP is perfectly fine, thanks.

Both languages can be used Insecurely. However, building web applications using modern architecture rather than php will lead to less security vulnerabilities. For example, building secure apis and using zero trust communication between the client and apis. Also using server side languages that provide some level of protection against mistakes like leaving open injection gaps. Unless you are security scanning an application you can’t say for certain it is secure. Security is a methodology not necessary a language although some languages do make security gaps less likely. Furthermore, building apps without being concerned for modern ux is doing a major disservice to customers. A pleasant modern ux will destroy a old legacy server rendered app with a bunch of page loads any day. Also pos systems are a little different than web apps even though they can be built as such since pos need to be always available. Therefore, it is typical to run the front end directly on the hardware and sync with a remote data server or api.

4 posts were split to a new topic: PHP, security and the environment

Consider using a ready-made free cart such as Ecwid.

I’ve not tried using it!

Um, no thanks. First of all, there is a limit of the number of products (I will need to manage 1,000+), it has branding, and is not free. Also, I don’t need a payment processor, since everything will be done with cash.

And plus, the best thing about being a developer is that you can design things however you want them, and you have full control over your data, and how it is used (Mostly the latter).

I kind of gave up with the AJAX, as I don’t really have time to learn it now. I trying some PHP/SQL approach that should work, I am just hoping the page can reload super fast. I’ll let you know when it’s done (might be a few weeks)!

I do not understand how everything will be done by cash. But if everything is done by cash, could you not simply have an order form that gets emailed to you? Or do you really need a database for stock availability and control?

In-person only. I want to keep track of sales and stock.

1 Like