Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

Eliminate out of stock options

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #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
  #2  
Old 11-09-2006, 05:25 AM
 
balinor balinor is offline
 

Veteran
  
Join Date: Oct 2003
Location: Connecticut, USA
Posts: 30,253
 

Default Re: Eliminate out of stock options

Hey Ralph...quick question...you say this eliminates options, not variants. However, since options don't have a stock value associated with them, not sure that makes any sense? Basically I have a client who wants to eliminate out of stock variants from displaying...is that what this does?
__________________
Padraic Ryan
Ryan Design Studio
Professional E-Commerce Development
Reply With Quote
  #3  
Old 11-09-2006, 06:14 AM
 
geckoday geckoday is offline
 

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

Default Re: Eliminate out of stock options

It eliminates option values where all variants that include that value have no stock. If you have a single option class for a product then the net effect is to eliminate out of stock variants. If you have multiple option classes for a product there will still be option value combinations that can be out of stock.

To eliminate all out of stock variants it requires some somewhat complex UI changes that I haven't found the time to tackle yet. The two most common are:
  1. Build a list of all the option value combinations (i.e. variants) that are in stock and list them in a single dropdown. rei.com does this.
  2. Force the user to choose option values from the option classes in a fixed sequence (e.g first select size, then select color) resetting subsequent option class dropdowns to only those option values that have variants with stock. nordstrom.com does this.
__________________
Manuka Bay Company
X-Cart Version 4.0.19 [Linux]

UGG Boots and other fine sheepskin products
http://www.snowriver.com
Reply With Quote
  #4  
Old 11-09-2006, 06:43 AM
 
balinor balinor is offline
 

Veteran
  
Join Date: Oct 2003
Location: Connecticut, USA
Posts: 30,253
 

Default Re: Eliminate out of stock options

Got it, thanks! I think someone could make a decent chunk of change if they wrote a 'dynamic option' mod where one option controls what is displayed in the next option.
__________________
Padraic Ryan
Ryan Design Studio
Professional E-Commerce Development
Reply With Quote
  #5  
Old 12-12-2006, 10:34 AM
 
stevekem stevekem is offline
 

Senior Member
  
Join Date: Dec 2006
Posts: 111
 

Default Re: Eliminate out of stock options

Quote:
Originally Posted by geckoday
  1. Force the user to choose option values from the option classes in a fixed sequence (e.g first select size, then select color) resetting subsequent option class dropdowns to only those option values that have variants with stock. nordstrom.com does this.


Hello,

Do you happen to know how to do the above like nordstrom.com? I am looking for mod just like this ASAP and am willing to pay a reasonable price for it. Thanks in advance!
__________________
X-Cart Gold v4.4.1
Reply With Quote
  #6  
Old 12-15-2006, 06:21 AM
 
SMDStudios SMDStudios is offline
 

eXpert
  
Join Date: Dec 2003
Location: Orlando, FL
Posts: 207
 

Default Re: Eliminate out of stock options

Has anyone done this? I need this like yesterday?

Quote:
Originally Posted by balinor
Got it, thanks! I think someone could make a decent chunk of change if they wrote a 'dynamic option' mod where one option controls what is displayed in the next option.
__________________
X-Cart Gold various versions
Tahoe Web Design

WebsiteCM.com - We recommend WebsiteCM
Reply With Quote
  #7  
Old 03-11-2008, 06:55 AM
 
hhiker hhiker is offline
 

eXpert
  
Join Date: May 2007
Posts: 231
 

Default Re: Eliminate out of stock options

Does anyone know if this will work with 4.1.8?

Quote:
I think someone could make a decent chunk of change if they wrote a 'dynamic option' mod where one option controls what is displayed in the next option.

Well, since I have dug this thread out of the back room, apparently no one wanted to make a good chunk of change! I sure wish I knew enough to be able to make this happen. But for now, if the original post will work with 4.1.8, I will use it. Any help is better than none.
__________________
-
-
Versions: 4.1.10 and 4.3.0 (see post for which cart)

"Until man duplicates a blade of grass, nature can laugh at his so-called scientific knowledge." - Thomas Edison

"Never doubt that a small group of thoughtful, committed citizens can change the world; indeed, it is the only thing that ever has." - Margaret Mead (1901-197 quoted in John M. RIchardson, ed. Making it Happen, 1982

"Water is the best of all things." - Pindar (c. 522 BC - c. 438 BC), Olympian Odes
Reply With Quote
  #8  
Old 03-11-2008, 07:00 AM
 
balinor balinor is offline
 

Veteran
  
Join Date: Oct 2003
Location: Connecticut, USA
Posts: 30,253
 

Default Re: Eliminate out of stock options

I have used it on 4.1.8 successfully, yes.
__________________
Padraic Ryan
Ryan Design Studio
Professional E-Commerce Development
Reply With Quote
  #9  
Old 03-11-2008, 08:57 AM
 
hhiker hhiker is offline
 

eXpert
  
Join Date: May 2007
Posts: 231
 

Default Re: Eliminate out of stock options

Were there any modifications you had to make to the original post? I can not seem to get it to work on the test server.
__________________
-
-
Versions: 4.1.10 and 4.3.0 (see post for which cart)

"Until man duplicates a blade of grass, nature can laugh at his so-called scientific knowledge." - Thomas Edison

"Never doubt that a small group of thoughtful, committed citizens can change the world; indeed, it is the only thing that ever has." - Margaret Mead (1901-197 quoted in John M. RIchardson, ed. Making it Happen, 1982

"Water is the best of all things." - Pindar (c. 522 BC - c. 438 BC), Olympian Odes
Reply With Quote
  #10  
Old 03-11-2008, 08:59 AM
 
balinor balinor is offline
 

Veteran
  
Join Date: Oct 2003
Location: Connecticut, USA
Posts: 30,253
 

Default Re: Eliminate out of stock options

I'll need to dig back into the code. I'm adding it to a site this week, I'll post back here with the results.
__________________
Padraic Ryan
Ryan Design Studio
Professional E-Commerce Development
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 03:24 AM.

   

 
X-Cart forums © 2001-2020