Javascript to check if it Product Exists in Shopping Cart

General ShopSite user discussion

Javascript to check if it Product Exists in Shopping Cart

Postby sellmethemoney » Tue Dec 15, 2009 9:11 am

Hello,

I'm fairly new here at shopsite and I have a question.

Do any of you have a Javascript sample that can be added to a template in order to stop a customer from ordering the same product twice?

We need our customers to be able to order only 1 of each of our products. We already set the maximum quantity to 1 and the customer cannot change the total once it's been ordered.

We have Shopsite Pro version 10.

Thanks!

:D
sellmethemoney
 
Posts: 17
Joined: Tue Dec 15, 2009 9:00 am
Location: Chicago, IL

Postby robm » Tue Dec 15, 2009 11:17 am

This should work:

Code: Select all
var x = {}, len = ss_sku.length;
for (var i = 0; i < len; i++) {
  if ((x[ss_sku[i]] === true) && (button == "8")) {
    alert("Only ONE of each item is allowed to be ordered.");
    return false;
  }
  x[ss_sku[i]] = true;
}


Put the code in the textbox "Javascript added at start of built-in CheckIt function:" under Commerce Setup -> Shopping Cart
robm
 
Posts: 463
Joined: Fri Aug 04, 2006 5:46 pm
Location: Connecticut

Postby sellmethemoney » Tue Dec 15, 2009 12:09 pm

And it did beautifully!!

Thanks Rob.
sellmethemoney
 
Posts: 17
Joined: Tue Dec 15, 2009 9:00 am
Location: Chicago, IL

Re: Javascript to check if it Product Exists in Shopping Car

Postby Kennedy » Tue Jul 05, 2011 10:19 am

Is there a way to limit this to 2 particular sku #?

I only have 2 products that they can order only 1 of at a time.
Kennedy
 
Posts: 33
Joined: Fri Jun 10, 2011 6:18 am


Return to User Forum

Who is online

Users browsing this forum: No registered users and 39 guests