[ic] Single SKU in Multiple Categories

Bob Ramstad interchange-users@interchange.redhat.com
Thu Dec 20 16:27:00 2001


   "Fred Pope" wrote:

   I am looking at alternatives of having a single SKU show up in multiple
   categories. Looking through the archives, the best way to do this easily
   is either to do a join in a separate table in the database, or to add a
   second column in the products database table if the there are not going
   to be an excessive amount, but this is clearly poor database design.
   Someone had suggested seperating the category list by commas in the
   products table, but this does not work to produce the desired result.
   What you end up with is a new category with a name of the two categories
   seperated by a comma on the results.html page. 

I'm doing this -- it isn't in a production environment yet, but I'm
pretty happy with how it's working out.

In my particular case, I have items which need to appear on the page
of other items.  This is similar to the approach you mentioned above
i.e. item = category and subitem = item.

in dbconf/mysql/products.mysql I added

Database  products  COLUMN_DEF   "contents=VARCHAR(255)"

and made appropriate adjustments in the UI so I could view and edit
this field.

I then placed SKUs in the field separated by spaces.  (There's
probably a slick way to put a select box in the UI, but I want to
control the ordering of the items on the page, and so a simple text
list struck me as being the most simple.)

Finally, I edited flypage.html so that when any page has contents, the
contents are displayed.  I used a two column format and placed this
code just before [/fly-list]:

[if-item-field contents]
<table BORDER="0" CELLSPACING="0" CELLPADDING="0" WIDTH="100%">
[loop list="[item-field contents]"]
[loop-alternate 2][else]<tr VALIGN="top">[/else][/loop-alternate]
[if explicit][condition]return [item-field type] eq 'PAGE';[/condition]
<td>&nbsp;&nbsp;[page [loop-code]]<IMG SRC="thumb/[loop-field thumb]" ALT="[item-filter entities][loop-description][/item-filter]" BORDER="0"></A></td><td>&nbsp;</td><td><b>[page [loop-code]][loop-description]</A></b>[if-loop-field abstract]<BR>[loop-field abstract][/if-loop-field][if explicit][condition]return [loop-field orderable] eq 'YES';[/condition]<BR><B>[loop-price]</B>[else][tmp min]999999[/tmp][tmp max]0[/tmp][loop list="[loop-field contents]" prefix="elt"][if scratch min > [elt-price]][tmp min][elt-price][/tmp][/if][if scratch max < [elt-price]][tmp max][elt-price][/tmp][/if][/loop][if scratch min == [scratch max]]<BR><b>[scratch min]</b>[else]<BR><b>[scratch min]&nbsp;--&nbsp;[scratch max]</b>[/else][/if][/else][/if]</td>
[else]
<td>&nbsp;&nbsp;<IMG SRC="thumb/[loop-field thumb]" ALT="[item-filter entities][loop-description][/item-filter]"></td><td>&nbsp;</td><td><FORM ACTION="[area order]" METHOD="POST"><B>[loop-description]</B>[if-loop-field abstract]<BR>[loop-field abstract][/if-loop-field]<BR>[loop-code]&nbsp;&nbsp;<B>[loop-price]</B><BR><INPUT TYPE="hidden" NAME="mv_order_item" VALUE="[loop-code]"><INPUT TYPE="hidden" NAME="mv_session_id" value="[data session id]">Quantity:&nbsp;<INPUT TYPE="text" NAME="mv_order_quantity" VALUE="1" SIZE="2" MAXLENGTH="2">&nbsp;&nbsp;<INPUT TYPE="SUBMIT" VALUE="Add to Cart"></FORM></td>
[/else]
[/if]
[/loop]
</table>
[/if-item-field]

There's a lot of junk in here that I've added for some other fields I
created, but it gives you an idea of how you might want to format
items on the page.  The key is the [loop ....]  construct which has no
problems looping over the contents field.

Now, why did I do it this way?  That's complicated, but I think
personally that it's easier to think of categories as pages which
happen to have other items on them -- and then modify flypage to
handle the display of the other items.  I find it confusing to go the
other way i.e. this particular item belongs to these X categories.  I
want control over the order that the items appear on the category
pages, and I don't want to have to skip around to each item to be able
to change the way the category appears.  Also, I want each category to
be able to have a graphic at the top and have a caption... so the
"default" foundation approach of using searches on the left edge for
each category name doesn't work for me either.

For those who are curious, I'm partially inspired by / conforming to
Yahoo! Store database layout -- my current store Condom Country
www.condom.com is hosted by Yahoo! and I'm in the process of migrating
it to Interchange.

-- Bob