View Single Post
  #1  
Old 01-03-2006, 03:30 PM
 
geckoday geckoday is offline
 

X-Wizard
  
Join Date: Aug 2005
Posts: 1,073
 

Default Eliminate out of stock options

I've developed a small mod to eliminate out of stock options from displaying on the product page. Note this eliminates options, not variants. For example, if you have a product with 3 colors (red, green, blue) and 3 sizes (S, M, L) and your stock looks like this:

Code:
Red Green Blue S 0 2 2 M 0 0 2 L 0 0 0
The color dropdown will show only Green and Blue. The Size dropdown will show S and M - no matter what color is selected. So the customer will never see Red because its completely out of stock in all sizes. Green will be displayed but the customer will be able to select M only to find out it is out of stock.

There are two files to change.

In modules/Product_Options/customer_options.php find:
Code:
if(!empty($product_options)) $smarty->assign("product_options",$product_options);
And insert this code right before it:
Code:
if (is_array($product_options)) { foreach($product_options as $k => $v) { foreach ($v['options'] as $k2 => $v2) { if ($v['is_modifier'] == '') { $sql = "SELECT COUNT($sql_tbl[variants].variantid) FROM $sql_tbl[variants] INNER JOIN $sql_tbl[variant_items] ON $sql_tbl[variants].variantid = $sql_tbl[variant_items].variantid WHERE $sql_tbl[variant_items].optionid = $v2[optionid] AND $sql_tbl[variants].avail > 0"; $product_options[$k]['options'][$k2]['any_stock'] = (int)func_query_first_cell($sql) > 0; } else { $product_options[$k]['options'][$k2]['any_stock'] = true; } } } }
In skin1/modules/Product_Options/customer_options.tpl find:
Code:
<OPTION value="{$o.optionid}"{if $o.selected eq 'Y'} selected{/if}>{$o.option_name}{if $v.is_modifier eq 'Y' && $o.price_modifier ne 0} ({if $o.modifier_type ne '%'}{include file="currency.tpl" value=$o.price_modifier display_sign=1}{else}{$o.price_modifier}%{/if}){/if}</OPTION>
And replace it with this:
Code:
{if $o.any_stock} <OPTION value="{$o.optionid}"{if $o.selected eq 'Y'} selected{/if}>{$o.option_name}{if $v.is_modifier eq 'Y' && $o.price_modifier ne 0} ({if $o.modifier_type ne '%'}{include file="currency.tpl" value=$o.price_modifier display_sign=1}{else}{$o.price_modifier}%{/if}){/if}</OPTION> {/if}

This was developed and tested on 4.0.14 but should drop in easily in other versions.

Hope this helps someone out.
__________________
Manuka Bay Company
X-Cart Version 4.0.19 [Linux]

UGG Boots and other fine sheepskin products
http://www.snowriver.com
Reply With Quote