<%args> $c => 'default' <%shared> my $database ='chaliceart'; my $database_login = 'chaliceart'; my $database_pass = 'chaliceart'; my $dbh; <%init> use Data::Dumper; $dbh = DBI->connect("DBI:mysql:$database", $database_login, $database_pass) || $m->comp("error_noreturn", message => "Database name,
login, or password is incorrect."); my @bob; #$m->session->{cart_array} = \@bob; <& $c &> <%def default> <%doc> <%doc>
ChaliceArt Shopping Cart

<& list_cart_contents&>







<%def cart_error> <%init> use MIME::Lite; my $body = $ARGS{'errstr'}."\n"; $body .= Dumper($m->session,\%ENV,\%ARGS,$m->request_args); my $email = MIME::Lite->new( To => $ARGS{'to'} || 'techsupport@chaliceart.com', Subject => $ARGS{'subject'} || 'error', From => 'program_error@chaliceart.com', Type => 'TEXT', Data => $body); $email->delete("date"); $email->send; Sorry Chalice Art Shopping Cart is experiencing technical difficulties please try again later. or contact techsupport@chaliceart.com. <%perl> $m->abort; <%def list_cart_contents> <%init> my $list = $m->session->{cart_array}; my $subtotal = 0; my $total = 0; my $shipping_hash = $m->comp('get_shipping'); my $shipping = $m->request_args->{'shipping'} || $shipping_hash->{'price'}; foreach(@$list){ $_->{'item_shippping_method'} = $m->request_args->{'shipping_method'} || $shipping_hash->{'method'}; $shipping += $_->{'item_shipping'}; $subtotal += ($_->{item_price} * $_->{item_quantity}); } $m->comp('cart_error', 'to' => 'techsupport@chaliceart.com', 'subject' => 'error in cart.htm no shipping method', 'errstr' => 'no shipping method') if(!$shipping); if((!$m->session->{'x_invoice_num'}) && (!$m->request_args->{'noinvoice'})){ $m->session->{'x_invoice_num'} = $m->comp('insert_invoice', shipping => $shipping, subtotal => $subtotal); }elsif(!$m->request_args->{'noinvoice'}){ $m->comp('update_invoice', shipping => $shipping, subtotal => $subtotal); }else{ $shipping = 0; $total = 0; $subtotal = 0; } $subtotal = 0; % foreach my $item (@$list) { % $subtotal += ($item->{item_price} * $item->{item_quantity}); %# $shipping += ($item->{item_quantity} * $item->{item_shipping}); %}
Image
Item
Quantity
Price
<%$item->{item_title}%>
<%$item->{item_name}%>
<%$item->{item_extra}%><%"\n"%>
<%$item->{item_quantity}%>
$<%$item->{item_price} * $item->{item_quantity}%>
 
Description
Subtotal
$<%$subtotal%>
Shipping
$<%$shipping%>
Total
$<%$subtotal + $shipping%>
<&shipping_options_nav&>
%if(!$m->request_args->{'noinvoice'}){ %}else{ %}
%if(!$m->request_args->{'noinvoice'}){ %}else{ %}

Texas residents only: 6% sales tax will be added to purchases. <%def insert_invoice> <%init> use Storable qw{freeze}; use Date::Calc qw{:all}; my $order = $m->session->{cart_array}; $dbh->do("LOCK TABLES"); my $max_invoice_id = $dbh->selectrow_array("Select max(invoice_id) from Invoice"); my $invoice_num = $dbh->selectrow_array("select invoice_num from Invoice where invoice_id = ?",undef,$max_invoice_id); $dbh->do("UNLOCK TABLES"); $invoice_num++; $invoice_num = sprintf("%010s",$invoice_num); $dbh->do("Insert into Invoice set invoice_status = ?, invoice_date = ?, invoice_order = ?, invoice_amount = ?, invoice_freight = ?, invoice_num = ?", undef, 'VIEW_CART', sprintf("%04d%02d%02d%02d%02d%02d",Today_and_Now()), freeze($order), $ARGS{subtotal}, $ARGS{shipping}, $invoice_num ); return $invoice_num; <%def update_invoice> <%init> use Storable qw{freeze}; use Date::Calc qw{:all}; my $invoice_num = $m->session->{'x_invoice_num'}; my $order = $m->session->{cart_array}; $dbh->do("update Invoice set invoice_status = ?, invoice_date = ?, invoice_order = ?, invoice_amount = ?, invoice_freight = ? where invoice_num = ?", undef, 'VIEW_CART', sprintf("%04d%02d%02d%02d%02d%02d",Today_and_Now()), freeze($order), $ARGS{subtotal}, $ARGS{shipping}, sprintf("%010s",$invoice_num) ); <%def void_invoice> <%init> use DBI; my $void; $dbh->do("update Invoice set invoice_status = ? where invoice_num = ?", undef, 'CUSTOMER_VOIDED', $ARGS{'invoice_num'}) if($ARGS{'invoice_num'}); <%def get_shipping> <%init> use DBI; return $dbh->selectrow_hashref("select * from shipping where shipping_id=?",undef,'1'); <%def shipping_options_nav> <%init> use DBI; my $shipping_options = $dbh->selectall_arrayref("select * from shipping",{ Columns=>{}}); #print "
";
#print Dumper($m->request_args->{'shipping'});
#$m->flush_buffer;
#$m->abort;


Shipping Options: %if(!$m->request_args->{'noinvoice'}){ %} %foreach my $method(@$shipping_options){ % if($m->request_args->{'shipping'} == $method->{'price'}){ % }else{ % } %}
<%def usr_cart_error> <%init> my $link = $m->session->{'errstr'};#'HERE'; delete $m->session->{'errstr'}; <%$link%> <%def add_to_cart> <%init> $m->session->{'contenue_url'} = $ENV{'HTTP_REFERER'}; my $current_cart = $m->session->{cart_array}; my $price = $m->request_args->{price}; my $item_name = $m->request_args->{name}; my $item_extra = $m->request_args->{extra}; my $item_title = $m->request_args->{item_name}; my $comment; if($m->request_args->{price_menu}){ if($m->request_args->{price_menu} eq 'void'){ $m->session->{'errstr'} = "This product:
".$item_title."
".$item_name."
".$item_extra."
requires that an option be selected please click HERE to return to previous page."; $m->redirect("?c=usr_cart_error"); } ($price,$comment) = split(/,/,$m->request_args->{price_menu}) } #print "
";
#print Dumper(\%ENV);
#$m->flush_buffer;
#$m->abort;

#
# Check to see if we already have this item.  If so, then increment its quantity.

foreach (@$current_cart) {
 if ( ( $_->{item_name} eq $item_name ) 
&&    ($_->{item_extra} eq $item_extra) 
&&    ($_->{item_title} eq $item_title) ) {
   $_->{item_quantity} += 1;
   $m->redirect("cart.htm");
  }
}
#
# Add to cart
my $extra = $m->request_args->{extra};
my $void;
if($comment){
#my @temp = split(/\s/,$extra);
#print "
";
#print Dumper($extra);
#$m->flush_buffer;
#$m->abort;
   #$extra =~ s/\$.*//g;
   $comment =~ s/\$.*//g;
   $extra .= '
Option: '.$comment.' '.$m->request_args->{comment}; }else{ $extra .= '
Option: '.$m->request_args->{comment}; } push(@$current_cart, { 'item_title' => $m->request_args->{item_name}, 'item_name' => $m->request_args->{name}, 'item_extra' => $extra, 'item_quantity' => 1, 'item_image_path' => $m->request_args->{image_path}, 'item_price' => $price, 'item_shippping_method' => '', 'item_shipping' => $m->request_args->{shipping} } ); $m->session->{cart_array} = $current_cart; $m->redirect("cart.htm"); <%def clear_cart> <%init> my @bob; delete $m->session->{cart_array}; $m->comp('void_invoice', invoice_num => $m->session->{'x_invoice_num'}); delete $m->session->{'x_invoice_num'}; $m->redirect("cart.htm?noinvoice=1");