[Date Prev][Date Next][Thread Prev][Thread Next][Interchange by date
][Interchange by thread
]
[ic] [TREE] tag and tree_build.html
** PRIVATE **
Hi all,
Just a quick question about the tree_build.html code example. Here it is for reference.
[perl tables="products tree"]
my $db = $Db{products};
my $ary = $db->query('select sku,comb_category from products');
my $out = '';
my $code = '00000';
my $cc = '0000';
my %done;
my @levels;
foreach $row ( @$ary) {
my ($sku, $cat) = @$row;
next if $done{$cat};
my $parent = 'TOP';
my @parts = split /:/, $cat;
my $combname = '';
for( my $i = 0; $i < @parts; $i++) {
my $name = $parts[$i];
my $comb = join ":", @parts[0 .. $i];
my $level = $levels[$i] ||= {};
if(! $level->{$name}) {
$level->{$name} = [ ++$code, $parent, ++$cc, $name, $comb ];
$parent = $cc;
}
else {
$parent = $level->{$name}->[2];
}
}
}
my $tdb = $Db{tree};
$tdb->query('delete from tree');
my @flds = qw/parent_fld child_fld name category/;
my $count++;
for(@levels) {
my $hash = $_;
for(sort keys %$hash) {
my $rec = $hash->{$_};
my $code = shift @$rec;
$tdb->set_slice($code, \@flds, $rec);
$count++;
}
}
return $count;
[/perl]
The problem I am having is that when there are two or more sub-levels that have the same name, the build process doesn't account for the items. This would be an example
Brand#1
Sweaters
Pants
Suits
Brand#2
Sweaters
Suits
Shoes
In this example, the tree_build.html is not properly accounting for the "Sweater" category.
Has anyone already encountered this and come up with a work around? Any help would be greatly appreciated.
Thanks,
Gary