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)
);
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});
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});
}
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->{$_};
}
$data->{subtotal} = $data->{price} * $data->{quantity};
$quant += $data->{quantity};
+ $quant_freepost += $data->{quantity} if $data->{freepost};
$total += $data->{subtotal};
push @data, $data
}
}
$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);
<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&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>