Interchange Developer Resource


[Date Prev][Date Next][Thread Prev][Thread Next][Interchange by date ][Interchange by thread ]

Re: [ic] Nested Loops - Newbie



> Hi I am trying to get it so that a menu link for a category only links to
> products in that category and in the area it is displayed under.

Mike posted the attached file that not only makes this process work but it
allows for creating custom cat link searches effortlessly. I have heavily
tested this in 4.8.2 and it works beautifully.

Just dump it into catalog/pages/admin directory of any catalog to try it
out.

Delete it if you want to revert to the default layout_auto.html page. (I
don't think so)

Click on 'Design' and 'auto populate' to use it.





[set page_title]Layout auto-populate[/set] [set ui_class]Design[/set] [set page_banner]Layout Editor: Organize your site into categories[/set] [set page_perm]layout=e[/set] [set help_name]layout.edit[/set] [set icon_name]icon_pages.gif[/set] [tmp meta_header] [include include/table_populator] [/tmp] [seti ui_body_extra][/seti] @_UI_STD_HEAD_@
1. Choose a table as the source: [if !value area_table] [value name=area_table set=products hide=1] [value name=area_column set=prod_group hide=1] [value name=cat_column set=category hide=1] [/if] [loop list="[list-databases]" option=area_table] [loop-code] [/loop]
2. Choose a column to populate areas: -- none -- [loop list="[db-columns table='[value area_table]']" option=area_column] [loop-code] [/loop]
3. Choose a column to populate categories: -- none -- [loop list="[db-columns table='[value area_table]']" option=cat_column] [loop-code] [/loop]
4. Choose a search type: Narrow search (area and category match) Simple search (only category matches) Complex search (template substitution on below)
5. Complex search code: NOTE: Not active unless complex search selected above.
fi=products st=db co=yes sf=prod_group se=~PROD_GROUP~ op=eq sf=category se=~CATEGORY~ op=eq sf=inactive se=1 op=ne rf=sku va=banner_text=~BANNER_TEXT~
6. Select the page class:
7. Select the page area:
8. Decide whether to remove previous settings: No Yes
9. Click this button to populate: [button text="Populate"] [flag type=write table="area"] [flag type=write table="cat"] [seti ui_failure] [perl tables="area cat [cgi area_table]"] my $go_page = $CGI->{mv_nextpage}; $CGI->{mv_nextpage} = '@@MV_PAGE@@'; my $ptab = $CGI->{area_table} or return "no area source table"; my $pdb = $Db{$ptab} or return "area source table bad"; my $adb = $Db{area} or return "no area table"; my $cdb = $Db{cat} or return "no cat table"; my $acol = $CGI->{area_column}; my $ccol = $CGI->{cat_column}; if(! $acol and ! $ccol ) { return "no column to populate either"; } my $selector = ''; my $selcode = ''; my %area_defaults = ( name => undef, which_page => $CGI->{which_page} || 'all', sort => '05', sel => $CGI->{sel} || 'left', display_type => 'name', ); my %catmap; my $narrow; my $lt; my $search_code; if($CGI->{cat_type} eq 'simple') { $lt = 'simple'; $selector = 'category=~CATEGORY~'; $search_code = ''; } elsif($CGI->{cat_type} eq 'narrow') { $narrow = 1; $lt = 'simple'; $selector = <{search_code}; } my %cat_defaults = ( link_type => $lt, selector => $selector, search => $search_code, sort => '05', display_type => 'name' ); if($CGI->{nuke}) { $adb->query('delete from area'); $cdb->query('delete from cat'); } if($acol) { $adb->config('AUTO_NUMBER', '1000') if ! $adb->config('_Auto_number'); return "area column $acol doesn't exist" unless $pdb->column_exists($acol); my $ary = $pdb->query("select distinct $acol from $ptab order by $acol") or return "area column query failed"; for(@$ary) { my ($area) = (@$_); my $key = $adb->set_row(''); return "no autonumbering available" if ! $key; $catmap{$area} = $key; for(keys %area_defaults) { $adb->set_field($key, $_, $area_defaults{$_} || $area); } } } my %catdone; if($ccol) { $cdb->config('AUTO_NUMBER', '1000') if ! $cdb->config('_Auto_number'); return "cat column $ccol doesn't exist" unless $pdb->column_exists($ccol); my ($ary, $fh) = $pdb->query( "select $acol, $ccol from $ptab order by $ccol", ) or return "cat column query failed"; foreach my $row (@$ary) { my $area = $row->[$fh->{$acol}]; my $cat = $row->[$fh->{$ccol}]; my $donetag = $narrow ? "$area:$cat" : $cat; next if $catdone{$donetag}++; my $key = $cdb->set_row(''); return "no cat autonumbering available" if ! $key; my %defaults = %cat_defaults; $defaults{name} = $cat; $defaults{sel} = $catmap{$area}; $defaults{search} =~ s/~ (\w+) ~/$row->[$fh->{lc $1}]/gx; $defaults{selector} =~ s/~ (\w+) ~/$row->[$fh->{lc $1}]/gx; for(keys %defaults) { Log("setting col=$_ key=$key = $defaults{$_}"); $cdb->set_field($key, $_, $defaults{$_}); } } } $CGI->{mv_nextpage} = $go_page; my $out = $Tag->uneval( { ref => \%catmap } ); $out =~ s/,/,\n/g; #return '' . $Tag->uneval( { ref => \%catmap } ) . "</XMP"; return; [/perl] [/seti] [/button] <BR> </td> </tr> <tr> <td colspan=2 bgcolor=__UI_C_TOPBLOCKBAR__><img src="" width=__UI_MAIN_WIDTH__ height=1></td> </tr> </table> <!------- END REAL STUFF ----- --> @_UI_STD_FOOTER_@ <!----> <!--X-Body-of-Message-End--> <!--X-MsgBody-End--> <!--X-Follow-Ups--> <hr> <!--X-Follow-Ups-End--> <!--X-References--> <ul><li><strong>References</strong>: <ul> <li><strong><a name="10825" href="msg10825.html">[ic] Nested Loops - Newbie</a></strong> <ul><li><em>From:</em> &quot;Jeff Fearn&quot; &lt;jeffrey_fearn@hotmail.com&gt;</li></ul></li> </ul></li></ul> <!--X-References-End--> <!--X-BotPNI--> <ul> <li>Prev by Date: <strong><a href="msg10827.html">[ic] Tax caluculation problem</a></strong> </li> <li>Next by Date: <strong><a href="msg10830.html">RE: [ic] mail archive search broken?</a></strong> </li> <li>Prev by thread: <strong><a href="msg10825.html">[ic] Nested Loops - Newbie</a></strong> </li> <li>Next by thread: <strong><a href="msg10850.html">Re: [ic] Nested Loops - Newbie</a></strong> </li> <li>Index(es): <ul> <li><a href="index.html#10829"><strong>Date</strong></a></li> <li><a href="thrd217.html#10829"><strong>Thread</strong></a></li> </ul> </li> </ul> <!--X-BotPNI-End--> <!--X-User-Footer--> <form method="post" action="/cgi-bin/htsearch"> <font size=-1> Search for: <input type="text" size="20" name="words" value=""> Match: <select name=method> <option value=and>All <option value=or>Any </select> Format: <select name=format> <option value=builtin-long>Long <option value=builtin-short>Short </select> Sort by: <select name=sort> <option value=score>Score <option value=time>Time <option value=title>Title <option value=revscore>Reverse Score <option value=revtime>Reverse Time <option value=revtitle>Reverse Title </select> <input type="submit" value="Search"> </font> <input type=hidden name=config value=htdig> <input type=hidden name=restrict value=""> <input type=hidden name=exclude value=""> </form> <!--X-User-Footer-End--> </body> </html>