X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (https://forum.x-cart.com/forumdisplay.php?f=20)
-   -   Limiting the purchase quantity of a product (https://forum.x-cart.com/showthread.php?t=33735)

kacz 09-06-2007 08:38 AM

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

dire_lobo 10-03-2007 03:58 PM

Re: Limiting the purchase quantity of a product
 
kacz,

OUTSTANDING work. Both the mod and the instructions seem well thought out and clear. Looks like it would work nicely. Adding it to my evergrowing list. Based on an honest evaulation of my skillset, implementation does looks a little daunting to me (like it's ragged wobbling on the edge between "yes! I got it!" and "Oh crap, where did I screw up THIS time?!?!" ;-) but worth a try!

balinor 10-03-2007 05:12 PM

Re: Limiting the purchase quantity of a product
 
Moving to Completed Custom Mods

kacz 10-04-2007 07:59 AM

Re: Limiting the purchase quantity of a product
 
thanks, I've actually done a bit more with this mod. The biggest problem that I had to deal with is that my client had items for which tens of thousands could be purchased (he does large-scale DVD and CD replication). So, when you try to load the items with the max order quantity of say 50,000 you'll spin for minutes building the <select> form element.

The thing to do then was to replace the <select> form element with an <input type'"text"> element for the quanity in the cart and on the product templates.

Doing that has the side effect of requiring that you change the way minimum order quantities get handled (in the past, min order quanitites could be controlled by setting the first value in the <select> element to the minimum quantity).


So, if you get to the point where MAX Order quantity or the $config.Appearance.max_select_quantity causes your system to dog while it writes a bunch of selects, just drop me a PM and an I can send the rest of the changes.

imexhouse 07-06-2008 08:50 PM

Re: Limiting the purchase quantity of a product
 
Error in this line:

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

Should be:

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

brettsontfarrey 08-25-2009 09:04 AM

Re: Limiting the purchase quantity of a product
 
This doesn't work. I use X-Cart Pro 4.1.8, and it worked when trying to add more than the max quantity in the cart, but the product page allowed for you to keep adding products. The drop down never populated correctly.


All times are GMT -8. The time now is 12:09 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.