Revision 205

Date:
2012/04/06 11:27:43
Author:
ahitrov
Revision Log:
Delivery price differs according to order sum
Files:

Legend:

 
Added
 
Removed
 
Modified
  • utf8/plugins/webshop/comps/contenido/components/inputs/cost_level.msn

     
    1 <%once>
    2
    3 use JSON::XS;
    4 my $json = JSON::XS->new->utf8;
    5
    6 </%once>
    7 <%args>
    8
    9 $name => undef
    10 $rusname => undef
    11 $check => undef
    12
    13 </%args>
    14 <%init>
    15
    16 my $fields = $check ? $json->decode($check) : [];
    17
    18 $m->out('');
    19 $m->out('<table width="95%" style="margin:5px 0;padding:5 6 5 6;border:1px solid #ccc;font-size:70%;font-family:Tahoma;background-color:#f5f5f5;color:#000;">');
    20 $m->out('<tr bgcolor="silver" valign="top"><th width="40%"><h5 style="margin:0; padding:4px; font-size:11px; color:blue;">Порог стоимости (сумма заказа больше или равна):</h5></th>');
    21 $m->out('<th width="60%"><h5 style="margin:0; padding:4px; font-size:11px; color:blue;">Стоимость доставки (% или число):</h5></th></tr>');
    22
    23 my $max = scalar @$fields + 2;
    24 for my $i ( 1..$max ) {
    25 my $rusname = "$rusname N$i";
    26 my $object = $fields->[$i-1];
    27 $m->comp('.field',
    28 name => $name,
    29 object => $object,
    30 number => $i,
    31 );
    32 }
    33 $m->out('</table>');
    34
    35 </%init>
    36 <%def .field>
    37 <%args>
    38
    39 $name => undef
    40 $object => undef
    41 $number => undef
    42
    43 </%args>
    44 <%init>
    45 </%init>
    46 <tr valign="top">
    47 <td><input type="text" name="<% $name.'_level_'.$number %>" value="<% (ref $object ? $object->{level} : '') |h %>" style="width:97%"></td>
    48 <td><input type="text" name="<% $name.'_cost_'.$number %>" value="<% (ref $object ? $object->{cost} : '') |h %>" style="width:97%;"></td>
    49 </tr>
    50 </%def>
  • utf8/plugins/webshop/comps/contenido/components/outputs/cost_level.msn

     
    1 <%once>
    2
    3 use JSON::XS;
    4 my $json = JSON::XS->new;
    5
    6 </%once>
    7 <%args>
    8
    9 $name => undef
    10 $SETS => undef
    11
    12 </%args>
    13 <%init>
    14
    15 return undef if (! ref($SETS));
    16 return undef if (! $name);
    17
    18 my $FIELDS = {};
    19 while (my ($element,$value) = each %{$SETS}) {
    20 if ( $element =~ /^${name}_level_(\d+)$/ ) {
    21 my $index = $1;
    22 $value =~ s/^\s+//s;
    23 $value =~ s/\s+$//s;
    24 if ( defined $value && $value =~ /^\d+$/ ) {
    25 $FIELDS->{$index}{level} = $value;
    26 }
    27 } elsif ( $element =~ /^${name}_cost_(\d+)$/ ) {
    28 my $index = $1;
    29 $value =~ s/^\s+//s;
    30 $value =~ s/\s+$//s;
    31 if ( defined $value && ($value =~ /^\d+$/ || $value =~ /^\d+[\.\,]\d+$/ || $value =~ /^\d+%$/) ) {
    32 $value =~ s/\,/\./;
    33 $FIELDS->{$index}{cost} = $value;
    34 }
    35 }
    36 }
    37 my @FIELDS = sort { int($a->{level}) <=> int($b->{level}) } grep { $_->{level} && defined $_->{cost} } values %$FIELDS;
    38 return $json->encode(\@FIELDS);
    39
    40 </%init>
  • utf8/plugins/webshop/comps/contenido/webshop/index.html

     
    38 38 <h4 align="center"><i>---- Нет документов -----</i></h4>
    39 39 % }
    40 40
    41
    42 41 </td>
    43 42 <td width="1%">&nbsp;</td>
    44 43 </tr>
     
    50 49
    51 50 $ost => 1
    52 51 $p => 1
    52 $delete => undef
    53 53
    54 54 </%args>
    55 55 <%init>
     
    78 78 my ($status_map) = grep { $_->{attr} eq 'status' } @structure;
    79 79 my ($current_status) = grep { $_->[0] == $ost } @{$status_map->{cases}};
    80 80
    81 my $active_rights = $m->comp('/contenido/webshop/subs/user_rights.msn');
    82 if ( !$active_rights && $delete ) {
    83 my $return_params = join ('&', map { $_.'='.$filter_params{$_} } grep { $_ ne 's' } keys %filter_params );
    84 my %deleted;
    85 while ( my ($field, $value) = each %ARGS ) {
    86 if ( $field =~ /^delete_(\d+)_(\w+)$/ ) {
    87 my $oid = $1;
    88 my $attr = $2;
    89 $deleted{$oid}{$attr} = $value;
    90 }
    91 }
    92 my %classes = map { $_->{class} => 1 } values %deleted;
    93 foreach my $delete_class ( keys %classes ) {
    94 my @ids;
    95 while ( my ($oid, $attr) = each %deleted) {
    96 push @ids, $oid if exists $attr->{id} && $attr->{id} && ($attr->{class} eq $delete_class);
    97 }
    98 my @objects = $keeper->get_documents (
    99 id => \@ids,
    100 class => $delete_class
    101 ) if @ids;
    102 foreach my $object ( @objects ) {
    103 my $document_access = $user->section_accesses($user, $object->section);
    104 next unless $document_access == 2;
    105 $object->delete;
    106 }
    107 }
    108 $m->redirect("/contenido/webshop/".($return_params ? '?'.$return_params : ''));
    109 }
    110
    81 111 </%init>
  • utf8/plugins/webshop/lib/webshop/Delivery.pm

     
    1 1 package webshop::Delivery;
    2 2
    3 3 use base "Contenido::Document";
    4 use JSON::XS;
    5 our $json = JSON::XS->new->utf8;
    6
    4 7 sub extra_properties
    5 8 {
    6 9 return (
     
    12 15 },
    13 16 { 'attr' => 'dtime', 'hidden' => 1 },
    14 17 { 'attr' => 'price', 'type' => 'string', 'rusname' => 'Стоимость доставки (NN или NN%)', default => 0 },
    18 { 'attr' => 'price_modify', 'type' => 'cost_level', 'rusname' => 'Стоимость доставки с учетом стоимости заказа' },
    15 19 { 'attr' => 'abstr', 'type' => 'text', 'rusname' => 'Краткое описание' },
    16 20 { 'attr' => 'fields', 'type' => 'status_multi', 'rusname' => 'Поля, необходимые к заполнению',
    17 21 'cases' => [
     
    25 29 )
    26 30 }
    27 31
    32 sub price_actual
    33 {
    34 my $self = shift;
    35 my $sum = shift;
    36 my $price = $self->price;
    37 $price = defined $price && $price =~ /^\d+$/ ? $price : 0;
    38
    39 if ( $sum ) {
    40 if ( $self->price_modify ) {
    41 my $modify = $json->decode( $self->price_modify );
    42 if ( ref $modify eq 'ARRAY' && @$modify ) {
    43 foreach my $mod ( @$modify ) {
    44 if ( $mod->{level} <= $sum ) {
    45 $price = $mod->{cost};
    46 }
    47 }
    48 }
    49 }
    50 return $price;
    51 } else {
    52 return $price;
    53 }
    54 }
    55
    28 56 sub class_name
    29 57 {
    30 58 return 'Способ доставки';