Revision bc8ddcc1
Von Tamino Steinert vor 12 Monaten 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 { |
... | ... | |
512 | 513 |
die "Given variant_property_values dosn't match the variant_properties of parent_variant part"; |
513 | 514 |
} |
514 | 515 |
|
516 |
my $separator = '.'; # TODO: make configurable |
|
517 |
|
|
518 |
my $last_variant_number = |
|
519 |
max |
|
520 |
map { |
|
521 |
my $partnumber = $_->partnumber; |
|
522 |
$partnumber =~ s/.*\Q$separator\E([0-9]*)/$1/; # escape chars between \Q \E |
|
523 |
$partnumber; |
|
524 |
} |
|
525 |
$self->variants; |
|
526 |
|
|
515 | 527 |
my $new_variant = $self->clone_and_reset; |
516 |
# TODO set partnumber |
|
517 |
$new_variant->part_type('variant'); |
|
518 |
$new_variant->save; |
|
519 |
SL::DB::VariantPropertyValuePart->new( |
|
520 |
part_id => $new_variant->id, |
|
521 |
variant_property_value_id => $_->id, |
|
522 |
)->save for @$variant_property_values; |
|
523 |
SL::DB::PartParentVariantPartVariant->new( |
|
524 |
variant_id => $new_variant->id, |
|
525 |
parent_variant_id => $self->id, |
|
526 |
)->save; |
|
528 |
$new_variant->partnumber($self->partnumber . $separator . ($last_variant_number + 1)); |
|
529 |
$new_variant->variant_type('variant'); |
|
530 |
$new_variant->add_assemblies(map {$_->clone_and_reset} $self->assemblies) if ($self->is_assembly); |
|
531 |
$new_variant->add_variant_property_values(@$variant_property_values); |
|
527 | 532 |
|
533 |
$self->add_variants($new_variant); |
|
534 |
$self->save; |
|
528 | 535 |
return $new_variant; |
529 | 536 |
} |
530 | 537 |
|
... | ... | |
644 | 651 |
|
645 | 652 |
sub variant_value { |
646 | 653 |
my ($self, $variant_property) = @_; |
654 |
die "only callable on parts of type parent_variant" unless $self->is_variant; |
|
655 |
die "only callable with SL::DB::VariantProperty object" unless ref $variant_property eq 'SL::DB::VariantProperty'; |
|
647 | 656 |
|
648 | 657 |
my %property_id_to_values = |
649 | 658 |
map {$_->variant_property_id => $_} |
Auch abrufbar als: Unified diff
Varianten: alle Artikeltypen ermöglichen