| 1 | package Dancer::Plugin::Interchange6::Routes::Checkout; | ||
| 2 | |||
| 3 | use Dancer ':syntax'; | ||
| 4 | use Dancer::Plugin; | ||
| 5 | use Dancer::Plugin::Interchange6; | ||
| 6 | |||
| 7 | =head1 NAME | ||
| 8 | |||
| 9 | Dancer::Plugin::Interchange6::Routes::Checkout - Checkout routes for Interchange6 Shop Machine | ||
| 10 | |||
| 11 | =cut | ||
| 12 | |||
| 13 | register_hook 'before_checkout_display'; | ||
| 14 | |||
| 15 | =head1 DESCRIPTION | ||
| 16 | |||
| 17 | This route isn't active by default and B<not recommended>. | ||
| 18 | |||
| 19 | =head1 FUNCTIONS | ||
| 20 | |||
| 21 | =head2 checkout_route | ||
| 22 | |||
| 23 | Returns the checkout route based on the passed routes configuration. | ||
| 24 | |||
| 25 | =cut | ||
| 26 | |||
| 27 | sub checkout_route { | ||
| 28 | my $routes_config = shift; | ||
| 29 | |||
| 30 | return sub { | ||
| 31 | my %values; | ||
| 32 | |||
| 33 | # add stuff useful for cart display | ||
| 34 | my $cart = cart; | ||
| 35 | $values{cart_subtotal} = $cart->subtotal; | ||
| 36 | $values{cart_total} = $cart->total; | ||
| 37 | $values{cart} = $cart->products; | ||
| 38 | |||
| 39 | # call before_checkout_display route so template tokens | ||
| 40 | # can be injected | ||
| 41 | execute_hook('before_checkout_display', \%values); | ||
| 42 | template $routes_config->{checkout}->{template}, \%values; | ||
| 43 | } | ||
| 44 | } | ||
| 45 | |||
| 46 | 1; |