View Single Post
  #20  
Old 04-30-2008, 12:56 PM
 
itsmeee itsmeee is offline
 

Advanced Member
  
Join Date: Sep 2007
Posts: 56
 

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

Alright, now again please realize I've only been working with PHP for a little bit here and everything I know I've taught myself. So if anyone good could make sure I'm not screwing stuff up that would be great.

Anyway my problem as I listed in my last post is that I needed certain products such as bookmarks to be purchased in certain quantities by wholesale members while regular users needed to be able to purchase whatever amount they wanted.

We start with what gfiebich posted but with my modifications for the 4.1.8 ver (maybe the whole 4.1.x branch).
  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/func.js and find
    Code:
    if (!availObj) availObj = document.getElementById('product_avail'); if (availObj && availObj.tagName.toUpperCase() == 'SELECT') { 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) { var cnt = availObj.options.length; for (var x = (avail < 0 ? 0 : avail); x < cnt; x++) availObj.options[availObj.options.length-1] = null; } else { var cnt = availObj.options.length; for (var x = cnt+1; x <= avail; x++) availObj.options[cnt++] = new Option(x, x); } } } else { /* New and old first value in quantities list is differ */ while (availObj.options.length > 0) availObj.options[0] = null; var cnt = 0; for (var x = min_avail; x <= avail; x++) availObj.options[cnt++] = new Option(x, x); } if (availObj.options.length == 0) availObj.options[0] = new Option(txt_out_of_stock, 0); } select_avail = availObj.options[availObj.selectedIndex].value; } check_wholesale(select_avail); if ((alert_msg == 'Y') && (min_avail > avail)) alert(txt_out_of_stock);

    and replace it with

    Code:
    if (case_size == '') { if (!availObj) availObj = document.getElementById('product_avail'); if (availObj && availObj.tagName.toUpperCase() == 'SELECT') { 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) { var cnt = availObj.options.length; for (var x = (avail < 0 ? 0 : avail); x < cnt; x++) availObj.options[availObj.options.length-1] = null; } else { var cnt = availObj.options.length; for (var x = cnt+1; x <= avail; x++) availObj.options[cnt++] = new Option(x, x); } } } else { /* New and old first value in quantities list is differ */ while (availObj.options.length > 0) availObj.options[0] = null; var cnt = 0; for (var x = min_avail; x <= avail; x++) availObj.options[cnt++] = new Option(x, x); } if (availObj.options.length == 0) availObj.options[0] = new Option(txt_out_of_stock, 0); } select_avail = availObj.options[availObj.selectedIndex].value; } check_wholesale(select_avail); if ((alert_msg == 'Y') && (min_avail > avail)) alert(txt_out_of_stock); }
  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).

To add in the functionality so that certain products such as bookmarks to be purchased in certain quantities by wholesale members while regular users needed to be able to purchase whatever amount they wanted.
  • Follow this link and follow the instructions so that you can specify things in smarty based on membership levels you've created.
  • Now open modules/Product_Options/customer_options.tpl again and find this:
    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}

    and replace with:

    Code:
    {if $usermembership == "Wholesale"} {* 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}{** end **} {else} {if $active_modules.Product_Options ne ""} {include file="modules/Product_Options/customer_options.tpl"} {/if} {/if}
  • Now in the same file find this:
    Code:
    {section name=quantity loop=$mq start=$start_quantity step=$case_size}

    and replace it with:

    Code:
    {if $usermembership == "Wholesale"} {section name=quantity loop=$mq start="0" step=$case_size} <option value="{%quantity.index%}"{if $smarty.get.quantity eq %quantity.index%} selected="selected"{/if}>{%quantity.index%}</option> {/section} {else} {section name=quantity loop=$mq start=$start_quantity} <option value="{%quantity.index%}"{if $smarty.get.quantity eq %quantity.index%} selected="selected"{/if}>{%quantity.index%}</option> {/section} {/if}

This isn't fully finished. I'd like to change the starting # from "0" to something I have defined in an extra field. I'm sort of figuring out how to do this.
__________________
Version 4.1.8
Reply With Quote