View Single Post
  #9  
Old 08-24-2005, 02:06 PM
 
gfiebich gfiebich is offline
 

Senior Member
  
Join Date: Feb 2003
Location: St. Paul, MN
Posts: 108
 

Default

Here is the latest version of my spin on Shane's variant table.

My goal with this was to display SKU, Variant Name(s), Inventory, and Price information in a table on the product.tpl page. For interface consistancy, I want this table to also appear for products that have no variants. Because modifiers do not have unique SKUs or Inventory, they do not appear in the table. The table can handle multiple variants per product by creating a column for each.

Display of inventory levels is independent of Admin inventory preference settings. I want my customers to be allowed to backorder products, so I "Disable inventory tracking" in the admin. Fortunately, this doesn't actuallly turn off X-cart's backend inventory functionality - products and variants still display the inventory fields in the admin and purchases still impact these inventory levels.

Bonus feature: because our sites typically have a mix of both warehoused products and "Just In Time" products (items ordered from our vendors per customer order), we need a way to display this gracefully to the customer. Here's what I did: 1) create an Extra Field (lefthand menu in the admin) called "Inventory Type". 2) in any product that is not warehoused, enter "JIT" in the "Inventory Type" field. My variants table will then display "Unlimited" in the inventory column instead of "0".

Okay, here's the code:
(place this anywhere on the product.tpl page where you would like the table to appear)
Code:
{* Determine if product exists in warehouse - JIT stands for'Just In Time' (ie. not inventoried). This is handled with an Extra Product Field. *} {section name=field loop=$extra_fields} {if $extra_fields[field].field_value eq "JIT"}{assign var="JIT" value="yes"}{/if} {/section} {* Determine if product has variants *} {if $variants} <table cellspacing="1" cellpadding="0" border="0" class="chart" width="100%"> {* Build table header *} <tr class="chart_head"> <td>SKU</td> {* Loop to handle multiple variant names *} {foreach from=$product_options item=v} {if $v.is_modifier eq ''}<TD>{if $usertype eq "A"}{$v.class}{else}{$v.classtext|default:$v.class}{/if}</TD>{/if} {/foreach} <td>Qty.</td> <td>Price</td> </tr> {* Build table rows *} {section name=test loop=$variants} <tr class="{cycle values="chart_dark,chart_light"}"> <td>{$variants[test].productcode}</td> {* Loop to handle multiple variants *} {foreach name=foo item=item key=key from=$variants[test].options} <td>{$item.option_name}</td> {/foreach} <td>{if $JIT eq "yes"}Unlimited{else}{if $variants[test].avail < 1}0{else}{$variants[test].avail}{/if}{/if}</td> <td>${$variants[test].price}</td> </tr> {/section} </table> {else} {* This product has no variants but we still want a table to display with basic SKU, Qty, and Price info *} <table cellspacing="1" cellpadding="0" border="0" class="chart" width="100%"> <tr class="chart_head"> <td>SKU</td> <td>Qty.</td> <td>Price</td> </tr> <tr class="{cycle values="chart_dark,chart_light"}"> <td>{$product.productcode}</td> {if $JIT eq "yes"}<td>Unlimited</td>{else} <td>{if $product.avail < 1}0{else}{$product.avail}{/if}</td>{/if} <td>${$product.price}</td> </tr> </table> {/if}

The table makes use of a few custom CSS styles. Add these to your skin1.css file.
Code:
table.chart { background-color: #ffffff; color: black; text-align:center} table.chart tr.chart_head td {background-color: #556591; padding: 2px 2px 2px 2px; color:#ffffff; font-size:10px} table.chart tr.chart_light td {background-color: #cccccc; padding: 2px 2px 2px 2px; font-size:10px} table.chart tr.chart_dark td {background-color: #eeeeee; padding: 2px 2px 2px 2px; font-size:10px} table.productoptions { } table.productoptions td { white-space:nowrap; border-top:1px; border-top-color:#cccccc; border-top-style:solid; padding:5px;}

Eventually, I'd like to figure out how to make individual rows highlight based on the variant selections made by the customer - but that's a ways down my to-do list.

See it in action here: http://www.napawear.com - LIVE SITE (no test orders, please!)
The mod above was written for X-cart Gold 4.0.13

Happy modding.
-Glen[/url]
__________________
NO LONGER USING X-CART - NOT ACTIVE IN THESE FORUMS
Reply With Quote