Can I limit the Quantity to 1?

General ShopSite user discussion

Can I limit the Quantity to 1?

Postby jdjackson7 » Mon Dec 15, 2014 1:00 pm

We offer free samples at $0 cost. We want to limit the quantity a customer can purchase of each sample to only one. Is there a way to prevent someone from ordering more than one of a particular product?
Thanks
jdjackson7
 
Posts: 20
Joined: Wed Mar 23, 2011 11:21 am

Re: Can I limit the Quantity to 1?

Postby ShopSite Lauren » Tue Dec 16, 2014 10:40 am

Not really. ShopSite Pro does have inventory tracking which would allow one purchase total, but not one purchase per customer.

One solution might be to add the free samples with the coupon code, so that the sample product(s) is actually a dollar amount but customers can enter a coupon code to get 1 free sample. If you do this option, you can have the information right in the cart for customers to see..

"Have you chosen your free sample? Use coupon code: free4me"
- ShopSite Lauren
Contact me for help with any of your
custom ShopSite template questions.
ShopSite Lauren
 
Posts: 889
Joined: Fri Aug 11, 2006 1:35 pm
Location: Orem, UT

Re: Can I limit the Quantity to 1?

Postby dgray » Wed Jan 07, 2015 9:47 am

Don't know if this helps, but I wrote some javascript to warn a customer if quantity > 1 when they press the Checkout button:

(This goes in Commerce, Order System, Shopping Cart page, javascript checkit section. You'd need to add a test for your SKU.)

Code: Select all
<script>
<!-- Aug 14, 2013 This checks for quantity > 1, which is highly unlikely for downloads. -->
var quantity_check = true;
if (quantity_check && button == "8") {
   var nQuantityN = 0;
   for (var i=0; i < number_products; i++)
   {
      if ( ss_quantity[i] > 1)
         nQuantityN += 1;
   }
   if ( nQuantityN > 0 )
      return (confirm ("At least one item in your cart has the quantity set to more than one. If you only meant to order one of each item, please press Cancel now and correct your order, else press OK to proceed to the checkout."));
}
</script>
dgray
 
Posts: 54
Joined: Fri Sep 08, 2006 9:06 am

Re: Can I limit the Quantity to 1?

Postby jdjackson7 » Wed Jan 07, 2015 9:51 am

Hey dgray, Thanks for your reply. This is not really what I am looking for.
I want to make sure that a specific item (a sample) does not have a qty greater than 1. I only want someone to be able to order 1 of a sample. got any ideas?
jdjackson7
 
Posts: 20
Joined: Wed Mar 23, 2011 11:21 am

Re: Can I limit the Quantity to 1?

Postby dgray » Wed Jan 07, 2015 10:08 am

Yes, as I say, you can add a test for your particular SKU. I don't remember the SKU variable name off-hand, I think it's probably ss_sku, so in that case the code for your test would be something like:

Code: Select all
     if ( ss_sku[i] == "FREE_SAMPLE_SKU" && ss_quantity[i] > 1)
         nQuantityN += 1;


And just put your product's particular SKU text instead of FREE_SAMPLE_SKU. And it looks like the return value of False actually stops the customer proceeding to Checkout, which you could force, which I think is exactly what you want. Someone from ShopSite correct me if I'm wrong!
dgray
 
Posts: 54
Joined: Fri Sep 08, 2006 9:06 am

Re: Can I limit the Quantity to 1?

Postby dgray » Wed Jan 07, 2015 10:29 am

Ok, so maybe something like this. It resets the ss_quantity back to 1. Not sure if that will work or not (might be readonly). If not, just tell the customer to change it back to 1. Anyhow, they can't proceed while it's > 1.

Code: Select all
// Don't let customer order more that quantity one for SKU_123
var quantity_check = true;
if (quantity_check && button == "8") {
   var nQuantityN = 0;
   for (var i=0; i < number_products; i++)
   {
      if ( ss_sku[i] == "SKU_123" && ss_quantity[i] > 1) {
           ss_quantity[i] = 1;
           nQuantityN += 1;
      }
   }
   if ( nQuantityN > 0 ) {
      alert ("Sorry, only one free sample per customer. Quantity has been changed to one.");
      // or perhaps...
      alert ("Sorry, only one free sample per customer. Please set the quantity to 1 before proceeding to Checkout, thank you.");
      return (false);
   }
}
dgray
 
Posts: 54
Joined: Fri Sep 08, 2006 9:06 am

Re: Can I limit the Quantity to 1?

Postby jdjackson7 » Wed Jan 07, 2015 11:03 am

Yes this look like it could work. Any idea how I could use your code for multiple skus?
jdjackson7
 
Posts: 20
Joined: Wed Mar 23, 2011 11:21 am

Re: Can I limit the Quantity to 1?

Postby dgray » Wed Jan 07, 2015 11:35 am

Well, something a bit like this I guess... Untested, of course.

Code: Select all
    // Don't let customer order more that quantity one of the following SKUs
    var my_skus = ["SKU_X", "SKU_Y", "SKU_Z"];
    var quantity_check = true;

    // Perform the check
    if (quantity_check && button == "8") {
        var nQuantityN = 0;
        for (var i=0; i < number_products; i++) {
            for (var j = 0; j < my_skus.length; j++) {
                if ( ss_sku[i] == my_skus[j] && ss_quantity[i] > 1) {
                    ss_quantity[i] = 1;
                    nQuantityN += 1;
                }
            }
        }
        if ( nQuantityN > 0 ) {
            alert ("Sorry, only one free sample per customer. Quantity has been changed to one.");
            // or perhaps...
            alert ("Sorry, only one free sample per customer. Please set the quantity to 1 before proceeding to Checkout, thank you.");
            return (false);
        }
    }
dgray
 
Posts: 54
Joined: Fri Sep 08, 2006 9:06 am

Re: Can I limit the Quantity to 1?

Postby jdjackson7 » Wed Jan 07, 2015 11:45 am

Yeah I think that might do it. I will try it out and let you know. Thanks very much for your help! Have a good one.
jdjackson7
 
Posts: 20
Joined: Wed Mar 23, 2011 11:21 am


Return to User Forum

Who is online

Users browsing this forum: No registered users and 61 guests