Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 56da9bba

Von Tamino Steinert vor 6 Tagen hinzugefügt

  • ID 56da9bba662605b6a59c2fa444f11bf5465c61c1
  • Vorgänger 1095df47
  • Nachfolger 65c0626e

Varianten: Stammartikel anlegen und Varianten erstellen

Unterschiede anzeigen:

SL/Controller/Part.pm
87 87
  $self->add;
88 88
};
89 89

  
90
sub action_add_parent_variant {
91
  my ($self, %params) = @_;
92

  
93
  $self->part( SL::DB::Part->new_parent_variant );
94
  $self->add;
95
}
96

  
90 97
sub action_add_from_record {
91 98
  my ($self) = @_;
92 99

  
......
104 111

  
105 112
  check_has_valid_part_type($::form->{part_type});
106 113

  
107
  $self->action_add_part       if $::form->{part_type} eq 'part';
108
  $self->action_add_service    if $::form->{part_type} eq 'service';
109
  $self->action_add_assembly   if $::form->{part_type} eq 'assembly';
110
  $self->action_add_assortment if $::form->{part_type} eq 'assortment';
114
  $self->action_add_part           if $::form->{part_type} eq 'part';
115
  $self->action_add_service        if $::form->{part_type} eq 'service';
116
  $self->action_add_assembly       if $::form->{part_type} eq 'assembly';
117
  $self->action_add_assortment     if $::form->{part_type} eq 'assortment';
118
  $self->action_add_parent_variant if $::form->{part_type} eq 'parent_variant';
119
  $self->action_add_variant        if $::form->{part_type} eq 'variant';
111 120
};
112 121

  
113 122
sub action_save {
......
213 222
  }
214 223
}
215 224

  
225
sub action_create_variants {
226
  my ($self) = @_;
227
  my @variant_property_ids = sort keys %{$::form->{variant_properties}};
228

  
229
  my $part = $self->part;
230
  my $variant_properties = $part->variant_properties();
231
  my @needed_variant_property_ids = sort map {$_->id} @$variant_properties;
232

  
233
  if (@variant_property_ids != @needed_variant_property_ids) {
234
    return $self->js->error(
235
      t8('No property value selected for variant properties: #1.',
236
        join(", ",
237
          map {$_->name_translated}
238
          grep {!defined $::form->{variant_properties}->{$_->id}->{selected_property_values}}
239
          @$variant_properties
240
        )
241
      )
242
    )->render();
243
  }
244

  
245
  my @grouped_variant_property_values = ();
246
  push @grouped_variant_property_values,
247
    SL::DB::Manager::VariantPropertyValue->get_all(
248
      where => [ id => $::form->{variant_properties}->{$_}->{selected_property_values} ]
249
    )
250
    for @variant_property_ids;
251

  
252

  
253
  my @variant_property_values_lists = ();
254
  foreach my $variant_property_values (@grouped_variant_property_values) {
255
    my @new_lists = ();
256
    foreach my $variant_property_value (@$variant_property_values) {
257
      unless (scalar @variant_property_values_lists) {
258
        push @new_lists, [$variant_property_value];
259
      }
260
      foreach my $variant_property_values_list (@variant_property_values_lists) {
261
        push @new_lists, [@$variant_property_values_list, $variant_property_value];
262
      }
263
    }
264
    @variant_property_values_lists = @new_lists;
265
  }
266

  
267
  my @new_variants = ();
268
  SL::DB->client->with_transaction(sub {
269
    push @new_variants, $part->create_new_variant($_)
270
      for @variant_property_values_lists;
271
    1;
272
  }) or do {
273
    return $self->js->error(t8('Error while creating variants: ' . @_))->render();
274
  };
275

  
276
  $self->redirect_to(
277
    controller => 'Part',
278
    action     => 'edit',
279
    'part.id'  => $self->part->id
280
  );
281
}
282

  
216 283
sub action_delete {
217 284
  my ($self) = @_;
218 285

  
......
314 381
    @{ $params{CUSTOM_VARIABLES_FIRST_TAB} }  = extract_by { $_->{first_tab} == 1 } @{ $params{CUSTOM_VARIABLES} };
315 382
  }
316 383

  
317
  my %title_hash = ( part       => t8('Edit Part'),
318
                     assembly   => t8('Edit Assembly'),
319
                     service    => t8('Edit Service'),
320
                     assortment => t8('Edit Assortment'),
384
  my %title_hash = ( part           => t8('Edit Part'),
385
                     assembly       => t8('Edit Assembly'),
386
                     service        => t8('Edit Service'),
387
                     assortment     => t8('Edit Assortment'),
388
                     parent_variant => t8('Edit Parent Variant'),
389
                     variant        => t8('Edit Variant'),
321 390
                   );
322 391

  
323 392
  $self->part->prices([])       unless $self->part->prices;
......
964 1033
  $self->_set_javascript;
965 1034
  $self->_setup_form_action_bar;
966 1035

  
967
  my %title_hash = ( part       => t8('Add Part'),
968
                     assembly   => t8('Add Assembly'),
969
                     service    => t8('Add Service'),
970
                     assortment => t8('Add Assortment'),
1036
  my %title_hash = ( part           => t8('Add Part'),
1037
                     assembly       => t8('Add Assembly'),
1038
                     service        => t8('Add Service'),
1039
                     assortment     => t8('Add Assortment'),
1040
                     parent_variant => t8('Add Parent Variant'),
1041
                     variant        => t8('Add Variant'),
971 1042
                   );
972 1043

  
973 1044
  $self->render(
......
979 1050

  
980 1051
sub _set_javascript {
981 1052
  my ($self) = @_;
982
  $::request->layout->use_javascript("${_}.js")  for qw(kivi.Part kivi.File kivi.PriceRule kivi.ShopPart kivi.Validator);
1053
  $::request->layout->use_javascript("${_}.js")  for qw(kivi.Part kivi.File kivi.PriceRule kivi.ShopPart kivi.Validator jquery.selectboxes jquery.multiselect2side);
983 1054
  $::request->layout->add_javascripts_inline("\$(function(){kivi.PriceRule.load_price_rules_for_part(@{[ $self->part->id ]})});") if $self->part->id;
984 1055
}
985 1056

  
......
1619 1690
}
1620 1691

  
1621 1692
sub check_has_valid_part_type {
1622
  die "invalid part_type" unless $_[0] =~ /^(part|service|assembly|assortment)$/;
1693
  die "invalid part_type" unless $_[0] =~ /^(part|service|assembly|assortment|parent_variant|variant)$/;
1623 1694
}
1624 1695

  
1625 1696

  

Auch abrufbar als: Unified diff