]> iEval git - app-web-oof.git/blobdiff - lib/App/Web/Oof.pm
Add order total in email subject
[app-web-oof.git] / lib / App / Web / Oof.pm
index 0ecfd1be76bcf9761d07b2bbb9a3ca46ff533484..a131c9c5a0ae85c63ed92b50906324bd4a9f84b7 100644 (file)
@@ -44,7 +44,7 @@ my $postage_per_item = $ENV{OOF_POSTAGE_PER_ITEM} // 50;
 ##################################################
 
 my %db;
-my ($form, $continue, $order, $details, $pay, $display);
+my ($form, $continue, $order, $details, $pay, $display, $down);
 
 {
        sub parse_html {
@@ -60,6 +60,7 @@ my ($form, $continue, $order, $details, $pay, $display);
        $details  = parse_html 'details';
        $pay      = parse_html 'pay';
        $display  = parse_html 'display';
+       $down     = parse_html 'down';
 }
 
 sub stringify_money { sprintf "£%.2f", $_[0] / 100 }
@@ -74,12 +75,16 @@ sub make_slug {
 sub product_to_schemaorg {
        my ($include_url, %data) = @_;
        my $stock = $data{stock} > 0 ? 'InStock' : 'OutOfStock';
+       my @extra;
+       push @extra, (brand => {'@type' => 'Brand', name => $data{brand}}) if $data{brand};
+       push @extra, (model => $data{model}) if $data{model};
        +{
                '@context' => 'http://schema.org/',
                '@type'    => 'Product',
                name => $data{title},
                image => "/static/fullpics/$data{product}-1.jpg",
                description => $data{subtitle},
+               @extra,
                offers => {
                        '@type' => 'Offer',
                        price => ($data{price} =~ s/(..)$/\.$1/r),
@@ -221,7 +226,7 @@ sub order_app {
                                header => [
                                        From    => $ENV{OOF_EMAIL_FROM},
                                        To      => $ENV{OOF_EMAIL_TO},
-                                       Subject => "Order $id placed",
+                                       Subject => "Order $id placed for ".stringify_money($parms{total}),
                                ],
                                body => 'A new order was placed.',
                        )) if $ENV{OOF_EMAIL_TO};
@@ -277,6 +282,17 @@ sub details_app {
        $tree->fid('pictures')->find('li')->iter3(\@pics, \&details_list_element);
        $tree->fid('jsonld')->replace_content(encode_json product_to_schemaorg '', %data);
 
+       $tree->fid('dd_stock')->replace_content($data{stock});
+       $tree->fid('dd_price')->replace_content(stringify_money $data{price});
+       for (qw/brand model/) {
+               if ($data{$_}) {
+                       $tree->fid("dd_$_")->replace_content($data{$_});
+               } else {
+                       $tree->fid("dt_$_")->detach;
+                       $tree->fid("dd_$_")->detach;
+               }
+       }
+
        for my $ahref ($tree->find('a')) {
                $ahref->attr(href => "/form?highlight=$id") if $ahref->attr('href') eq '/';
        }
@@ -345,6 +361,18 @@ sub app {
                                $res;
                        }
                };
+               enable sub {
+                       my $app = shift;
+                       sub {
+                               if (-f 'down.html') {
+                                       my $down_lit = HTML::Element::Library::super_literal read_file 'down.html';
+                                       my $tree = $down->clone;
+                                       $tree->fid('content')->replace_content($down_lit);
+                                       return [503, ['Content-type' => 'text/html; charset=utf-8'], [$tree->as_HTML]]
+                               }
+                               $app->(@_)
+                       }
+               };
                mount '/' => sub { [301, [Location => '/form'], []] };
                mount '/form'     => \&form_app;
                mount '/continue' => \&continue_app;
This page took 0.022766 seconds and 4 git commands to generate.