Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 93b347a8

Von Tamino Steinert vor 11 Monaten hinzugefügt

Varianten: Varianten Eigenschaften zum Stammartikel hinzufügen

Unterschiede anzeigen:

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::JSON;
......
221 224
  }
222 225
}
223 226

  
227
sub action_update_variant_property_value_options {
228
  my ($self) = @_;
229

  
230
  my %select_tag_options = (
231
    title_key => 'displayable_name',
232
    value_key => 'id',
233
  );
234

  
235
  my @options;
236
  my $variant_property_id = $::form->{add_variant_property};
237
  if ($variant_property_id) {
238
    my $variant_property = SL::DB::VariantProperty->new(id => $variant_property_id)->load;
239
    @options = $variant_property->property_values;
240
  }
241

  
242
  unless (scalar @options) {
243
    $select_tag_options{with_empty}  = 1;
244
    $select_tag_options{empty_title} = t8("Select Variant Property First");
245
  }
246

  
247
  foreach my $variant (@{$self->part->variants}) {
248
    my $select_tag_name = "add_variant_property_value_" . $variant->id;
249
    my $new_select_tag = select_tag(
250
      $select_tag_name, \@options,
251
      %select_tag_options
252
    );
253
    $self->js->replaceWith("#$select_tag_name", $new_select_tag);
254
  }
255

  
256
  $self->js->render();
257
}
258

  
259
sub action_add_variant_property {
260
  my ($self) = @_;
261

  
262
  my $variant_property_id = $::form->{add_variant_property};
263
  die t8("Please select a variant property") unless ($variant_property_id);
264
  foreach my $variant (@{$self->part->variants}) {
265
    die t8("Please select a new variant property value for all variants")
266
      unless $::form->{"add_variant_property_value_" . $variant->id};
267
  }
268

  
269
  SL::DB->client->with_transaction(sub {
270
    SL::DB::VariantPropertyPart->new(
271
      part_id             => $self->part->id,
272
      variant_property_id => $variant_property_id,
273
    )->save;
274
    foreach my $variant (@{$self->part->variants}) {
275
      SL::DB::VariantPropertyValuePart->new(
276
        part_id                   => $variant->id,
277
        variant_property_value_id => $::form->{"add_variant_property_value_" . $variant->id},
278
      )->save;
279
    }
280
    1;
281
  }) or do {
282
    return $self->js->error(t8('Error while adding variant property: ' . @_))->render();
283
  };
284

  
285
  $self->redirect_to(
286
    controller => 'Part',
287
    action     => 'edit',
288
    'part.id'  => $self->part->id
289
  );
290
}
291

  
224 292
sub action_create_variants {
225 293
  my ($self) = @_;
226 294
  my @variant_property_ids = sort keys %{$::form->{variant_properties}};
......
233 301
    return $self->js->error(
234 302
      t8('No property value selected for variant properties: #1.',
235 303
        join(", ",
236
          map {$_->name_translated}
304
          map {$_->displayable_name}
237 305
          grep {!defined $::form->{variant_properties}->{$_->id}->{selected_property_values}}
238 306
          @$variant_properties
239 307
        )
......
359 427
  $self->_set_javascript;
360 428
  $self->_setup_form_action_bar;
361 429

  
362
  my (%assortment_vars, %assembly_vars);
363
  %assortment_vars = %{ $self->prepare_assortment_render_vars } if $self->part->is_assortment;
364
  %assembly_vars   = %{ $self->prepare_assembly_render_vars   } if $self->part->is_assembly;
430
  my (%assortment_vars, %assembly_vars, %parent_variant_vars, %variant_vars);
431
  %assortment_vars     = %{ $self->prepare_assortment_render_vars }     if $self->part->is_assortment;
432
  %assembly_vars       = %{ $self->prepare_assembly_render_vars   }     if $self->part->is_assembly;
433
  %parent_variant_vars = %{ $self->prepare_parent_variant_render_vars } if $self->part->is_parent_variant;
365 434

  
366 435
  $params{CUSTOM_VARIABLES}  = $params{use_as_new} && $::form->{old_id}
367 436
                            ?  CVar->get_custom_variables(module => 'IC', trans_id => $::form->{old_id})
......
390 459
    title             => $title_hash{$self->part->part_type},
391 460
    %assortment_vars,
392 461
    %assembly_vars,
462
    %parent_variant_vars,
393 463
    translations_map  => { map { ($_->language_id   => $_) } @{$self->part->translations} },
394 464
    prices_map        => { map { ($_->pricegroup_id => $_) } @{$self->part->prices      } },
395 465
    oldpartnumber     => $::form->{oldpartnumber},
......
1016 1086
  return \%vars;
1017 1087
}
1018 1088

  
1089
sub prepare_parent_variant_render_vars {
1090
  my ($self) = @_;
1091

  
1092
  my %has_variant_property =
1093
    map { $_->id => 1}
1094
    @{$self->part->variant_properties};
1095
  my @available_variant_properis =
1096
    grep {!$has_variant_property{$_->id}}
1097
    @{SL::DB::Manager::VariantProperty->get_all()};
1098
  my %vars = (
1099
    AVAILABLE_VARIANT_PROPERIES => \@available_variant_properis,
1100
  );
1101

  
1102
  return \%vars;
1103
}
1104

  
1019 1105
sub add {
1020 1106
  my ($self) = @_;
1021 1107

  

Auch abrufbar als: Unified diff