Revision 6571181b
Von Tamino Steinert vor 12 Monaten hinzugefügt
SL/Controller/Part.pm | ||
---|---|---|
use SL::DB::PriceRuleItem;
|
||
use SL::DB::PurchaseBasketItem;
|
||
use SL::DB::Shop;
|
||
use SL::DB::VariantProperty;
|
||
use SL::DB::VariantPropertyPart;
|
||
use SL::DB::VariantPropertyValuePart;
|
||
use SL::Helper::Flash;
|
||
use SL::Helper::PrintOptions;
|
||
use SL::JSON;
|
||
... | ... | |
}
|
||
}
|
||
|
||
sub action_update_variant_property_value_options {
|
||
my ($self) = @_;
|
||
|
||
my %select_tag_options = (
|
||
title_key => 'displayable_name',
|
||
value_key => 'id',
|
||
);
|
||
|
||
my @options;
|
||
my $variant_property_id = $::form->{add_variant_property};
|
||
if ($variant_property_id) {
|
||
my $variant_property = SL::DB::VariantProperty->new(id => $variant_property_id)->load;
|
||
@options = $variant_property->property_values;
|
||
}
|
||
|
||
unless (scalar @options) {
|
||
$select_tag_options{with_empty} = 1;
|
||
$select_tag_options{empty_title} = t8("Select Variant Property First");
|
||
}
|
||
|
||
foreach my $variant (@{$self->part->variants}) {
|
||
my $select_tag_name = "add_variant_property_value_" . $variant->id;
|
||
my $new_select_tag = select_tag(
|
||
$select_tag_name, \@options,
|
||
%select_tag_options
|
||
);
|
||
$self->js->replaceWith("#$select_tag_name", $new_select_tag);
|
||
}
|
||
|
||
$self->js->render();
|
||
}
|
||
|
||
sub action_add_variant_property {
|
||
my ($self) = @_;
|
||
|
||
my $variant_property_id = $::form->{add_variant_property};
|
||
die t8("Please select a variant property") unless ($variant_property_id);
|
||
foreach my $variant (@{$self->part->variants}) {
|
||
die t8("Please select a new variant property value for all variants")
|
||
unless $::form->{"add_variant_property_value_" . $variant->id};
|
||
}
|
||
|
||
SL::DB->client->with_transaction(sub {
|
||
SL::DB::VariantPropertyPart->new(
|
||
part_id => $self->part->id,
|
||
variant_property_id => $variant_property_id,
|
||
)->save;
|
||
foreach my $variant (@{$self->part->variants}) {
|
||
SL::DB::VariantPropertyValuePart->new(
|
||
part_id => $variant->id,
|
||
variant_property_value_id => $::form->{"add_variant_property_value_" . $variant->id},
|
||
)->save;
|
||
}
|
||
1;
|
||
}) or do {
|
||
return $self->js->error(t8('Error while adding variant property: ' . @_))->render();
|
||
};
|
||
|
||
$self->redirect_to(
|
||
controller => 'Part',
|
||
action => 'edit',
|
||
'part.id' => $self->part->id
|
||
);
|
||
}
|
||
|
||
sub action_create_variants {
|
||
my ($self) = @_;
|
||
my @variant_property_ids = sort keys %{$::form->{variant_properties}};
|
||
... | ... | |
return $self->js->error(
|
||
t8('No property value selected for variant properties: #1.',
|
||
join(", ",
|
||
map {$_->name_translated}
|
||
map {$_->displayable_name}
|
||
grep {!defined $::form->{variant_properties}->{$_->id}->{selected_property_values}}
|
||
@$variant_properties
|
||
)
|
||
... | ... | |
$self->_set_javascript;
|
||
$self->_setup_form_action_bar;
|
||
|
||
my (%assortment_vars, %assembly_vars);
|
||
%assortment_vars = %{ $self->prepare_assortment_render_vars } if $self->part->is_assortment;
|
||
%assembly_vars = %{ $self->prepare_assembly_render_vars } if $self->part->is_assembly;
|
||
my (%assortment_vars, %assembly_vars, %parent_variant_vars, %variant_vars);
|
||
%assortment_vars = %{ $self->prepare_assortment_render_vars } if $self->part->is_assortment;
|
||
%assembly_vars = %{ $self->prepare_assembly_render_vars } if $self->part->is_assembly;
|
||
%parent_variant_vars = %{ $self->prepare_parent_variant_render_vars } if $self->part->is_parent_variant;
|
||
|
||
$params{CUSTOM_VARIABLES} = $params{use_as_new} && $::form->{old_id}
|
||
? CVar->get_custom_variables(module => 'IC', trans_id => $::form->{old_id})
|
||
... | ... | |
title => $title_hash{$self->part->part_type},
|
||
%assortment_vars,
|
||
%assembly_vars,
|
||
%parent_variant_vars,
|
||
translations_map => { map { ($_->language_id => $_) } @{$self->part->translations} },
|
||
prices_map => { map { ($_->pricegroup_id => $_) } @{$self->part->prices } },
|
||
oldpartnumber => $::form->{oldpartnumber},
|
||
... | ... | |
return \%vars;
|
||
}
|
||
|
||
sub prepare_parent_variant_render_vars {
|
||
my ($self) = @_;
|
||
|
||
my %has_variant_property =
|
||
map { $_->id => 1}
|
||
@{$self->part->variant_properties};
|
||
my @available_variant_properis =
|
||
grep {!$has_variant_property{$_->id}}
|
||
@{SL::DB::Manager::VariantProperty->get_all()};
|
||
my %vars = (
|
||
AVAILABLE_VARIANT_PROPERIES => \@available_variant_properis,
|
||
);
|
||
|
||
return \%vars;
|
||
}
|
||
|
||
sub add {
|
||
my ($self) = @_;
|
||
|
SL/DB/Part.pm | ||
---|---|---|
$self->variant_property_values) . "]";
|
||
}
|
||
|
||
sub variant_value {
|
||
my ($self, $variant_property) = @_;
|
||
|
||
my %property_id_to_values =
|
||
map {$_->variant_property_id => $_}
|
||
@{$self->variant_property_values};
|
||
|
||
my $property_value = $property_id_to_values{$variant_property->id};
|
||
|
||
return $property_value && $property_value->displayable_name();
|
||
}
|
||
|
||
sub init_onhandqty {
|
||
my ($self) = @_;
|
||
my $qty = SL::Helper::Inventory::get_onhand(part => $self->id) || 0;
|
SL/DB/VariantProperty.pm | ||
---|---|---|
|
||
sub name_translated {goto &name} # TODO
|
||
|
||
sub displayable_name {
|
||
my ($self) = @_;
|
||
return $self->name . "(" . $self->abbreviation . ")";
|
||
}
|
||
|
||
1;
|
SL/DB/VariantPropertyValue.pm | ||
---|---|---|
|
||
sub value_translated {goto &value} # TODO
|
||
|
||
sub displayable_name {
|
||
my ($self) = @_;
|
||
return $self->value . "(" . $self->abbreviation . ")";
|
||
}
|
||
|
||
1;
|
js/kivi.Part.js | ||
---|---|---|
$.post("controller.pl", data, kivi.eval_json_result);
|
||
};
|
||
|
||
ns.update_variant_property_value_options = function() {
|
||
var data = $('#ic').serializeArray();
|
||
data.push({ name: 'action', value: 'Part/update_variant_property_value_options' });
|
||
$.post("controller.pl", data, kivi.eval_json_result);
|
||
};
|
||
|
||
ns.add_variant_property = function() {
|
||
var data = $('#ic').serializeArray();
|
||
data.push({ name: 'action', value: 'Part/add_variant_property' });
|
||
$.post("controller.pl", data, kivi.eval_json_result);
|
||
};
|
||
|
||
var KEY = {
|
||
TAB: 9,
|
||
ENTER: 13,
|
templates/design40_webpages/part/_parent_variant.html | ||
---|---|---|
[% USE P %]
|
||
|
||
<div class="wrapper">
|
||
<div class="wrapper input-panel">
|
||
<h3> [% LxERP.t8("Variant Properties") %] </h3>
|
||
<table class="tbl-list">
|
||
<caption>
|
||
[% LxERP.t8("Variants") %]
|
||
</caption>
|
||
<thead>
|
||
<th>[% "Partnumber" | $T8 %]</th>
|
||
<th>[% "Description" | $T8 %]</th>
|
||
<th>[% "Property Values (Abbreviation)" | $T8 %]</th>
|
||
[% FOREACH variant_property = SELF.part.variant_properties %]
|
||
<th> [% variant_property.displayable_name %] </th>
|
||
[% END %]
|
||
<th>
|
||
[% L.select_tag("add_variant_property", AVAILABLE_VARIANT_PROPERIES
|
||
title_key='displayable_name', value_key='id',
|
||
with_empty=1, empty_title=LxERP.t8("Variant Property"),
|
||
onchange='kivi.Part.update_variant_property_value_options();',
|
||
)%]
|
||
[% L.button_tag('kivi.Part.add_variant_property();', LxERP.t8("Insert new")) %]
|
||
</th>
|
||
</thead>
|
||
<tbody class="row_entry listrow">
|
||
[% FOREACH variant = SELF.part.variants %]
|
||
<tr>
|
||
<td>[% variant.presenter.part %]</td>
|
||
<td>[% variant.description | html %]</td>
|
||
<td>[% variant.variant_values | html %]</td>
|
||
[% FOREACH variant_property = SELF.part.variant_properties %]
|
||
<td> [% variant.variant_value(variant_property) %] </td>
|
||
[% END %]
|
||
<td>
|
||
[% L.select_tag("add_variant_property_value_" _ variant.id, []
|
||
title_key='displayable_name', value_key='id',
|
||
with_empty=1, empty_title=LxERP.t8("Select Variant Property First"),
|
||
) %]
|
||
</td>
|
||
</tr>
|
||
[% END %]
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
|
||
<div class="wrapper input-panel">
|
||
<h3> [% LxERP.t8("Create new Variants") %] </h3>
|
||
<div class="wrapper">
|
||
... | ... | |
<h4>[% variant_property.name_translated | html %]</h4>
|
||
[% L.select_tag("variant_properties." _ variant_property.id _ ".selected_property_values[]",
|
||
variant_property.property_values,
|
||
title_key='value_translated', value_key='id',
|
||
title_key='displayable_name', value_key='id',
|
||
id="selected_property_values_" _ variant_property.id,
|
||
multiple=1,
|
||
) %]
|
||
... | ... | |
</div>
|
||
[% L.button_tag('kivi.Part.create_variants();', LxERP.t8("Create Variants with selected Values")) %]
|
||
</div>
|
||
|
||
<table class="tbl-list">
|
||
<caption>
|
||
[% LxERP.t8("Variants") %]
|
||
</caption>
|
||
<thead>
|
||
<th>[% "Partnumber" | $T8 %]</th>
|
||
<th>[% "Description" | $T8 %]</th>
|
||
<th>[% "Property Values" | $T8 %]</th>
|
||
</thead>
|
||
<tbody class="row_entry listrow">
|
||
[% FOREACH variant = SELF.part.variants %]
|
||
<tr>
|
||
<td>[% variant.presenter.part %]</td>
|
||
<td>[% variant.description | html %]</td>
|
||
<td>[% variant.variant_values | html %]</td>
|
||
</tr>
|
||
[% END %]
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
|
||
|
Auch abrufbar als: Unified diff
Varianten: Varianten Eigenschaften zum Stammartikel hinzufügen