Revision 4d65e27a
Von Tamino Steinert vor 5 Tagen hinzugefügt
SL/Controller/Part.pm | ||
---|---|---|
24 | 24 |
use SL::DB::PriceRuleItem; |
25 | 25 |
use SL::DB::PurchaseBasketItem; |
26 | 26 |
use SL::DB::Shop; |
27 |
use SL::DB::VariantProperty; |
|
28 |
use SL::DB::VariantPropertyPart; |
|
29 |
use SL::DB::VariantPropertyValuePart; |
|
27 | 30 |
use SL::Helper::Flash; |
28 | 31 |
use SL::Helper::PrintOptions; |
29 | 32 |
use SL::Helper::UserPreferences::PartPickerSearch; |
... | ... | |
222 | 225 |
} |
223 | 226 |
} |
224 | 227 |
|
228 |
sub action_update_variant_property_value_options { |
|
229 |
my ($self) = @_; |
|
230 |
|
|
231 |
my %select_tag_options = ( |
|
232 |
title_key => 'displayable_name', |
|
233 |
value_key => 'id', |
|
234 |
); |
|
235 |
|
|
236 |
my @options; |
|
237 |
my $variant_property_id = $::form->{add_variant_property}; |
|
238 |
if ($variant_property_id) { |
|
239 |
my $variant_property = SL::DB::VariantProperty->new(id => $variant_property_id)->load; |
|
240 |
@options = $variant_property->property_values; |
|
241 |
} |
|
242 |
|
|
243 |
unless (scalar @options) { |
|
244 |
$select_tag_options{with_empty} = 1; |
|
245 |
$select_tag_options{empty_title} = t8("Select Variant Property First"); |
|
246 |
} |
|
247 |
|
|
248 |
foreach my $variant (@{$self->part->variants}) { |
|
249 |
my $select_tag_name = "add_variant_property_value_" . $variant->id; |
|
250 |
my $new_select_tag = select_tag( |
|
251 |
$select_tag_name, \@options, |
|
252 |
%select_tag_options |
|
253 |
); |
|
254 |
$self->js->replaceWith("#$select_tag_name", $new_select_tag); |
|
255 |
} |
|
256 |
|
|
257 |
$self->js->render(); |
|
258 |
} |
|
259 |
|
|
260 |
sub action_add_variant_property { |
|
261 |
my ($self) = @_; |
|
262 |
|
|
263 |
my $variant_property_id = $::form->{add_variant_property}; |
|
264 |
die t8("Please select a variant property") unless ($variant_property_id); |
|
265 |
foreach my $variant (@{$self->part->variants}) { |
|
266 |
die t8("Please select a new variant property value for all variants") |
|
267 |
unless $::form->{"add_variant_property_value_" . $variant->id}; |
|
268 |
} |
|
269 |
|
|
270 |
SL::DB->client->with_transaction(sub { |
|
271 |
SL::DB::VariantPropertyPart->new( |
|
272 |
part_id => $self->part->id, |
|
273 |
variant_property_id => $variant_property_id, |
|
274 |
)->save; |
|
275 |
foreach my $variant (@{$self->part->variants}) { |
|
276 |
SL::DB::VariantPropertyValuePart->new( |
|
277 |
part_id => $variant->id, |
|
278 |
variant_property_value_id => $::form->{"add_variant_property_value_" . $variant->id}, |
|
279 |
)->save; |
|
280 |
} |
|
281 |
1; |
|
282 |
}) or do { |
|
283 |
return $self->js->error(t8('Error while adding variant property: ' . @_))->render(); |
|
284 |
}; |
|
285 |
|
|
286 |
$self->redirect_to( |
|
287 |
controller => 'Part', |
|
288 |
action => 'edit', |
|
289 |
'part.id' => $self->part->id |
|
290 |
); |
|
291 |
} |
|
292 |
|
|
225 | 293 |
sub action_create_variants { |
226 | 294 |
my ($self) = @_; |
227 | 295 |
my @variant_property_ids = sort keys %{$::form->{variant_properties}}; |
... | ... | |
234 | 302 |
return $self->js->error( |
235 | 303 |
t8('No property value selected for variant properties: #1.', |
236 | 304 |
join(", ", |
237 |
map {$_->name_translated}
|
|
305 |
map {$_->displayable_name}
|
|
238 | 306 |
grep {!defined $::form->{variant_properties}->{$_->id}->{selected_property_values}} |
239 | 307 |
@$variant_properties |
240 | 308 |
) |
... | ... | |
366 | 434 |
$self->_set_javascript; |
367 | 435 |
$self->_setup_form_action_bar; |
368 | 436 |
|
369 |
my (%assortment_vars, %assembly_vars); |
|
370 |
%assortment_vars = %{ $self->prepare_assortment_render_vars } if $self->part->is_assortment; |
|
371 |
%assembly_vars = %{ $self->prepare_assembly_render_vars } if $self->part->is_assembly; |
|
437 |
my (%assortment_vars, %assembly_vars, %parent_variant_vars, %variant_vars); |
|
438 |
%assortment_vars = %{ $self->prepare_assortment_render_vars } if $self->part->is_assortment; |
|
439 |
%assembly_vars = %{ $self->prepare_assembly_render_vars } if $self->part->is_assembly; |
|
440 |
%parent_variant_vars = %{ $self->prepare_parent_variant_render_vars } if $self->part->is_parent_variant; |
|
372 | 441 |
|
373 | 442 |
$params{CUSTOM_VARIABLES} = $params{use_as_new} && $::form->{old_id} |
374 | 443 |
? CVar->get_custom_variables(module => 'IC', trans_id => $::form->{old_id}) |
... | ... | |
397 | 466 |
title => $title_hash{$self->part->part_type}, |
398 | 467 |
%assortment_vars, |
399 | 468 |
%assembly_vars, |
469 |
%parent_variant_vars, |
|
400 | 470 |
translations_map => { map { ($_->language_id => $_) } @{$self->part->translations} }, |
401 | 471 |
prices_map => { map { ($_->pricegroup_id => $_) } @{$self->part->prices } }, |
402 | 472 |
oldpartnumber => $::form->{oldpartnumber}, |
... | ... | |
1025 | 1095 |
return \%vars; |
1026 | 1096 |
} |
1027 | 1097 |
|
1098 |
sub prepare_parent_variant_render_vars { |
|
1099 |
my ($self) = @_; |
|
1100 |
|
|
1101 |
my %has_variant_property = |
|
1102 |
map { $_->id => 1} |
|
1103 |
@{$self->part->variant_properties}; |
|
1104 |
my @available_variant_properis = |
|
1105 |
grep {!$has_variant_property{$_->id}} |
|
1106 |
@{SL::DB::Manager::VariantProperty->get_all()}; |
|
1107 |
my %vars = ( |
|
1108 |
AVAILABLE_VARIANT_PROPERIES => \@available_variant_properis, |
|
1109 |
); |
|
1110 |
|
|
1111 |
return \%vars; |
|
1112 |
} |
|
1113 |
|
|
1028 | 1114 |
sub add { |
1029 | 1115 |
my ($self) = @_; |
1030 | 1116 |
|
Auch abrufbar als: Unified diff
Varianten: Varianten Eigenschaften zum Stammartikel hinzufügen