| 1 | package XTaTIK::Controller::Cart; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | our $VERSION = '0.001002'; # VERSION | |||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Mojo::Base 'Mojolicious::Controller'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use experimental 'postderef'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 1 | my @CHECKOUT_FORM_FIELDS = qw/ | |||||||||||||||||||||||||||
| 10 | address1 address2 city do_save_address email | ||||||||||||||||||||||||||||
| 11 | lname name phone promo_code province toc zip | ||||||||||||||||||||||||||||
| 12 | /; | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | sub index { | ||||||||||||||||||||||||||||
| 15 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
index: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 0 | $self->stash( $self->cart->all_items_cart_quote_kv ); | |||||||||||||||||||||||||||
| 18 | }; | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | sub thank_you { | ||||||||||||||||||||||||||||
| 21 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
thank_you: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | # TODO: refactor this into Module::Plugable | ||||||||||||||||||||||||||||
| 24 | 0 | my $handler = 'XTaTIK::Plugin::Cart::' | |||||||||||||||||||||||||||
| 25 | . $self->config('checkout_system'); | ||||||||||||||||||||||||||||
| 26 | 0 | ▶ | eval "require $handler" or die $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 0 | $self->stash( thank_you_html => $handler->new->thank_you( $self ) ); | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | sub add { | ||||||||||||||||||||||||||||
| 32 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
add: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 0 | my $p = $self->cart | |||||||||||||||||||||||||||
| 35 | ->add( $self->param('quantity'), $self->param('number') ); | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 0 | $self->cart_dollars('refresh'); $self->cart_cents('refresh'); | |||||||||||||||||||||||||||
| 38 | 0 | $self->cart->save; | |||||||||||||||||||||||||||
| 39 | $self->stash( | ||||||||||||||||||||||||||||
| 40 | number => $self->param('number'), | ||||||||||||||||||||||||||||
| 41 | quantity => $self->param('quantity'), | ||||||||||||||||||||||||||||
| 42 | 0 | ▶ | is_quote => $p->{price} > 0 ? 0 : 1, | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$self->req->headers->referrer || '/products'
MC/DC0%0/1
$self->req->headers->referrer || '/products'
$self->req->headers->referrer
Truth table0%0/2
A
A= $self->req->headers->referrer
| |||||||||||||||||||||||||||||
| 43 | return_to => $self->req->headers->referrer || '/products', | ||||||||||||||||||||||||||||
| 44 | ); | ||||||||||||||||||||||||||||
| 45 | }; | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | sub checkout { | ||||||||||||||||||||||||||||
| 48 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
checkout: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 0 | my @ids = map /(\d+)/, grep /^id/, $self->req->params->names->@*; | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 0 | for ( @ids ) { | |||||||||||||||||||||||||||
| 53 | 0 | $self->cart->alter_quantity( | |||||||||||||||||||||||||||
| 54 | $self->param('number_' . $_), | ||||||||||||||||||||||||||||
| 55 | $self->param('quantity_' . $_) | ||||||||||||||||||||||||||||
| 56 | ); | ||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | 0 | ▶ | @ids and $self->cart->save; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 0 | $self->cart_dollars('refresh'); $self->cart_cents('refresh'); | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 0 | for ( @CHECKOUT_FORM_FIELDS ) { | |||||||||||||||||||||||||||
| 62 | 0 | ▶ | next if length $self->param($_); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 0 | ▶ | $self->param( $_ => $self->geoip_region ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$_ eq "province" and not length $self->session($_)
MC/DC0%0/2
$_ eq "province" and not length $self->session($_)
$_ eq "province"
not length $self->session($_)
Truth table0%0/3
A and not(B)
A= $_ eq "province"B= not length $self->session($_)
| |||||||||||||||||||||||||||||
| 65 | if $_ eq 'province' and not length $self->session($_); | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 0 | ▶ | next unless length $self->session($_); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | 0 | $self->param( $_ => $self->session($_) ); | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | $self->stash( | ||||||||||||||||||||||||||||
| 72 | 0 | $self->cart->all_items_cart_quote_kv, | |||||||||||||||||||||||||||
| 73 | ); | ||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | sub checkout_review { | ||||||||||||||||||||||||||||
| 77 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
checkout_review: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 0 | $self->session( | |||||||||||||||||||||||||||
| 80 | customer_data => { | ||||||||||||||||||||||||||||
| 81 | map +( $_ => $self->param($_) ), qw/ | ||||||||||||||||||||||||||||
| 82 | address1 address2 city email | ||||||||||||||||||||||||||||
| 83 | lname name phone promo_code province zip | ||||||||||||||||||||||||||||
| 84 | / | ||||||||||||||||||||||||||||
| 85 | }, | ||||||||||||||||||||||||||||
| 86 | ); | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 0 | my ( $cart ) = $self->cart->all_items_cart_quote; | |||||||||||||||||||||||||||
| 89 | 0 | ▶ | @$cart or $self->redirect_to('/cart/thank-you'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 0 | ▶ | if ( $self->param('do_save_address') ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | $self->session( $_ => $self->param($_) ) | ||||||||||||||||||||||||||||
| 93 | 0 | for @CHECKOUT_FORM_FIELDS; | |||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | else { | ||||||||||||||||||||||||||||
| 96 | $self->session( $_ => undef ) | ||||||||||||||||||||||||||||
| 97 | 0 | for @CHECKOUT_FORM_FIELDS; | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 0 | $self->form_checker( | |||||||||||||||||||||||||||
| 101 | rules => { | ||||||||||||||||||||||||||||
| 102 | email => { | ||||||||||||||||||||||||||||
| 103 | max => 300, | ||||||||||||||||||||||||||||
| 104 | email => 'Email', | ||||||||||||||||||||||||||||
| 105 | }, | ||||||||||||||||||||||||||||
| 106 | name => { | ||||||||||||||||||||||||||||
| 107 | max => 300, | ||||||||||||||||||||||||||||
| 108 | name => 'First name', | ||||||||||||||||||||||||||||
| 109 | }, | ||||||||||||||||||||||||||||
| 110 | lname => { | ||||||||||||||||||||||||||||
| 111 | max => 300, | ||||||||||||||||||||||||||||
| 112 | name => 'Last name', | ||||||||||||||||||||||||||||
| 113 | }, | ||||||||||||||||||||||||||||
| 114 | address1 => { | ||||||||||||||||||||||||||||
| 115 | max => 1000, | ||||||||||||||||||||||||||||
| 116 | name => 'Address line 1', | ||||||||||||||||||||||||||||
| 117 | }, | ||||||||||||||||||||||||||||
| 118 | address2 => { | ||||||||||||||||||||||||||||
| 119 | max => 1000, | ||||||||||||||||||||||||||||
| 120 | name => 'Address line 2', | ||||||||||||||||||||||||||||
| 121 | optional => 1, | ||||||||||||||||||||||||||||
| 122 | }, | ||||||||||||||||||||||||||||
| 123 | city => { | ||||||||||||||||||||||||||||
| 124 | max => 300, | ||||||||||||||||||||||||||||
| 125 | }, | ||||||||||||||||||||||||||||
| 126 | do_save_address => { | ||||||||||||||||||||||||||||
| 127 | optional => 1, | ||||||||||||||||||||||||||||
| 128 | select => 1, | ||||||||||||||||||||||||||||
| 129 | }, | ||||||||||||||||||||||||||||
| 130 | province=> { | ||||||||||||||||||||||||||||
| 131 | valid_values => [ | ||||||||||||||||||||||||||||
| 132 | qw/AB BC MB NB NL NT NS NU ON PE QC SK YT/ | ||||||||||||||||||||||||||||
| 133 | ], | ||||||||||||||||||||||||||||
| 134 | valid_values_error => 'Please specify province', | ||||||||||||||||||||||||||||
| 135 | }, | ||||||||||||||||||||||||||||
| 136 | zip => { | ||||||||||||||||||||||||||||
| 137 | max => 20, | ||||||||||||||||||||||||||||
| 138 | name => 'Postal code', | ||||||||||||||||||||||||||||
| 139 | }, | ||||||||||||||||||||||||||||
| 140 | phone => { | ||||||||||||||||||||||||||||
| 141 | name => 'Phone number', | ||||||||||||||||||||||||||||
| 142 | }, | ||||||||||||||||||||||||||||
| 143 | toc => { | ||||||||||||||||||||||||||||
| 144 | mandatory_error => 'You must accept Terms and Conditions', | ||||||||||||||||||||||||||||
| 145 | }, | ||||||||||||||||||||||||||||
| 146 | promo_code => { | ||||||||||||||||||||||||||||
| 147 | name => 'Promo code', | ||||||||||||||||||||||||||||
| 148 | optional => 1, | ||||||||||||||||||||||||||||
| 149 | max => 100, | ||||||||||||||||||||||||||||
| 150 | }, | ||||||||||||||||||||||||||||
| 151 | }, | ||||||||||||||||||||||||||||
| 152 | ); | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | 0 | ▶ | unless ( $self->form_checker_ok ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 155 | 0 | $self->flash( | |||||||||||||||||||||||||||
| 156 | form_checker_error_wrapped => $self->form_checker_error_wrapped, | ||||||||||||||||||||||||||||
| 157 | ); | ||||||||||||||||||||||||||||
| 158 | 0 | $self->stash( cart => $cart ); | |||||||||||||||||||||||||||
| 159 | 0 | $self->render(template => 'cart/checkout'); | |||||||||||||||||||||||||||
| 160 | 0 | return; | |||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | # TODO: refactor this into Module::Plugable | ||||||||||||||||||||||||||||
| 164 | 0 | my $handler = 'XTaTIK::Plugin::Cart::' . $self->config('checkout_system'); | |||||||||||||||||||||||||||
| 165 | 0 | ▶ | eval "require $handler" or die $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | 0 | $self->stash( checkout_html => $handler->new->checkout( $self ) ); | |||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | 1 | 1; | |||||||||||||||||||||||||||