Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision eb82b54d

Von Tamino Steinert vor 11 Monaten hinzugefügt

  • ID eb82b54d003a4602c27b78521314d00511f62af5
  • Vorgänger c25824ca
  • Nachfolger 3735d44d

Varianten: Partpicker nach Varianten filtern.

Unterschiede anzeigen:

SL/DB/Manager/Part.pm
20 20
    my ($key, $value, $prefix) = @_;
21 21
    return __PACKAGE__->type_filter($value, $prefix);
22 22
  },
23
  all => sub {
24
    my ($key, $value, $prefix) = @_;
25
    return or => [ map { $prefix . $_ => $value } qw(partnumber description ean) ]
26
  },
23
  # all => sub {
24
  #   my ($key, $value, $prefix) = @_;
25
  #   return or => [ map { $prefix . $_ => $value } qw(partnumber description ean) ]
26
  # },
27 27
  all_with_makemodel => sub {
28 28
    my ($key, $value, $prefix) = @_;
29 29
    return or => [ map { $prefix . $_ => $value } qw(partnumber description ean makemodels.model) ],
......
34 34
    return or => [ map { $prefix . $_ => $value } qw(partnumber description ean customerprices.customer_partnumber) ],
35 35
      $prefix . 'customerprices';
36 36
  },
37
  # all_with_variants => sub {
38
  all => sub {
39
    my ($key, $value, $prefix) = @_;
40
    if ($value =~ m/\[/ || $value->{ilike} =~ m/\[/) { #variant_filter
41
      my $ilike = 0;
42
      if ($value->{ilike}) {
43
        $ilike = 1;
44
        $value = $value->{ilike};
45
        $value =~ s/^%//;
46
        $value =~ s/%$//;
47
      }
48
      #clean
49
      $value =~ s/^\s+//;
50
      $value =~ s/\s+$//;
51
      $value =~ s/^.*\[//;
52
      $value =~ s/].*$//;
53
      # search for part_id with all variant_property_values
54
      my @wheres;
55
      my @values;
56
      foreach my $variant_search (split(/\|/, $value)) {
57
        next unless $variant_search;
58
        my $comp = '=';
59
        my $or_and = 'and';
60
        my ($variant_name, $variant_value) = split(/:/, $variant_search);
61
        unless ($variant_name && $variant_value) {
62
          $variant_search =~ s/://;
63
          $variant_name = $variant_value = $variant_search;
64
          $or_and = 'or';
65
        }
66
        if ($ilike) {
67
          $comp = 'ilike';
68
          $variant_name  = "%$variant_name%";
69
          $variant_value = "%$variant_value%";
70
        }
71
        push @wheres, "(prop.abbreviation $comp ? $or_and val.abbreviation $comp ?)";
72
        push @values, $variant_name, $variant_value;
73
      }
74
      return unless @wheres;
75
      my $where = join(' or ', @wheres) || '1=1';
76
      push @values, scalar @wheres; # count_hits
77
      my $query = <<SQL;
78
        SELECT part_id from (
79
          SELECT
80
            t3.part_id, COUNT(*) as count_hits
81
          FROM
82
            variant_property_values val
83
            JOIN variant_properties prop ON (val.variant_property_id = prop.id)
84
            JOIN variant_property_values_parts t3 ON (t3.variant_property_value_id = val.id)
85
          WHERE
86
           $where
87
          GROUP BY t3.part_id
88
        ) as tmp
89
        WHERE count_hits >= ?;
90
SQL
91
      my @part_ids =
92
        map {$_->{part_id}}
93
        selectall_hashref_query($::form, $::form->get_standard_dbh, $query, @values);
94

  
95
      return id => scalar @part_ids ? \@part_ids : (-1); # empty list not allowed
96
    }
97
    return or => [ map { $prefix . $_ => $value } qw(partnumber description ean) ]
98
  }
37 99
);
38 100

  
39 101
sub type_filter {
SL/DB/Part.pm
637 637
sub variant_values {
638 638
  my ($self) = @_;
639 639
  return unless $self->is_variant;
640
  return join(" ",
641
    map {"[" . $_->variant_property->abbreviation . ":" . $_->abbreviation . "]"}
642
    $self->variant_property_values);
640
  return "[" .join("|",
641
    map {$_->variant_property->abbreviation . ":" . $_->abbreviation}
642
    $self->variant_property_values)  . "]";
643 643
}
644 644

  
645 645
sub init_onhandqty {

Auch abrufbar als: Unified diff