Revision 66c06a13
Von Tamino Steinert vor 10 Monaten hinzugefügt
SL/Controller/Part.pm | ||
---|---|---|
86 | 86 |
$self->add; |
87 | 87 |
}; |
88 | 88 |
|
89 |
sub action_add_parent_variant { |
|
90 |
my ($self, %params) = @_; |
|
91 |
|
|
92 |
$self->part( SL::DB::Part->new_parent_variant ); |
|
93 |
$self->add; |
|
94 |
} |
|
95 |
|
|
89 | 96 |
sub action_add_from_record { |
90 | 97 |
my ($self) = @_; |
91 | 98 |
|
... | ... | |
103 | 110 |
|
104 | 111 |
check_has_valid_part_type($::form->{part_type}); |
105 | 112 |
|
106 |
$self->action_add_part if $::form->{part_type} eq 'part'; |
|
107 |
$self->action_add_service if $::form->{part_type} eq 'service'; |
|
108 |
$self->action_add_assembly if $::form->{part_type} eq 'assembly'; |
|
109 |
$self->action_add_assortment if $::form->{part_type} eq 'assortment'; |
|
113 |
$self->action_add_part if $::form->{part_type} eq 'part'; |
|
114 |
$self->action_add_service if $::form->{part_type} eq 'service'; |
|
115 |
$self->action_add_assembly if $::form->{part_type} eq 'assembly'; |
|
116 |
$self->action_add_assortment if $::form->{part_type} eq 'assortment'; |
|
117 |
$self->action_add_parent_variant if $::form->{part_type} eq 'parent_variant'; |
|
118 |
$self->action_add_variant if $::form->{part_type} eq 'variant'; |
|
110 | 119 |
}; |
111 | 120 |
|
112 | 121 |
sub action_save { |
... | ... | |
212 | 221 |
} |
213 | 222 |
} |
214 | 223 |
|
224 |
sub action_create_variants { |
|
225 |
my ($self) = @_; |
|
226 |
my @variant_property_ids = sort keys %{$::form->{variant_properties}}; |
|
227 |
|
|
228 |
my $part = $self->part; |
|
229 |
my $variant_properties = $part->variant_properties(); |
|
230 |
my @needed_variant_property_ids = sort map {$_->id} @$variant_properties; |
|
231 |
|
|
232 |
if (@variant_property_ids != @needed_variant_property_ids) { |
|
233 |
return $self->js->error( |
|
234 |
t8('No property value selected for variant properties: #1.', |
|
235 |
join(", ", |
|
236 |
map {$_->name_translated} |
|
237 |
grep {!defined $::form->{variant_properties}->{$_->id}->{selected_property_values}} |
|
238 |
@$variant_properties |
|
239 |
) |
|
240 |
) |
|
241 |
)->render(); |
|
242 |
} |
|
243 |
|
|
244 |
my @grouped_variant_property_values = (); |
|
245 |
push @grouped_variant_property_values, |
|
246 |
SL::DB::Manager::VariantPropertyValue->get_all( |
|
247 |
where => [ id => $::form->{variant_properties}->{$_}->{selected_property_values} ] |
|
248 |
) |
|
249 |
for @variant_property_ids; |
|
250 |
|
|
251 |
|
|
252 |
my @variant_property_values_lists = (); |
|
253 |
foreach my $variant_property_values (@grouped_variant_property_values) { |
|
254 |
my @new_lists = (); |
|
255 |
foreach my $variant_property_value (@$variant_property_values) { |
|
256 |
unless (scalar @variant_property_values_lists) { |
|
257 |
push @new_lists, [$variant_property_value]; |
|
258 |
} |
|
259 |
foreach my $variant_property_values_list (@variant_property_values_lists) { |
|
260 |
push @new_lists, [@$variant_property_values_list, $variant_property_value]; |
|
261 |
} |
|
262 |
} |
|
263 |
@variant_property_values_lists = @new_lists; |
|
264 |
} |
|
265 |
|
|
266 |
my @new_variants = (); |
|
267 |
SL::DB->client->with_transaction(sub { |
|
268 |
push @new_variants, $part->create_new_variant($_) |
|
269 |
for @variant_property_values_lists; |
|
270 |
1; |
|
271 |
}) or do { |
|
272 |
return $self->js->error(t8('Error while creating variants: ' . @_))->render(); |
|
273 |
}; |
|
274 |
|
|
275 |
$self->redirect_to( |
|
276 |
controller => 'Part', |
|
277 |
action => 'edit', |
|
278 |
'part.id' => $self->part->id |
|
279 |
); |
|
280 |
} |
|
281 |
|
|
215 | 282 |
sub action_delete { |
216 | 283 |
my ($self) = @_; |
217 | 284 |
|
... | ... | |
307 | 374 |
@{ $params{CUSTOM_VARIABLES_FIRST_TAB} } = extract_by { $_->{first_tab} == 1 } @{ $params{CUSTOM_VARIABLES} }; |
308 | 375 |
} |
309 | 376 |
|
310 |
my %title_hash = ( part => t8('Edit Part'), |
|
311 |
assembly => t8('Edit Assembly'), |
|
312 |
service => t8('Edit Service'), |
|
313 |
assortment => t8('Edit Assortment'), |
|
377 |
my %title_hash = ( part => t8('Edit Part'), |
|
378 |
assembly => t8('Edit Assembly'), |
|
379 |
service => t8('Edit Service'), |
|
380 |
assortment => t8('Edit Assortment'), |
|
381 |
parent_variant => t8('Edit Parent Variant'), |
|
382 |
variant => t8('Edit Variant'), |
|
314 | 383 |
); |
315 | 384 |
|
316 | 385 |
$self->part->prices([]) unless $self->part->prices; |
... | ... | |
955 | 1024 |
$self->_set_javascript; |
956 | 1025 |
$self->_setup_form_action_bar; |
957 | 1026 |
|
958 |
my %title_hash = ( part => t8('Add Part'), |
|
959 |
assembly => t8('Add Assembly'), |
|
960 |
service => t8('Add Service'), |
|
961 |
assortment => t8('Add Assortment'), |
|
1027 |
my %title_hash = ( part => t8('Add Part'), |
|
1028 |
assembly => t8('Add Assembly'), |
|
1029 |
service => t8('Add Service'), |
|
1030 |
assortment => t8('Add Assortment'), |
|
1031 |
parent_variant => t8('Add Parent Variant'), |
|
1032 |
variant => t8('Add Variant'), |
|
962 | 1033 |
); |
963 | 1034 |
|
964 | 1035 |
$self->render( |
... | ... | |
970 | 1041 |
|
971 | 1042 |
sub _set_javascript { |
972 | 1043 |
my ($self) = @_; |
973 |
$::request->layout->use_javascript("${_}.js") for qw(kivi.Part kivi.File kivi.PriceRule kivi.ShopPart kivi.Validator); |
|
1044 |
$::request->layout->use_javascript("${_}.js") for qw(kivi.Part kivi.File kivi.PriceRule kivi.ShopPart kivi.Validator jquery.selectboxes jquery.multiselect2side);
|
|
974 | 1045 |
$::request->layout->add_javascripts_inline("\$(function(){kivi.PriceRule.load_price_rules_for_part(@{[ $self->part->id ]})});") if $self->part->id; |
975 | 1046 |
} |
976 | 1047 |
|
... | ... | |
1585 | 1656 |
} |
1586 | 1657 |
|
1587 | 1658 |
sub check_has_valid_part_type { |
1588 |
die "invalid part_type" unless $_[0] =~ /^(part|service|assembly|assortment)$/; |
|
1659 |
die "invalid part_type" unless $_[0] =~ /^(part|service|assembly|assortment|parent_variant|variant)$/;
|
|
1589 | 1660 |
} |
1590 | 1661 |
|
1591 | 1662 |
|
Auch abrufbar als: Unified diff
Varianten: Stammartikel anlegen und Varianten erstellen