Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 4d65e27a

Von Tamino Steinert vor 5 Tagen hinzugefügt

  • ID 4d65e27afd846d5daf600bae8d1beef26c7e3a65
  • Vorgänger 2d908c13
  • Nachfolger 1861cb74

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::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

  
SL/DB/Part.pm
643 643
    $self->variant_property_values)  . "]";
644 644
}
645 645

  
646
sub variant_value {
647
  my ($self, $variant_property) = @_;
648

  
649
  my %property_id_to_values =
650
    map {$_->variant_property_id => $_}
651
    @{$self->variant_property_values};
652

  
653
  my $property_value = $property_id_to_values{$variant_property->id};
654

  
655
  return $property_value && $property_value->displayable_name();
656
}
657

  
646 658
sub init_onhandqty {
647 659
  my ($self) = @_;
648 660
  my $qty = SL::Helper::Inventory::get_onhand(part => $self->id) || 0;
SL/DB/VariantProperty.pm
39 39

  
40 40
sub name_translated {goto &name} # TODO
41 41

  
42
sub displayable_name {
43
  my ($self) = @_;
44
  return $self->name . "(" . $self->abbreviation . ")";
45
}
46

  
42 47
1;
SL/DB/VariantPropertyValue.pm
21 21

  
22 22
sub value_translated {goto &value} # TODO
23 23

  
24
sub displayable_name {
25
  my ($self) = @_;
26
  return $self->value . "(" . $self->abbreviation . ")";
27
}
28

  
24 29
1;
js/kivi.Part.js
337 337
    $.post("controller.pl", data, kivi.eval_json_result);
338 338
  };
339 339

  
340
  ns.update_variant_property_value_options = function() {
341
    var data = $('#ic').serializeArray();
342
    data.push({ name: 'action', value: 'Part/update_variant_property_value_options' });
343
    $.post("controller.pl", data, kivi.eval_json_result);
344
  };
345

  
346
  ns.add_variant_property = function() {
347
    var data = $('#ic').serializeArray();
348
    data.push({ name: 'action', value: 'Part/add_variant_property' });
349
    $.post("controller.pl", data, kivi.eval_json_result);
350
  };
351

  
340 352
  var KEY = {
341 353
    TAB:       9,
342 354
    ENTER:     13,
templates/design40_webpages/part/_parent_variant.html
5 5
[% USE P %]
6 6

  
7 7
<div class="wrapper">
8
  <div class="wrapper input-panel">
9
    <h3> [% LxERP.t8("Variant Properties") %] </h3>
10
    <table class="tbl-list">
11
      <caption>
12
        [% LxERP.t8("Variants") %]
13
      </caption>
14
      <thead>
15
        <th>[% "Partnumber" | $T8 %]</th>
16
        <th>[% "Description" | $T8 %]</th>
17
        <th>[% "Property Values (Abbreviation)" | $T8 %]</th>
18
        [% FOREACH variant_property = SELF.part.variant_properties %]
19
        <th> [% variant_property.displayable_name %] </th>
20
        [% END %]
21
        <th>
22
          [% L.select_tag("add_variant_property", AVAILABLE_VARIANT_PROPERIES
23
            title_key='displayable_name', value_key='id',
24
            with_empty=1, empty_title=LxERP.t8("Variant Property"),
25
            onchange='kivi.Part.update_variant_property_value_options();',
26
          )%]
27
          [% L.button_tag('kivi.Part.add_variant_property();', LxERP.t8("Insert new")) %]
28
        </th>
29
      </thead>
30
      <tbody class="row_entry listrow">
31
        [% FOREACH variant = SELF.part.variants %]
32
          <tr>
33
            <td>[% variant.presenter.part %]</td>
34
            <td>[% variant.description | html %]</td>
35
            <td>[% variant.variant_values | html %]</td>
36
            [% FOREACH variant_property = SELF.part.variant_properties %]
37
            <td> [% variant.variant_value(variant_property) %] </td>
38
            [% END %]
39
            <td>
40
              [% L.select_tag("add_variant_property_value_" _ variant.id, []
41
                title_key='displayable_name', value_key='id',
42
                with_empty=1, empty_title=LxERP.t8("Select Variant Property First"),
43
              ) %]
44
            </td>
45
          </tr>
46
        [% END %]
47
      </tbody>
48
    </table>
49
  </div>
50

  
8 51
  <div class="wrapper input-panel">
9 52
    <h3> [% LxERP.t8("Create new Variants") %] </h3>
10 53
    <div class="wrapper">
......
13 56
        <h4>[% variant_property.name_translated | html %]</h4>
14 57
        [% L.select_tag("variant_properties." _ variant_property.id _ ".selected_property_values[]",
15 58
          variant_property.property_values,
16
          title_key='value_translated', value_key='id',
59
          title_key='displayable_name', value_key='id',
17 60
          id="selected_property_values_" _ variant_property.id,
18 61
          multiple=1,
19 62
        ) %]
......
27 70
    </div>
28 71
    [% L.button_tag('kivi.Part.create_variants();', LxERP.t8("Create Variants with selected Values")) %]
29 72
  </div>
30

  
31
  <table class="tbl-list">
32
    <caption>
33
      [% LxERP.t8("Variants") %]
34
    </caption>
35
    <thead>
36
      <th>[% "Partnumber" | $T8 %]</th>
37
      <th>[% "Description" | $T8 %]</th>
38
      <th>[% "Property Values" | $T8 %]</th>
39
    </thead>
40
    <tbody class="row_entry listrow">
41
      [% FOREACH variant = SELF.part.variants %]
42
        <tr>
43
          <td>[% variant.presenter.part %]</td>
44
          <td>[% variant.description | html %]</td>
45
          <td>[% variant.variant_values | html %]</td>
46
        </tr>
47
      [% END %]
48
    </tbody>
49
  </table>
50 73
</div>
51 74

  
52 75

  

Auch abrufbar als: Unified diff