Construct the shopping cart product list into a json array and then pass it to the server, or what?
我想大声告诉你2017-07-01 09:14:09
I have a say in this issue. All I have done this year is about shopping malls. Among them are from the shopping cart or product details page to the order confirmation page. I organize the data from the shopping cart according to the data format of the order confirmation page (usually into an object in the end) and then store it in localstorage (all done on the mobile side), and then jump directly to the page to traverse and render the data object on the order confirmation page. That's fine, don't worry, these are just for users to see on the front end. The backend will calculate the order amount again when paying, and then split the order, so even if the user changes the payment information, he still has to pay the money,
黄舟2017-07-01 09:14:09
No, the shopping cart content is not transmitted from the form to the server. It depends on how your mall shopping cart is implemented.
Whether it is SESSION, MySQL, or redis, etc.
When the order is submitted, the shopping cart content needs to be on the server side,
Here is to directly read the library or SESSION, redis
Verify again whether the sku quantity is consistent when submitting it
Recalculate the total price, discount, and total price on one side
Finally: Never trust the data submitted in the form, including the price of the product
Otherwise, it will be a joke to buy thousands of yuan for just one penny.
淡淡烟草味2017-07-01 09:14:09
Negotiate with your backend,
Our previous approach was to integrate the data structure provided by the backend into a string, pass it to the backend, and the backend will parse it according to its own algorithm
For example1_xxx_24:2_xxx_56
This is the backend splitting into multiple products based on colons, and then getting the values of the three parameters based on underscores. The data at that time is, the order of the parameters cannot be wrong, and the parameters must be present,
Just an example, it depends on how you want to implement it in the backend, the frontend is only responsible for transmitting and receiving
怪我咯2017-07-01 09:14:09
Save the data in the shopping cart on the front end, such as vuex in VUE and redux in react. These data will always be stored in a public place. If you are not logged in, it doesn’t matter. Let him choose first in the shopping cart and click to pay. Log in again and finally submit it in the form of a json array