Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision a279fb60

Von Tamino Steinert vor 2 Monaten hinzugefügt

  • ID a279fb605ba2ca165beedaaf906ad811dd070ddb
  • Vorgänger 89821947
  • Nachfolger e2cc408f

Varianten: Stammartikel anlegen und Varianten erstellen

Unterschiede anzeigen:

SL/DB/Part.pm
242 242
  $class->new(%params, part_type => 'parent_variant');
243 243
}
244 244

  
245
sub new_variant {
246
  my ($class, %params) = @_;
247
  $class->new(%params, part_type => 'variant');
248
}
249

  
250 245
sub last_modification {
251 246
  my ($self) = @_;
252 247
  return $self->mtime // $self->itime;
......
504 499
  return \@sorted;
505 500
}
506 501

  
502
sub create_new_variant {
503
  my ($self, $variant_property_values) = @_;
504
  die "only callable on parts of type parent_variant" unless $self->is_parent_variant;
505
  die "only callable on saved objects"                unless $self->id;
506

  
507
  my @selected_variant_property_ids = sort map {$_->variant_property_id} @$variant_property_values;
508
  my @variant_property_ids = sort map {$_->id} @{$self->variant_properties};
509
  if (@variant_property_ids != @selected_variant_property_ids) {
510
    die "Given variant_property_values dosn't match the variant_properties of parent_variant part";
511
  }
512

  
513
  my $new_variant = $self->clone_and_reset;
514
  # TODO set partnumber
515
  $new_variant->part_type('variant');
516
  $new_variant->save;
517
  SL::DB::VariantPropertyValuePart->new(
518
    part_id                   => $new_variant->id,
519
    variant_property_value_id => $_->id,
520
  )->save for @$variant_property_values;
521
  SL::DB::PartParentVariantPartVariant->new(
522
    variant_id        => $new_variant->id,
523
    parent_variant_id => $self->id,
524
  )->save;
525

  
526
  return $new_variant;
527
}
528

  
507 529
sub clone_and_reset_deep {
508 530
  my ($self) = @_;
509 531

  

Auch abrufbar als: Unified diff