A few things.
Try to follow the conventions to put your code in the right places. While you may break conventions, it’s better to follow them unless you have a really good reason. Putting your liveviews inside a template folder won’t help other people trying to help you.
Do Not put your scripts in the root template’s head, put them in app.js instead. Do not use jquery as a beginner, and most certainly do not use any Ajax in a LiveView.
Now for more practical advice. If you’re dead set on saving the cart in the session cookie, just add a button ‘save cart’ Form bindings — Phoenix LiveView v0.17.11 (there is much more to it, but that will get you somewhere).
Try to port your js code to Phoenix.LiveView.JS — Phoenix LiveView v0.17.11
Also, when writing in this forum, explain what you wanna do -there are other ways to build a shopping cart.
-------- French
Quelques petites choses:
Essaye de suivre les conventions de nommage des fichiers. Sinon c’est difficile pour les autres d’examiner ton code.
N’ecris pas, JAMAIS, de code js dans la balise script du header, utilise app.js. Et surtout pas d’ajax dans les LiveView. Essaye de ne pas utiliser jQuery.
Si tu veux vraiment sauver tes données de panier dans la session, rajoute un bouton sauver le panier pour plus tard (voir le lien plus haut).
Essaye de porter ton code js en utilisant les fonctionnalités du module JS (tout ce que tu as fait peut marcher).
De maniere general, sur le forum explique ce que tu veux obtenir comme résultat plutôt que demander des petites choses qui ne seront pas nécessairement comprises. En l’occurrence demande comment implementer un shopping cart. Tu auras plus de réponses
@derek-zhou : While I fully agree with you in general, sometimes, some people have difficulties speaking in English and further could be beginners who don’t really know what to ask.
I believe that the OP falls in that category, and I believe that we should welcome them. I’m not faulting you, a decade ago I was in dev mailing list for a very good software that’s still great, and I ‘dunked’ on a lost user there (not saying it’s what you did) only to have my ass handed to me, because many things are not obvious to beginners/people who don’t really speak English. Since then I ignore questions that come from a bad faith place (and there are a few in this forum) or I try to help. Again I believe OP’s intentions are good, and perhaps they’re misunderstood