From 8bbff1bcc40acc652541fcda101bda44de264921 Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Sat, 5 Mar 2016 17:47:36 +0000 Subject: [PATCH] Add free postage --- db.sql | 13 +++++++------ lib/App/Web/Oof.pm | 8 ++++++-- static/style.css | 8 ++++++++ tmpl/continue.html | 2 +- tmpl/form.html | 2 +- 5 files changed, 23 insertions(+), 10 deletions(-) diff --git a/db.sql b/db.sql index d8691f4..eaff6f2 100644 --- a/db.sql +++ b/db.sql @@ -1,10 +1,11 @@ CREATE TABLE IF NOT EXISTS products ( - product serial PRIMARY KEY, - title TEXT NOT NULL, - subtitle TEXT NOT NULL, - summary TEXT NOT NULL, - price INT NOT NULL, - stock INT NOT NULL, + product serial PRIMARY KEY, + title TEXT NOT NULL, + subtitle TEXT NOT NULL, + summary TEXT NOT NULL, + price INT NOT NULL, + stock INT NOT NULL, + freepost BOOLEAN NOT NULL DEFAULT FALSE, CONSTRAINT positive_stock CHECK (stock >= 0) ); diff --git a/lib/App/Web/Oof.pm b/lib/App/Web/Oof.pm index 3e76325..3310dd1 100644 --- a/lib/App/Web/Oof.pm +++ b/lib/App/Web/Oof.pm @@ -66,6 +66,7 @@ sub form_table_row { my ($data, $tr) = @_; $tr->fclass($_)->replace_content($data->{$_}) for qw/title subtitle stock/; $tr->fclass('price')->replace_content(stringify_money $data->{price}); + $tr->fclass('freepost')->detach unless $data->{freepost}; $tr->fclass('title')->attr('data-product', $data->{product}); $tr->fclass('title')->attr('href', '/details/'.$data->{product}.'/'.make_slug $data->{title}); # $tr->fclass('title')->attr('data-summary', $data->{summary}); @@ -87,6 +88,7 @@ sub form_app { sub continue_table_row { my ($data, $tr) = @_; $tr->fclass($_)->replace_content($data->{$_}) for qw/title subtitle quantity/; + $tr->fclass('freepost')->detach unless $data->{freepost}; $tr->fclass('price')->replace_content(stringify_money $data->{subtotal}); $tr->fclass('title')->attr('data-product', $data->{product}); } @@ -98,7 +100,7 @@ sub continue_app { my $req = Plack::Request->new($env); my $params = $req->body_parameters; - my ($quant, $total, @data, @notes); + my ($quant, $quant_freepost, $total, @data, @notes) = (0) x 3; for (sort keys %$params) { next unless /^quant/; next unless $params->{$_}; @@ -114,6 +116,7 @@ sub continue_app { } $data->{subtotal} = $data->{price} * $data->{quantity}; $quant += $data->{quantity}; + $quant_freepost += $data->{quantity} if $data->{freepost}; $total += $data->{subtotal}; push @data, $data } @@ -139,7 +142,8 @@ sub continue_app { } $tree->look_down(name => 'discount')->detach unless $dvalue; $tree->fid('discount_tr')->detach unless $dvalue; - my $postage = 220 + 50 * $quant; + my $postage = 220 + 50 * ($quant - $quant_freepost); + $postage = 0 if $quant == $quant_freepost; $tree->fid('postage')->replace_content(stringify_money $postage); $total += $postage; $tree->fid('total')->replace_content(stringify_money $total); diff --git a/static/style.css b/static/style.css index f95eb41..3679d1d 100644 --- a/static/style.css +++ b/static/style.css @@ -61,6 +61,14 @@ h2 { width: 100%; } +#items td:nth-child(2), #order td:nth-child(3) { + text-align: center; +} + +.freepost { + color: green; +} + table,th,td { border-collapse: collapse; } diff --git a/tmpl/continue.html b/tmpl/continue.html index 7cbbaa9..9df87eb 100644 --- a/tmpl/continue.html +++ b/tmpl/continue.html @@ -12,7 +12,7 @@
- +
ItemQuantityPrice



FREE P&P

Totals

diff --git a/tmpl/form.html b/tmpl/form.html index b719c2e..0b8e35c 100644 --- a/tmpl/form.html +++ b/tmpl/form.html @@ -10,7 +10,7 @@ - +
ItemPriceStockQuantity



FREE P&P

-- 2.39.2