Handel
view release on metacpan or search on metacpan
lib/Catalyst/Helper/Controller/Handel/Cart.pm view on Meta::CPAN
};
} else {
$c->forward('list');
};
} else {
$c->res->redirect($c->uri_for('[% uri %]/'));
};
return;
};
=head2 save
=over
=item Parameters: name
=back
Saves the current cart with the name specified.
[% uri %]/save/
=cut
sub save : Local {
my ($self, $c) = @_;
if ($c->req->method eq 'POST') {
if ($c->forward('validate')) {
if (my $cart = $c->forward('load')) {
$cart->name($c->req->param('name') || 'My Cart');
$cart->save;
$c->res->redirect($c->uri_for('[% uri %]/list/'));
};
} else {
$c->forward('default');
};
} else {
$c->res->redirect($c->uri_for('[% uri %]/'));
};
return;
};
=head2 update
=over
=item Parameters: quantity
=back
Updates the specified cart item qith the quantity given.
[% uri %]/update/
=cut
sub update : Local {
my ($self, $c) = @_;
if ($c->req->method eq 'POST') {
if ($c->forward('validate')) {
if (my $cart = $c->forward('load')) {
my $item = $cart->items({
id => $c->req->param('id')
})->first;
if ($item) {
$item->quantity($c->req->param('quantity'));
};
$c->res->redirect($c->uri_for('[% uri %]/'));
};
} else {
$c->forward('default');
};
} else {
$c->res->redirect($c->uri_for('[% uri %]/'));
};
return;
};
=head2 validate
Validates the current form parameters using the profile in profiles.yml that
matches the current action.
if ($c->forward('validate')) {
};
=cut
sub validate : Private {
my ($self, $c) = @_;
$self->{'validator'}->results->clear;
my $results = $self->{'validator'}->check(
$c->req,
$self->{'profiles'}->{$c->action}
);
if ($results->success) {
return $results;
} else {
$c->stash->{'errors'} = $results->messages($c->action);
};
return;
};
=head1 AUTHOR
A clever guy
=head1 LICENSE
( run in 2.504 seconds using v1.01-cache-2.11-cpan-2398b32b56e )