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

Limiting the purchase quantity of a product

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #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
  #2  
Old 10-03-2007, 03:58 PM
  dire_lobo's Avatar 
dire_lobo dire_lobo is offline
 

Advanced Member
  
Join Date: Dec 2005
Posts: 53
 

Default 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!
__________________
4.1.8 live
shared server/hosted linux
Physical Location: New Mexico, USA
Server Location: Arizona, USA
Reply With Quote
  #3  
Old 10-03-2007, 05:12 PM
 
balinor balinor is offline
 

Veteran
  
Join Date: Oct 2003
Location: Connecticut, USA
Posts: 30,253
 

Default Re: Limiting the purchase quantity of a product

Moving to Completed Custom Mods
__________________
Padraic Ryan
Ryan Design Studio
Professional E-Commerce Development
Reply With Quote
  #4  
Old 10-04-2007, 07:59 AM
 
kacz kacz is offline
 

Member
  
Join Date: Aug 2007
Posts: 11
 

Default 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.
__________________
X-Cart Pro - 4.1.8
X-Cart Pro - 4.1.9
Custom Mods and Skinning
Reply With Quote
  #5  
Old 07-06-2008, 08:50 PM
  imexhouse's Avatar 
imexhouse imexhouse is offline
 

eXpert
  
Join Date: May 2006
Location: Canada
Posts: 377
 

Default 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}
__________________
Jack@AquasanaCA
X-CART GOLD 4.0.19 Live
DSEFU, AOM, ezCheckout, ezUpsell, ezRecommends, RememberMe, RememberAnonCarts
AquasanaCanada.com - Aquasana╝ - #1 Rated Water Filters in America!
X-CART GOLD 4.4.5 Live
CDSEO Pro v. 1.8.4
AquasanaMontreal.com
Aquasana╝ & Rhino Water Filtration Systems
Reply With Quote
  #6  
Old 08-25-2009, 09:04 AM
 
brettsontfarrey brettsontfarrey is offline
 

Member
  
Join Date: Oct 2007
Location: Madison, WI
Posts: 12
 

Default 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.
__________________
xcart 4.2.3
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions



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 06:00 PM.

   

 
X-Cart forums © 2001-2020