[set page_title]Rebuild "Others who bought this" links[/set] [set ui_class]Merchandising[/set] [set page_perm]regen[/set] [set help_name]merch.build_related[/set] [set icon_name]admin/icon_config.gif[/set] @_UI_STD_HEAD_@
[calc] %sku = ( [loop search=" ra=yes fi=merchandising ml=100000 rf=sku,others_bought "][loop-calc] my $ref = q[[loop-data merchandising others_bought]]; return '' if $out !~ m/^\s*{/; return < $ref, EOF [/loop-calc] [/loop] ) [/calc] [perl tables="__UI_META_TABLE__ orderline merchandising"] my $db = $Db{orderline}; return "NO ORDERLINE table???!" if ! $db; my $start = tag_data( qw/__UI_META_TABLE__ lookup_exclude orderline/ ); my $query = "select code,order_number,sku from orderline "; $query .= " where order_number > '$start'" if $start; $query .= " order by code"; my $ary = $db->query( { sql => $query } ); for(@$ary) { my ($line, $on, $sku) = @$_; push @{$on{$on} ||= []}, $sku; } for(keys %on) { my $ref = $on{$_}; @ary = @$ref; for(@ary) { my $sku = $_; $sku{$sku} = {} unless $sku{$sku}; for (@ary) { next if $_ eq $sku; $sku{$sku}->{$_}++; } } } my $mdb = $Db{merchandising}; for(sort keys %sku) { my $val = $Tag->uneval( { ref => $sku{$_} } ); $out .= "$_ ==> $val
\n"; $mdb->set_field($_, 'others_bought', $val ); } return $out; [/perl]
@_UI_STD_FOOTER_@