Index: Delivery.pm =================================================================== --- Delivery.pm (revision 258) +++ Delivery.pm (revision 259) @@ -12,15 +12,19 @@ [0, 'Не активна'], [1, 'Действует'], ], - }, + }, { 'attr' => 'dtime', 'hidden' => 1 }, - { 'attr' => 'price', 'type' => 'string', 'rusname' => 'Стоимость доставки (NN или NN%)', default => 0 }, + { 'attr' => 'price', 'type' => 'string', 'rusname' => 'Стоимость доставки (число)', default => 0 }, { 'attr' => 'price_modify', 'type' => 'cost_level', 'rusname' => 'Стоимость доставки с учетом стоимости заказа' }, + { 'attr' => 'price_region', 'type' => 'cost_region', 'rusname' => 'Стоимость доставки с учетом региона' }, { 'attr' => 'abstr', 'type' => 'text', 'rusname' => 'Краткое описание' }, { 'attr' => 'fields', 'type' => 'status_multi', 'rusname' => 'Поля, необходимые к заполнению', 'cases' => [ ['timeline','Время заказа'], ['zipcode','Почтовый индекс'], + ['country','Страна'], + ['area','Регион из списка'], + ['town_id','Город из списка'], ['town','Город'], ['address','Адрес'], ['metro','Ближайшее метро'], @@ -32,15 +36,25 @@ sub price_actual { my $self = shift; - my $sum = shift; + my (%opts) = @_; + + my $sum = delete $opts{sum}; + my $region_id = exists $opts{region} && ref $opts{region} ? $opts{region}->id : exists $opts{region_id} ? $opts{region_id} : undef; my $price = $self->price; - $price = defined $price && $price =~ /^\d+$/ ? $price : 0; + $price = defined $price && $price =~ /^\d+$/ ? $price : 'не определена'; - if ( $sum ) { + if ( $region_id ) { + if ( $self->price_region ) { + my $region_price = $json->decode( $self->price_region ); + if ( ref $region_price eq 'HASH' && exists $region_price->{$region_id} ) { + $price = $region_price->{$region_id}; + } + } + } elsif ( $sum ) { if ( $self->price_modify ) { - my $modify = $json->decode( $self->price_modify ); - if ( ref $modify eq 'ARRAY' && @$modify ) { - foreach my $mod ( @$modify ) { + my $price_modify = $json->decode( $self->price_modify ); + if ( ref $price_modify eq 'ARRAY' && @$price_modify ) { + foreach my $mod ( @$price_modify ) { if ( $mod->{level} <= $sum ) { $price = $mod->{cost}; } @@ -47,12 +61,30 @@ } } } - return $price; - } else { - return $price; } + return $price; } +sub get_fields +{ + my $self = shift; + my $fields = $self->fields; + my @fields = @$fields if $fields && ref $fields eq 'ARRAY'; + + return @fields; +} + +sub check_field +{ + my $self = shift; + my $field = shift; + return unless $field; + my $fields = $self->fields; + my %fields = map { $_ => 1 } @$fields if ref $fields eq 'ARRAY' && @$fields; + + return exists $fields{$field} ? 1 : 0; +} + sub class_name { return 'Способ доставки';