X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (https://forum.x-cart.com/forumdisplay.php?f=20)
-   -   Eliminate out of stock options (https://forum.x-cart.com/showthread.php?t=19015)

geckoday 01-03-2006 03:30 PM

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.

balinor 11-09-2006 05:25 AM

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?

geckoday 11-09-2006 06:14 AM

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.

balinor 11-09-2006 06:43 AM

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.

stevekem 12-12-2006 10:34 AM

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!

SMDStudios 12-15-2006 06:21 AM

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.


hhiker 03-11-2008 06:55 AM

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.

balinor 03-11-2008 07:00 AM

Re: Eliminate out of stock options
 
I have used it on 4.1.8 successfully, yes.

hhiker 03-11-2008 08:57 AM

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.

balinor 03-11-2008 08:59 AM

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.


All times are GMT -8. The time now is 09:52 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.