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

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

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

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

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

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

  
645 657
sub init_onhandqty {
646 658
  my ($self) = @_;
647 659
  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