View Single Post
  #1  
Old 02-17-2006, 12:52 PM
 
gfiebich gfiebich is offline
 

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

Default 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
__________________
NO LONGER USING X-CART - NOT ACTIVE IN THESE FORUMS
Reply With Quote