Friday 15 February 2013

php - Online shopping cart with Laravel -



php - Online shopping cart with Laravel -

i using laravel , moltin/cart build cart scheme online store. far, have managed integrate cart scheme , go on paypal. though, in controller have constructor prevents user viewing, adding or removing items cart unless authenticated.

public function __construct() { parent::__construct(); $this->beforefilter('csrf', array('on'=>'post')); $this->beforefilter('auth', array('only'=>array('postaddtocart', 'getcart', 'getremoveitem'))); }

in order create paypal work had add together several hidden inputs in view necessary values , passing them paypal's paying page, so:

<input type="hidden" name="cmd" value="_xclick"> <input type="hidden" name="business" value="office@shop.com"> <input type="hidden" name="item_name" value="ecommerce store purchase"> <input type="hidden" name="currency_code" value="eur"> <input type="hidden" name="amount" value="{{ cart::total() }}"> <input type="hidden" name="first_name" value="{{ auth::user()->firstname }}"> <input type="hidden" name="last_name" value="{{ auth::user()->lastname }}"> <input type="hidden" name="email" value="{{ auth::user()->email }}"> {{ html::link('/', 'continue shopping', array('class'=>'btn btn-default')) }} <input type="submit" value="checkout paypal" class="btn btn-primary">

the problem user shouldn't logged in view, add together or remove items cart, asked login when submit button clicked. if remove filters constructor then, "trying property of non-object" error because of hidden inputs create utilize of auth class. have tried add together blade if auth::check status wasn't solution. suggestions?

answer

this did trick:

@if(!auth::check()) {{ html::link('users/signin', 'sign in pay', array('class'=>'btn btn-primary')) }} @else <input type="hidden" name="first_name" value="{{ auth::user()->firstname }}"> <input type="hidden" name="last_name" value="{{ auth::user()->lastname }}"> <input type="hidden" name="email" value="{{ auth::user()->email }}"> {{ html::link('/', 'continue shopping', array('class'=>'btn btn-default')) }} <input type="submit" value="checkout paypal" class="btn btn-primary"> @endif

also, removed filters constructor , changed redirection in sign in function, redirects accessed page.

using session variable hold visited url

in order go visited page need utilize session::put.

so, in getsignin function add:

session::put('previous_url', url::previous());

and in postsignin function need retrieve previous_url variable, stored in session, so:

if ( session::has('previous_url') ) { $url = session::get('previous_url'); session::forget('previous_url'); homecoming redirect::to($url); }

how replacing checkout button sign in button , redirect cart checkout again?

php laravel paypal

No comments:

Post a Comment