View Single Post
  #37  
Old 01-19-2012, 06:53 AM
 
philrisk philrisk is offline
 

X-Adept
  
Join Date: Jul 2009
Location: Newcastle upon Tyne, UK
Posts: 412
 

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

I have just successfully got this to work on 4.4.4 and also work on the product categories pages. Kudos to gfiebich for the original mod.
  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 (in my case) /skin/2-columns/customer/main/product_details.tpl or /skin/common_files/customer/main/product_details.tpl

    Find:

    HTML Code:
    {if $product.forsale neq "B" or ($product.forsale eq "B" and $smarty.get.pconf ne "" and $active_modules.Product_Configurator)} {if $active_modules.Product_Options ne ""} {if ($active_modules.Extra_Fields and $extra_fields) or ($active_modules.Feature_Comparison and $product.features.options)} <tr> <td colspan="3" class="poptions-product-separator">&nbsp;</td> </tr> {/if} {include file="modules/Product_Options/customer_options.tpl" disable=$lock_options} {/if} {/if}

    Replace with:

    HTML Code:
    {* CASESIZE MOD - 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 $product.forsale neq "B" or ($product.forsale eq "B" and $smarty.get.pconf ne "" and $active_modules.Product_Configurator)} {if $active_modules.Product_Options ne ""} {if ($active_modules.Extra_Fields and $extra_fields) or ($active_modules.Feature_Comparison and $product.features.options)} <tr> <td colspan="3" class="poptions-product-separator">&nbsp;</td> </tr> {/if} {include file="modules/Product_Options/customer_options.tpl" casesize=$case_size disable=$lock_options} {/if} {/if} {* CASESIZE MOD - End *}

    Find:

    HTML Code:
    var avail = {$product.appearance.max_quantity|default:1};

    Replace with:

    HTML Code:
    {if $case_size eq ''} var avail = {$product.appearance.max_quantity|default:1}; {/if}

    Find:

    HTML Code:
    {section name=quantity loop=$product.appearance.loop_quantity start=$product.appearance.min_quantity}

    Replace with:

    HTML Code:
    {section name=quantity loop=$product.appearance.loop_quantity start=$product.appearance.min_quantity step=$case_size}
  3. Open skin/common_files/modules/Product_Options/customer_options.tpl

    Find:

    HTML Code:
    {include file="modules/Product_Options/check_options.tpl"}

    Replace with:

    HTML Code:
    {include file="modules/Product_Options/check_options.tpl" case_size=$casesize}
  4. Open /skin/common_files/modules/Product_Options/func.js

    Find:

    HTML Code:
    if (availObj && availObj.tagName.toUpperCase() == 'SELECT') { // Select box if (!isNaN(min_avail) && !isNaN(avail)) { var first_value = -1; if (availObj.options[0]) first_value = availObj.options[0].value; if (first_value == min_avail) { /* New and old first value in quantities list is equal */ if ((avail-min_avail+1) != availObj.options.length) { if (availObj.options.length > avail-min_avail+1) { var cnt = availObj.options.length; for (var x = (avail-min_avail+1 < 0 ? 0 : avail-min_avail+1); x < cnt; x++) availObj.options[availObj.options.length-1] = null; } else { var cnt = availObj.options.length; for (var x = cnt+min_avail; x <= avail-min_avail+1; x++) availObj.options[cnt++] = new Option(x, x); } } } else { /* New and old first value in quantities list is differ */ var cnt = availObj.options.length - 1; while (cnt >= 0) availObj.options[cnt--] = null; cnt = 0; for (var x = min_avail; x <= avail; x++) availObj.options[cnt++] = new Option(x, x); } if (availObj.options.length == 0 || min_avail > avail) availObj.options[0] = new Option(txt_out_of_stock, 0); } select_avail = availObj.options[availObj.selectedIndex].value; } else if (availObj && availObj.tagName.toUpperCase() == 'INPUT' && availObj.type.toUpperCase() == 'TEXT') { // Input box if (!isNaN(min_avail) && !isNaN(avail)) { availObj.minQuantity = min_avail; availObj.maxQuantity = max_avail; } if (isNaN(parseInt(availObj.value)) || availObj.value == 0) availObj.value = min_avail; select_avail = availObj.value; }

    Replace with:

    HTML Code:
    if (availObj && availObj.tagName.toUpperCase() == 'SELECT') { if (case_size == '') { // Select box if (!isNaN(min_avail) && !isNaN(avail)) { var first_value = -1; if (availObj.options[0]) first_value = availObj.options[0].value; if (first_value == min_avail) { /* New and old first value in quantities list is equal */ if ((avail-min_avail+1) != availObj.options.length) { if (availObj.options.length > avail-min_avail+1) { var cnt = availObj.options.length; for (var x = (avail-min_avail+1 < 0 ? 0 : avail-min_avail+1); x < cnt; x++) availObj.options[availObj.options.length-1] = null; } else { var cnt = availObj.options.length; for (var x = cnt+min_avail; x <= avail-min_avail+1; x++) availObj.options[cnt++] = new Option(x, x); } } } else { /* New and old first value in quantities list is differ */ var cnt = availObj.options.length - 1; while (cnt >= 0) availObj.options[cnt--] = null; cnt = 0; for (var x = min_avail; x <= avail; x++) availObj.options[cnt++] = new Option(x, x); } if (availObj.options.length == 0 || min_avail > avail) availObj.options[0] = new Option(txt_out_of_stock, 0); } select_avail = availObj.options[availObj.selectedIndex].value; } else if (availObj && availObj.tagName.toUpperCase() == 'INPUT' && availObj.type.toUpperCase() == 'TEXT') { // Input box if (!isNaN(min_avail) && !isNaN(avail)) { availObj.minQuantity = min_avail; availObj.maxQuantity = max_avail; } if (isNaN(parseInt(availObj.value)) || availObj.value == 0) availObj.value = min_avail; select_avail = availObj.value; } }
  5. Open /skin/common_files/customer/main/buy_now.tpl

    Find:

    HTML Code:
    <select name="amount"> {section name=quantity loop=$product.appearance.loop_quantity start=$product.appearance.min_quantity} <option value="{%quantity.index%}"{if $smarty_get_quantity eq %quantity.index%} selected="selected"{/if}>{%quantity.index%}</option> {/section} </select>

    Replace with:

    HTML Code:
    {section name=field loop=$products} {section name=field2 loop=$products[field].extra_fields} {if $products[field].extra_fields[field2].field eq "CaseSize" && $products[field].extra_fields[field2].field_value ne ""} {assign var="case_size" value=$products[field].extra_fields[field2].field_value}{/if} {/section} {/section} <select name="amount"> {section name=quantity loop=$product.appearance.loop_quantity start=$product.appearance.min_quantity step=$case_size} <option value="{%quantity.index%}"{if $smarty_get_quantity eq %quantity.index%} selected="selected"{/if}>{%quantity.index%}</option> {/section} </select>
  6. Now, edit an item that you want to display with case quantities
  7. Set the "Min order amount" to the quantity you want to start at ("12" in my example).
  8. Set the "CaseSize" to the number you want to STEP by ("12" in my example).
__________________
Live with Gold 4.5.1
Dedicated Linux server
MaxCDN 4 pull zones
Dedicated SSL

Reply With Quote