T
T
Tetiana972021-07-03 16:59:41
PHP
Tetiana97, 2021-07-03 16:59:41

How can I add a shopping cart to the website of an online store so that when you click on the "Buy" button, a shopping cart with a product is displayed?

Good afternoon! Can you please tell me how you can add a shopping cart to the website of an online clothing store so that when you click on the "Buy" button, a cart with the selected product, its quantity, size, price, total cost is displayed? And also to be able to add items to the cart and remove them. PHP and Java Script are used.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman, 2021-07-03
@Tetiana97

I suggest)))
There are exactly 2 fundamentally different options:
1. Store data about the goods added to the cart on the server
2. Store data about the goods added to the cart on the client
If your online store forces the user to log in, then you should implement the first option. If the store is not tied to the user in any way (there is no authorization of any kind, user data is not stored on the server), then option 2 will be the best for you.
And so, here are descriptive examples of the possible implementation of both options:
Option 1:

  • on the client, when you click the [add to cart] button for any product, we send AJAX information about this product to the server
  • on the server, having received such a request, we remember this information in the user's data corresponding to his basket (adding it to the existing one)
  • on the client, when you click the [view cart] button, we send an AJAX request to the server for all the data from the user's cart
  • on the server, having received such a request, you get all information about the added products from the user data and send it in response to the request
  • on the client, having received such a response, you form a window (page) in which you display this data in a user-friendly form
  • etc. etc.

Option 2:
  • on the client, when you click the [add to cart] button for any product, we write information about this product in lacalstogage
  • on the client, when you click the [view cart] button, we take from lacalstogage all the data about the goods already added to the cart and form a window (page) from them in which you display this data in a user-friendly form
  • etc. etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question