• Delivery.pm

    258 259  
    12 12 [0, 'Не активна'],
    13 13 [1, 'Действует'],
    14 14 ],
    15 },
    15 },
    16 16 { 'attr' => 'dtime', 'hidden' => 1 },
    17 { 'attr' => 'price', 'type' => 'string', 'rusname' => 'Стоимость доставки (NN или NN%)', default => 0 },
    17 { 'attr' => 'price', 'type' => 'string', 'rusname' => 'Стоимость доставки (число)', default => 0 },
    18 18 { 'attr' => 'price_modify', 'type' => 'cost_level', 'rusname' => 'Стоимость доставки с учетом стоимости заказа' },
    19 { 'attr' => 'price_region', 'type' => 'cost_region', 'rusname' => 'Стоимость доставки с учетом региона' },
    19 20 { 'attr' => 'abstr', 'type' => 'text', 'rusname' => 'Краткое описание' },
    20 21 { 'attr' => 'fields', 'type' => 'status_multi', 'rusname' => 'Поля, необходимые к заполнению',
    21 22 'cases' => [
    22 23 ['timeline','Время заказа'],
    23 24 ['zipcode','Почтовый индекс'],
    25 ['country','Страна'],
    26 ['area','Регион из списка'],
    27 ['town_id','Город из списка'],
    24 28 ['town','Город'],
    25 29 ['address','Адрес'],
    26 30 ['metro','Ближайшее метро'],
     
    32 36 sub price_actual
    33 37 {
    34 38 my $self = shift;
    35 my $sum = shift;
    39 my (%opts) = @_;
    40
    41 my $sum = delete $opts{sum};
    42 my $region_id = exists $opts{region} && ref $opts{region} ? $opts{region}->id : exists $opts{region_id} ? $opts{region_id} : undef;
    36 43 my $price = $self->price;
    37 $price = defined $price && $price =~ /^\d+$/ ? $price : 0;
    44 $price = defined $price && $price =~ /^\d+$/ ? $price : 'не определена';
    38 45
    39 if ( $sum ) {
    46 if ( $region_id ) {
    47 if ( $self->price_region ) {
    48 my $region_price = $json->decode( $self->price_region );
    49 if ( ref $region_price eq 'HASH' && exists $region_price->{$region_id} ) {
    50 $price = $region_price->{$region_id};
    51 }
    52 }
    53 } elsif ( $sum ) {
    40 54 if ( $self->price_modify ) {
    41 my $modify = $json->decode( $self->price_modify );
    42 if ( ref $modify eq 'ARRAY' && @$modify ) {
    43 foreach my $mod ( @$modify ) {
    55 my $price_modify = $json->decode( $self->price_modify );
    56 if ( ref $price_modify eq 'ARRAY' && @$price_modify ) {
    57 foreach my $mod ( @$price_modify ) {
    44 58 if ( $mod->{level} <= $sum ) {
    45 59 $price = $mod->{cost};
    46 60 }
    47 61 }
    48 62 }
    49 63 }
    50 return $price;
    51 } else {
    52 return $price;
    53 64 }
    65 return $price;
    54 66 }
    55 67
    68 sub get_fields
    69 {
    70 my $self = shift;
    71 my $fields = $self->fields;
    72 my @fields = @$fields if $fields && ref $fields eq 'ARRAY';
    73
    74 return @fields;
    75 }
    76
    77 sub check_field
    78 {
    79 my $self = shift;
    80 my $field = shift;
    81 return unless $field;
    82 my $fields = $self->fields;
    83 my %fields = map { $_ => 1 } @$fields if ref $fields eq 'ARRAY' && @$fields;
    84
    85 return exists $fields{$field} ? 1 : 0;
    86 }
    87
    56 88 sub class_name
    57 89 {
    58 90 return 'Способ доставки';