Add free postage
[app-web-oof.git] / lib / App / Web / Oof.pm
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);
This page took 0.01 seconds and 4 git commands to generate.