Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 66c06a13

Von Tamino Steinert vor 10 Monaten hinzugefügt

  • ID 66c06a13bf892e3346eec50f7f4ea278f8de0318
  • Vorgänger f36c200a
  • Nachfolger b16967fa

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;
......
503 498
  return \@sorted;
504 499
}
505 500

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

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

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

  
525
  return $new_variant;
526
}
527

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

  

Auch abrufbar als: Unified diff