1 |
198 |
ahitrov |
package webshop::Address; |
2 |
|
|
|
3 |
|
|
use Contenido::Globals; |
4 |
|
|
use base "Contenido::Document"; |
5 |
|
|
sub extra_properties |
6 |
|
|
{ |
7 |
|
|
return ( |
8 |
|
|
{ 'attr' => 'status', 'type' => 'status', 'rusname' => 'Статус заказа', |
9 |
|
|
'cases' => [ |
10 |
|
|
[0, 'Дополнительный адрес'], |
11 |
|
|
[1, 'Основной адрес'], |
12 |
|
|
], |
13 |
|
|
}, |
14 |
|
|
{ 'attr' => 'name', 'type' => 'string', 'rusname' => 'Контактное лицо' }, |
15 |
259 |
ahitrov |
{ 'attr' => 'phone', 'type' => 'string', 'rusname' => 'Телефон для связи', |
16 |
|
|
mandatory => 1, rel => 'Не указан телефон' }, |
17 |
|
|
{ 'attr' => 'zipcode', 'type' => 'string', 'rusname' => 'Почтовый индекс', |
18 |
|
|
mandatory => 1, rel => 'Не указан почтовый индекс' }, |
19 |
|
|
{ 'attr' => 'area', 'type' => 'lookup', 'rusname' => 'Регион', |
20 |
|
|
lookup_opts => { class => 'webshop::Area', order_by => 'name' }, |
21 |
|
|
allow_null => 1, mandatory => 1, rel => 'Не выбран регион' |
22 |
|
|
}, |
23 |
|
|
{ 'attr' => 'town_id', 'type' => 'lookup', 'rusname' => 'Город', |
24 |
|
|
lookup_opts => { class => 'webshop::Town', order_by => 'name' }, |
25 |
|
|
allow_null => 1, mandatory => 1, rel => 'Не выбран город' |
26 |
|
|
}, |
27 |
|
|
{ 'attr' => 'town', 'type' => 'string', 'rusname' => 'Город', |
28 |
|
|
mandatory => 1, rel => 'Не указан город' }, |
29 |
544 |
ahitrov |
{ 'attr' => 'carrier', 'type' => 'string', 'rusname' => 'Транспортная компания' }, |
30 |
198 |
ahitrov |
{ 'attr' => 'metro', 'type' => 'string', 'rusname' => 'Ближайшее метро' }, |
31 |
259 |
ahitrov |
{ 'attr' => 'address', 'type' => 'text', 'rusname' => 'Адрес доставки', rows => 5, |
32 |
|
|
mandatory => 1, rel => 'Не заполнен адрес доставки' }, |
33 |
784 |
ahitrov |
{ 'attr' => 'axiomus', 'type' => 'text', 'rusname' => 'Адрес axiomus', rows => 5 }, |
34 |
663 |
ahitrov |
{ 'attr' => 'timeline', 'type' => 'string', 'rusname' => 'Предпочтительная дата и время', |
35 |
259 |
ahitrov |
mandatory => 1, rel => 'Вы не указали предпочтительное время получения заказа' }, |
36 |
198 |
ahitrov |
{ 'attr' => 'description', 'type' => 'text', 'rusname' => 'Описание для курьера', rows => 5 }, |
37 |
|
|
) |
38 |
|
|
} |
39 |
|
|
|
40 |
|
|
sub class_name |
41 |
|
|
{ |
42 |
259 |
ahitrov |
return 'Webshop: адрес доставки'; |
43 |
198 |
ahitrov |
} |
44 |
|
|
|
45 |
|
|
sub class_description |
46 |
|
|
{ |
47 |
259 |
ahitrov |
return 'Webshop: адрес доставки'; |
48 |
198 |
ahitrov |
} |
49 |
|
|
|
50 |
|
|
sub class_table |
51 |
|
|
{ |
52 |
|
|
return 'webshop::SQL::AddressTable'; |
53 |
|
|
} |
54 |
|
|
|
55 |
416 |
ahitrov |
sub as_string |
56 |
|
|
{ |
57 |
|
|
my ($self, %opts) = @_; |
58 |
|
|
my $areas = delete $opts{areas}; |
59 |
|
|
|
60 |
|
|
my @string; |
61 |
|
|
push @string, $self->name if $self->name; |
62 |
|
|
push @string, $self->zipcode if $self->zipcode; |
63 |
|
|
if ( $self->area ) { |
64 |
|
|
if ( ref $areas ) { |
65 |
|
|
push @string, $areas->{$self->area}->name if exists $areas->{$self->area}; |
66 |
|
|
} else { |
67 |
|
|
my $area = $self->keeper->get_document_by_id( $self->area, class => 'webshop::Area' ); |
68 |
|
|
push @string, $area->name if ref $area; |
69 |
|
|
} |
70 |
|
|
} |
71 |
|
|
push @string, $self->town if $self->town; |
72 |
|
|
push @string, $self->address if $self->address; |
73 |
|
|
return join(', ', @string); |
74 |
|
|
} |
75 |
|
|
|
76 |
259 |
ahitrov |
sub pre_store |
77 |
|
|
{ |
78 |
|
|
my $self = shift; |
79 |
|
|
|
80 |
|
|
if ( $self->town_id && !$self->town ) { |
81 |
|
|
my $town = webshop::Town->new( $keeper, $self->town_id ); |
82 |
|
|
if ( ref $town ) { |
83 |
|
|
$self->town( $town->name ); |
84 |
|
|
} |
85 |
|
|
} |
86 |
|
|
|
87 |
|
|
return 1; |
88 |
|
|
} |
89 |
|
|
|
90 |
198 |
ahitrov |
1; |