View Single Post
  #1  
Old 09-06-2007, 08:38 AM
 
kacz kacz is offline
 

Member
  
Join Date: Aug 2007
Posts: 11
 

Default Limiting the purchase quantity of a product

Here's a method for setting up X-Cart to set a maximum order quantity by item:

1. Update the table"*products" to include a column called "max_amount"

1a. Set a max amount for a single product using a SQL update (for test purposes)

1b. Add a row to the table *languages as follows: insert into xcart_languages (code, name, value, topic) values('US', 'lbl_max_amount', 'Maximum Order Quantity', 'Labels')

<<note, the items in bold may be modified to suit your particular configuration)


2. Update the /include/product_modify.php file to include this in the product array (search for "min_amount=" and then add it in the next row):

"max_amount" => $max_amount,


3. Update /main/product_details.tpl to include this row <tr> right after the row <tr> that lays out $product.min_amount

<tr>
{if $geid ne ''}<td width="15" class="TableSubHead"><input type="checkbox" value="Y" name="fields[max_amount]" /></td>{/if}
<td class="FormButton" nowrap="nowrap">{$lng.lbl_max_amount}</td>
<td class="ProductDetails"><input type="text" name="max_amount" size="18" value="{if $product.productid eq ""}1{else}{$product.max_amount}{/if}" /></td>
</tr>

4. Now, you need to change the skin1/customer/main/cart.tpl file because it handles order amounts as a text field and not a select field. So, first, add this to near the top of the file (on the line directly after the first "{/if}" ):

{literal}
<script type="text/javascript">
function validate(order,max)
{
if ((order*1)>(max*1))
{
msg="Your order quantity of ";
msg+=order;
msg+=" exceeds the maximum order quantity of ";
msg+=max;
alert(msg);
return false
}
else {return true}
}
</script>
{/literal}

This sets up the simple validation rules.

5. Now, add this between the two <br/>'s which follow the {include file="modules/Special_Offers/customer/cart_free.tpl"}

<input type="hidden" name="productmaxamount{$products[product].cartid}" value="{if $products[product].max_amount le $products[product].min_amount}{$config.Appearance.max_select_quantit y}{else}{ $products[product].max_amount}{/if}">

(this places the productmaxamount in close proximity to the product order amount and sets the max order quantity to either the product's max order quantity or the Appearance.Max selection quantity)

6. In the <input> tag that describes the productindexes fields (look for something like this: name="productindexes[{$products[product].cartid}]") insert the onchange reference to call the validate script:


onchange="validate(this.value, document.cartform.productmaxamount{$products[product].cartid}.value);"

7. Modify include/product_modify.php by adding the followng lines AFTER the comment # Correct the min_amount (this will set the max_amount to the value you set in Appearance Maximum number of selections in quantity selectbox):

if (empty($max_amount) || intval($max_amount) == 0)
$max_amount = $config['Appearance']['max_select_quantity'];

8. Now, modify/customer/main/product.tpl as follows
Change:
{assign var="mq" value=$config.Appearance.max_select_quantity}

To
{assign var="mq" value=$product.max_amount}

Change:


{math equation="min(maxquantity+minamount, productquantity+1)" assign="mq" maxquantity=$config.Appearance.max_select_quantity minamount=$minamount productquantity=$product.avail}



to:


{math equation="min(maxquantity+minamount, productquantity+1)" assign="mq" maxquantity=$product_max_amount minamount=$minamount productquantity=$product.avail}


There is a much more complex hack to implement this same limiter in a configured product. Drop me a line and I can walk you through it...



And voila! You've got a max order amount for both the catalog and the cart.
__________________
X-Cart Pro4.1.8
__________________
X-Cart Pro - 4.1.8
X-Cart Pro - 4.1.9
Custom Mods and Skinning
Reply With Quote