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

Case Quantities (ie. 12, 24, 36, etc) in quantity pulldown

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #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
  #2  
Old 03-02-2006, 06:54 AM
 
gfiebich gfiebich is offline
 

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

Default

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
__________________
NO LONGER USING X-CART - NOT ACTIVE IN THESE FORUMS
Reply With Quote
  #3  
Old 05-11-2006, 08:28 AM
  photo's Avatar 
photo photo is offline
 

X-Wizard
  
Join Date: Feb 2006
Location: UK
Posts: 1,146
 

Default

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
__________________
v4.1.10
In Dev v4.5.x


"If you don't keep an eye on your business, someone else will."
Reply With Quote
  #4  
Old 05-15-2006, 02:53 AM
  photo's Avatar 
photo photo is offline
 

X-Wizard
  
Join Date: Feb 2006
Location: UK
Posts: 1,146
 

Default

I also found out I only have this problem if the product has a variant.
__________________
v4.1.10
In Dev v4.5.x


"If you don't keep an eye on your business, someone else will."
Reply With Quote
  #5  
Old 05-15-2006, 11:31 AM
 
gfiebich gfiebich is offline
 

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

Default

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
__________________
NO LONGER USING X-CART - NOT ACTIVE IN THESE FORUMS
Reply With Quote
  #6  
Old 05-15-2006, 11:39 AM
  photo's Avatar 
photo photo is offline
 

X-Wizard
  
Join Date: Feb 2006
Location: UK
Posts: 1,146
 

Default

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
__________________
v4.1.10
In Dev v4.5.x


"If you don't keep an eye on your business, someone else will."
Reply With Quote
  #7  
Old 05-15-2006, 12:02 PM
  photo's Avatar 
photo photo is offline
 

X-Wizard
  
Join Date: Feb 2006
Location: UK
Posts: 1,146
 

Default

That did the trick Glen.

Thanks again
Tony
__________________
v4.1.10
In Dev v4.5.x


"If you don't keep an eye on your business, someone else will."
Reply With Quote
  #8  
Old 05-15-2006, 04:55 PM
 
gfiebich gfiebich is offline
 

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

Default

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
__________________
NO LONGER USING X-CART - NOT ACTIVE IN THESE FORUMS
Reply With Quote
  #9  
Old 05-16-2006, 05:57 AM
  photo's Avatar 
photo photo is offline
 

X-Wizard
  
Join Date: Feb 2006
Location: UK
Posts: 1,146
 

Default

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
__________________
v4.1.10
In Dev v4.5.x


"If you don't keep an eye on your business, someone else will."
Reply With Quote
  #10  
Old 11-06-2006, 05:00 PM
 
bretto bretto is offline
 

Member
  
Join Date: Jan 2006
Posts: 12
 

Default Re: Case Quantities (ie. 12, 24, 36, etc) in quantity pulldown

Thanks so much for the code. Works a treat.
__________________
X-Cart - 4.0.17
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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:40 PM.

   

 
X-Cart forums © 2001-2020