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)
-   -   Case Quantities (ie. 12, 24, 36, etc) in quantity pulldown (https://forum.x-cart.com/showthread.php?t=19986)

gfiebich 02-17-2006 12:52 PM

Case Quantities (ie. 12, 24, 36, etc) in quantity pulldown
 
I needed the ability to offer some items in "case quantities" (ie. 12, 24, 36, etc). This thread (http://forum.x-cart.com/viewtopic.php?t=23097) describes how to do this site-wide, but I also have items which are sold in single units. Here's what I did: (This has been edited to resolve the Variant Qty problem described in the posts below. GF) (I've edited the code again to patch another javascript issue - argh.)
  1. Create an Extra Field in the admin called "CaseSize". This will contain the number we will use to STEP by. Uncheck "show".
  2. Open skin1/customer/main/product.tpl and find:
    Code:

    {if $active_modules.Product_Options ne ""}
    {include file="modules/Product_Options/customer_options.tpl"}
    {/if}

    and replace it with
    Code:

    {* Determine if product is sold in Case Quantities. This is handled with an Extra Product Field. *}
    {section name=field loop=$extra_fields}
    {if $extra_fields[field].field eq "CaseSize" && $extra_fields[field].field_value ne ""}
    {assign var="case_size" value=$extra_fields[field].field_value}{/if}
    {/section}

    {if $active_modules.Product_Options ne ""}
    {include file="modules/Product_Options/customer_options.tpl" casesize=$case_size}
    {/if}

  3. Find
    Code:

    var avail = {$mq|default:1}-1;
    and replace it with
    Code:

    {if $case_size eq ''}
    var avail = {$mq|default:1}-1;
    {/if}

  4. Find
    Code:

    {section name=quantity loop=$mq start=$start_quantity}
    and replace it with
    Code:

    {section name=quantity loop=$mq start=$start_quantity step=$case_size}
  5. Open modules/Product_Options/customer_options.tpl and find
    Code:

    {include file="modules/Product_Options/check_options.tpl"}
    and replace it with
    Code:

    {include file="modules/Product_Options/check_options.tpl" case_size=$casesize}
  6. Open modules/Product_Options/check_options.tpl and find
    Code:

                            if(!isNaN(min_avail) && !isNaN(avail)) {
                                    var first_value = -1;
                                    if(document.getElementById('product_avail').options[0])
                                            first_value = document.getElementById('product_avail').options[0].value;
                                    if(first_value == min_avail) {
                                            if((avail-min_avail+1) != document.getElementById('product_avail').options.length) {
                                                    if(document.getElementById('product_avail').options.length > avail) {
                                                            cnt = document.getElementById('product_avail').options.length;
                                                            for(x = avail; x < cnt; x++)
                                                                    document.getElementById('product_avail').options[document.getElementById('product_avail').options.length-1] = null;
                                                    } else {
                                                            cnt = document.getElementById('product_avail').options.length;
                                                            for(x = cnt+1; x <= avail; x++)
                                                                    document.getElementById('product_avail').options[cnt++] = new Option(x, x);
                                                    }
                                            }
                                    } else {
                                            while(document.getElementById('product_avail').options.length > 0)
                                                    document.getElementById('product_avail').options[0] = null;
                                            cnt = 0;
                                            for(x = min_avail; x <= avail; x++)
                                                    document.getElementById('product_avail').options[cnt++] = new Option(x, x);
                                    }
                                    if(document.getElementById('product_avail').options.length == 0)
                                            document.getElementById('product_avail').options[0] = new Option(txt_out_of_stock, 0);
                            }

    and replace it with
    Code:

                            if (case_size == '') {
                                    if(!isNaN(min_avail) && !isNaN(avail)) {
                                            var first_value = -1;
                                            if(document.getElementById('product_avail').options[0])
                                                    first_value = document.getElementById('product_avail').options[0].value;
                                            if(first_value == min_avail) {
                                                    if((avail-min_avail+1) != document.getElementById('product_avail').options.length) {
                                                            if(document.getElementById('product_avail').options.length > avail) {
                                                                    cnt = document.getElementById('product_avail').options.length;
                                                                    for(x = avail; x < cnt; x++)
                                                                            document.getElementById('product_avail').options[document.getElementById('product_avail').options.length-1] = null;
                                                            } else {
                                                                    cnt = document.getElementById('product_avail').options.length;
                                                                    for(x = cnt+1; x <= avail; x++)
                                                                            document.getElementById('product_avail').options[cnt++] = new Option(x, x);
                                                            }
                                                    }
                                            } else {
                                                    while(document.getElementById('product_avail').options.length > 0)
                                                            document.getElementById('product_avail').options[0] = null;
                                                    cnt = 0;
                                                    for(x = min_avail; x <= avail; x++)
                                                            document.getElementById('product_avail').options[cnt++] = new Option(x, x);
                                            }
                                            if(document.getElementById('product_avail').options.length == 0)
                                                    document.getElementById('product_avail').options[0] = new Option(txt_out_of_stock, 0);
                                    }
                            }

  7. Now, edit an item that you want to display with case quantities
  8. set the "Min order amount" to the quantity you want to start at ("12" in my example).
  9. set the "CaseSize" to the number you want to STEP by ("12" in my example).

That's it! Items that don't have a CaseSize set will behave normally, stepping by 1. Notes: If you allow customers to update item quantities in the cart, they will be able to change their quantities to non case quantity multiples. Items using CaseSize will not benefit from X-cart's built-in inventory javascript. This was done in x-cart gold 4.0.13.

happy modding,
Glen

gfiebich 03-02-2006 06:54 AM

I've updated the code above to fix a problem with the quantity listing when showing case quanitities. The javascript on product.tpl also controls the quantity select menu and this needed to be edited to match how the Section loop behaved.

-Glen

photo 05-11-2006 08:28 AM

Hello Glen

I installed this mod and it works great except for the "step" option in the dropdown box. I have it set up to step by 10 up to 500 which it does, but after the 500 in the dropdown box it goes to 60, 61, 62, ect.. up to 500

Example of options in drop down box:

480
490
500
60
61
62

Any idea what may be causing this?

Thanks

photo 05-15-2006 02:53 AM

I also found out I only have this problem if the product has a variant.

gfiebich 05-15-2006 11:31 AM

Tony -
I've edited the original code above to fix the problem you found. Items with Variants and CaseSize should now display a proper Quantity selection pulldown. Thanks for spotting that.
-Glen

photo 05-15-2006 11:39 AM

Quote:

Originally Posted by gfiebich
Tony -
I've edited the original code above to fix the problem you found. Items with Variants and CaseSize should now display a proper Quantity selection pulldown. Thanks for spotting that.
-Glen


Thanks alot Glen I'll give it try. Really apreciate you taking the time to check this out.

Tony

photo 05-15-2006 12:02 PM

That did the trick Glen.

Thanks again
Tony

gfiebich 05-15-2006 04:55 PM

I've updated the code again with hopefully the last fix. Today's previous update disabled the "add to cart" button (whoops). The new fix applies to modules/product_options/check_options.tpl and turns off some javascript if the item has case quantities.

-Glen

photo 05-16-2006 05:57 AM

Thanks Glen,

I turned in a ticket on this to see if there is a way of doing this without losing X-cart's built-in inventory javascript.

Thanks
Tony

bretto 11-06-2006 05:00 PM

Re: Case Quantities (ie. 12, 24, 36, etc) in quantity pulldown
 
Thanks so much for the code. Works a treat.


All times are GMT -8. The time now is 07:26 PM.

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