Revision 1861cb74
Von Tamino Steinert vor 6 Tagen hinzugefügt
SL/DB/Part.pm | ||
---|---|---|
4 | 4 |
|
5 | 5 |
use Carp; |
6 | 6 |
use List::MoreUtils qw(any uniq); |
7 |
use List::Util qw(sum); |
|
7 |
use List::Util qw(sum max);
|
|
8 | 8 |
use Rose::DB::Object::Helpers qw(as_tree); |
9 | 9 |
|
10 | 10 |
use SL::Locale::String qw(t8); |
... | ... | |
215 | 215 |
sub is_assembly { $_[0]->part_type eq 'assembly' } |
216 | 216 |
sub is_service { $_[0]->part_type eq 'service' } |
217 | 217 |
sub is_assortment { $_[0]->part_type eq 'assortment' } |
218 |
sub is_parent_variant { $_[0]->part_type eq 'parent_variant' } |
|
219 |
sub is_variant { $_[0]->part_type eq 'variant' } |
|
218 |
|
|
219 |
sub is_parent_variant { $_[0]->variant_type eq 'parent_variant' } |
|
220 |
sub is_variant { $_[0]->variant_type eq 'variant' } |
|
220 | 221 |
|
221 | 222 |
sub type { return $_[0]->part_type; } |
222 | 223 |
|
... | ... | |
242 | 243 |
|
243 | 244 |
sub new_parent_variant { |
244 | 245 |
my ($class, %params) = @_; |
245 |
$class->new(%params, part_type => 'parent_variant');
|
|
246 |
$class->new(%params, variant_type => 'parent_variant');
|
|
246 | 247 |
} |
247 | 248 |
|
248 | 249 |
sub last_modification { |
... | ... | |
513 | 514 |
die "Given variant_property_values dosn't match the variant_properties of parent_variant part"; |
514 | 515 |
} |
515 | 516 |
|
517 |
my $separator = '.'; # TODO: make configurable |
|
518 |
|
|
519 |
my $last_variant_number = |
|
520 |
max |
|
521 |
map { |
|
522 |
my $partnumber = $_->partnumber; |
|
523 |
$partnumber =~ s/.*\Q$separator\E([0-9]*)/$1/; # escape chars between \Q \E |
|
524 |
$partnumber; |
|
525 |
} |
|
526 |
$self->variants; |
|
527 |
|
|
516 | 528 |
my $new_variant = $self->clone_and_reset; |
517 |
# TODO set partnumber |
|
518 |
$new_variant->part_type('variant'); |
|
519 |
$new_variant->save; |
|
520 |
SL::DB::VariantPropertyValuePart->new( |
|
521 |
part_id => $new_variant->id, |
|
522 |
variant_property_value_id => $_->id, |
|
523 |
)->save for @$variant_property_values; |
|
524 |
SL::DB::PartParentVariantPartVariant->new( |
|
525 |
variant_id => $new_variant->id, |
|
526 |
parent_variant_id => $self->id, |
|
527 |
)->save; |
|
529 |
$new_variant->partnumber($self->partnumber . $separator . ($last_variant_number + 1)); |
|
530 |
$new_variant->variant_type('variant'); |
|
531 |
$new_variant->add_assemblies(map {$_->clone_and_reset} $self->assemblies) if ($self->is_assembly); |
|
532 |
$new_variant->add_variant_property_values(@$variant_property_values); |
|
528 | 533 |
|
534 |
$self->add_variants($new_variant); |
|
535 |
$self->save; |
|
529 | 536 |
return $new_variant; |
530 | 537 |
} |
531 | 538 |
|
... | ... | |
645 | 652 |
|
646 | 653 |
sub variant_value { |
647 | 654 |
my ($self, $variant_property) = @_; |
655 |
die "only callable on parts of type parent_variant" unless $self->is_variant; |
|
656 |
die "only callable with SL::DB::VariantProperty object" unless ref $variant_property eq 'SL::DB::VariantProperty'; |
|
648 | 657 |
|
649 | 658 |
my %property_id_to_values = |
650 | 659 |
map {$_->variant_property_id => $_} |
Auch abrufbar als: Unified diff
Varianten: alle Artikeltypen ermöglichen