ECommerce/Plugin/Basket/Add.pm untested

filter: Statementstmt 0.0% 0 / 47 Branchbran n/a Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 83 CC 1 SCAR 6.9
CC
1
Cov
0%
http_post
2.0
redirect
2.0
BEGIN
2.0
CRAP 2.0
1 # -------------------------------------------------------------------------------------
2 # flo::plugin::Shop::Basket::Add
3 # -------------------------------------------------------------------------------------
4 # Author : Jean-Michel Hiver <jhiver@mkdoc.com>.
5 # Copyright : (c) MKDoc Holdings Ltd, 2003
6 #
7 # This MKDoc plugin adds an item into someones' shopping basket.
8 # If the client sent a cookie, then this cookie is used to fetch the existing basket.
9 #
10 # Otherwise, this module creates a new shopping basket and sends a cookie to the
11 # client for future retrieval.
12 # -------------------------------------------------------------------------------------
13 package flo::plugin::Shop::Basket::Add;
14 use strict;
15 use warnings;
16 use flo::Standard;
17 use flo::plugin::Shop::Basket::Help;
18 use MKDoc::Session;
19 use MKDoc::ECommerce::Item;
20 use MKDoc::ECommerce::Basket;
21  
22 use base qw /flo::plugin::Shop::Basket/;
23  
24  
25 sub http_post
26 {
27 my $self = shift;
28 my $cgi = flo::Standard::cgi();
29
30 # if there is no session present, redirect to a help
31 # page about cookies, user accounts and stuff
32 my $session = MKDoc::Session->load() || do {
33 my $help_p = new flo::plugin::Shop::Basket::Help();
34 print $cgi->redirect ($help_p->uri());
35 return 'TERMINATE';
36 };
37
38 # if the session holds no basket object, create one
39 $session->{basket} ||= new MKDoc::ECommerce::Basket();
40
41 my $item = new MKDoc::ECommerce::Item (
42 reference => $cgi->param ('reference'),
43 description => $cgi->param ('description'),
44 unit_price => $cgi->param ('unit_price'),
45 quantity => $cgi->param ('quantity'),
46 signature => $cgi->param ('signature'),
47 );
48
49 $item and do {
50 $session->{basket}->add ($item);
51 $session->save();
52 };
53
54 return $self->redirect();
55 }
56  
57  
58 sub redirect
59 {
60 my $self = shift;
61 my $cgi = flo::Standard::cgi();
62
63 # redirect the user to whereever s?he comes from and terminate
64 my $from = $cgi->param ('from') || $ENV{HTTP_REFERER} || do {
65 my $cgix = flo::Standard::cgi()->new();
66 for ($cgix->param()) { $cgix->delete ($_) }
67 $cgix->path_info ('/');
68 $cgix->self_url;
69 };
70
71 print $cgi->redirect ($from);
72 return 'TERMINATE';
73 }
74  
75  
76 1;
77  
78  
79 __END__