0

i have some problem, I'm creating apps for commerce, and the cart is work, but when I'm reloading the pages, the session is gone, cart, and other.

here's my code

//show product page
  $scope.showProductInfo=function (id,desc,img,name,price) {   
     sessionStorage.setItem('product_info_id', id);
     sessionStorage.setItem('product_info_desc', desc);
     sessionStorage.setItem('product_info_img', img);
     sessionStorage.setItem('product_info_name', name);
     sessionStorage.setItem('product_info_price', price);
     window.location.href = "/#/page8";
   };

   //add to cart function
   $scope.addToCart=function(id,image,name,price){    
    cart.add(id,image,name,price,1);  
   };                          

how can i save the data to session or cookies, like php did, so if the reloading page, the session not destroying/ session_destroy();

hope somebody care enough to help me

themasmul
  • 125
  • 1
  • 10
  • 2
    Possible duplicate of [saving variable value and retrieve it after page refresh](http://stackoverflow.com/questions/11740669/saving-variable-value-and-retrieve-it-after-page-refresh) – illeb Aug 10 '16 at 16:23

1 Answers1

0
  1. Move cart management into service - so you will get same data from any controller.
  2. When service is initialized - try to load from local storage (if not - create empty cart)
  3. Any change of cart must update localstorage
Oleg Imanilov
  • 2,591
  • 1
  • 13
  • 26