Add free postage
authorMarius Gavrilescu <marius@ieval.ro>
Sat, 5 Mar 2016 17:47:36 +0000 (17:47 +0000)
committerMarius Gavrilescu <marius@ieval.ro>
Sat, 5 Mar 2016 17:47:36 +0000 (17:47 +0000)
db.sql
lib/App/Web/Oof.pm
static/style.css
tmpl/continue.html
tmpl/form.html

diff --git a/db.sql b/db.sql
index d8691f4d5cafa479137ca5a2c27f2c3f5ef1ff26..eaff6f267247e5ce77fdfbca403424ce3c0e5cf0 100644 (file)
--- 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)
 );
 
index 3e76325eda5509c2ce55d8f5c6031b1ca627b3ad..3310dd1e6bbdaa69792723dd503371b36dbe9ba4 100644 (file)
@@ -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);
index f95eb4145761c1b5ee5f113f270b188841f64cf9..3679d1d917cbd177bd9136d7761256fe00d92c96 100644 (file)
@@ -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;
 }
index 7cbbaa9ae92607523650901d86cb1fa14cc34da2..9df87eb7950c7c8b6d3338027cbaa42e8ec12c0b 100644 (file)
@@ -12,7 +12,7 @@
 <form action="/order" method="POST">
 <table id="order">
 <thead><tr><th>Item<th>Quantity<th>Price</thead>
-<tbody><tr><td class="item"><a href="#" class="title"></a><br><span class="subtitle"></span><td class="quantity"><td class="price"></tbody>
+<tbody><tr><td class="item"><a href="#" class="title"></a><br><span class="subtitle"></span><td class="quantity"><td><span class="price"></span><span class="freepost"><br>FREE P&amp;P</span></tbody>
 </table>
 
 <h2>Totals</h2>
index b719c2e2ab2dba5b47280bcca98dfa11043403ec..0b8e35c41f61aa6753fbcf499bb99ba391b78674 100644 (file)
@@ -10,7 +10,7 @@
 <form action="continue" method="POST">
 <table id="items">
 <thead><tr><th>Item<th>Price<th>Stock<th>Quantity</thead>
-<tbody><tr><td class="item"><a target="lp4y_pics" href="#" class="title"></a><br><span class="subtitle"></span><td class="price"><td class="stock"><td><input class="quantity" type="number" min="0" value="0"></tbody>
+<tbody><tr><td class="item"><a target="lp4y_pics" href="#" class="title"></a><br><span class="subtitle"></span><td><span class="price"></span><span class="freepost"><br>FREE P&amp;P</span><td class="stock"><td><input class="quantity" type="number" min="0" value="0"></tbody>
 </table>
 
 <label>Discount code (optional)<br><input name="discount" type="text"></label><br>
This page took 0.015061 seconds and 4 git commands to generate.