mercredi 26 septembre 2018

Cookie data is not getting in cart listing page

I am developing a shopping cart website using laravel 5.5. My local development environment is Laravel Homestead. I am adding a functionality to store few details in to cookie before login.

User chosen a product and clicked on "add to cart" button, then the product details will store in to cookie and redirect to login page.

I need to retrieve that stored details from cookie after user login. After user login, page is redirect to cart listing page. But not getting any cookie data from cart page.

Script to store cookie and redirect to login page.

$.ajax({
        url: '/cookie/data/to/cart',
        dataType: 'JSON',
        type: 'POST',
        data: { productname: productname }
       })
         .done(function( data ) {
           if(data.response === 'success') {
              var redirect_url = '/login';
              $( "#errors_"+cabin ).hide();
              $( "#warning_"+cabin ).hide();
              window.location.href = redirect_url;
          }
 })

After set cookie from product listing page. Success response send to script

$minutes     = time()+31556926; //Where 31556926 is total seconds for a year
$productname = setcookie('productname', 'Apple', $minutes);
return response()->json(['response' => 'success']);

After user login, page redirect to cart page.

class ServiceController extends Controller
{
    public function cart()
    {
        if(isset($_COOKIE['cabinnamecookie']))
        {
            dd($_COOKIE['cabinnamecookie']);
        }

    }
}



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2NHenLf
via IFTTT

Aucun commentaire:

Enregistrer un commentaire