C4009
Ecommerce Template Expert
USA
612 Posts Pre-sales questions only (More Details...)
|
Posted - 04/06/2020 : 11:07:31
Friday we are getting in a number of cases of hand sanitizer (yes it was expensive but our customers will want it). We want to limit the purchase to one or two bottles per customer so that as many customers that would like to have some will be able to receive it as we do not have an unlimited quantity and when it is gone we will not be able to get more. Is there a way I can limit the number of units on an order? Thank you in advance.
Charles SleepRestfully.com
|
1818charlie
ECT Moderator
United Kingdom
1194 Posts |
Posted - 04/06/2020 : 11:25:25
Hi Charles
I don't think that's possible but it would be a good feature to have. I know there's a minimum quantity feature so a maximum one would be a good idea too. One for the suggestions. Perhaps Vince could work some magic
Steve Bolton, Lancashire, UK
Remember - Any edits to the ectcart.css file will be overwritten by updater's. ALL edits to ectcart.css rules should be placed in your style.css file
Edited by - 1818charlie on 04/06/2020 11:28:42
|
RobertBrady
New Member
USA
51 Posts Pre-sales questions only (More Details...)
|
Posted - 04/06/2020 : 12:14:06
I think this might help, if you assign the product with a coupon code perhaps?
https://www.ecommercetemplates.com/help/ecommplus/discounts.asp
|
dbdave
ECT Moderator
USA
10408 Posts |
Posted - 04/06/2020 : 12:34:12
Hi Charles, you know I love the javascript... I think it's possible to write something simple that will pick up on the product ID and the quantity for that item, and then fire a warning and stop checkout if the quantity exceeds your limit. When do you need this? I have a few irons in the fire right now, but I think I can work off some code I've already put together.
David
|
C4009
Ecommerce Template Expert
USA
612 Posts Pre-sales questions only (More Details...)
|
Posted - 04/06/2020 : 13:26:56
Dave to the rescue. Thank you. I need it for the end of the week if possible. I want to get this product to those in need.
Charles
|
dbdave
ECT Moderator
USA
10408 Posts |
Posted - 04/08/2020 : 23:53:25
Hi Charles, I didn't forget you. I am close on this and doing some final testing.
David
|
C4009
Ecommerce Template Expert
USA
612 Posts Pre-sales questions only (More Details...)
|
Posted - 04/09/2020 : 06:54:31
Thank you dave.
|
dbdave
ECT Moderator
USA
10408 Posts |
Posted - 04/09/2020 : 09:26:43
Hi Charles, try this out. And for anyone interested, this is designed for one product where you set a max quantity. It will check for that item and trigger an "alert" with a message that too many have been added and it disables checkout buttons until the quantity is adjusted. It's designed to only run on the first cart page. It is for .asp only. We could probably make it so the quantity adjusted automatically, but this should get you fixed up. There are two settings you need to make and that is shown in red. Place this near the bottom of your cart.asp page before the closing </body> tag. Please be sure to test it right away after installing. Thanks, David :::EDITED CODE BELOW 4/24::: <% 'BEGIN SET MAX PURCHASE QUANTITY if orderid="" then dim rsMax, contn, querymax, maxprodid, maxqty, chekqty maxprodid = "WIDGET" 'SET YOUR PRODUCT ID HERE (Must be in quotes) maxqty = 3 'SET YOUR MAX QUANTITY HERE (No quotes) %> <script> function maxFunction (maxqty,maxid) { alert ('WARNING Checkout disabled\nThe item '+maxid+' has a max allowable purchase of '+maxqty+' units.\nPlease adjust the quantity in your cart to no more than '+maxqty+'.'); if (document.getElementsByClassName("checkoutbutton1")[0]) {document.getElementsByClassName("checkoutbutton1")[0].style.display = "none";} if (document.getElementsByClassName("checkoutbutton1")[1]) {document.getElementsByClassName("checkoutbutton1")[1].style.display = "none";} if (document.getElementsByClassName("checkoutbutton1")[2]) {document.getElementsByClassName("checkoutbutton1")[2].style.display = "none";} if (document.getElementsByClassName("checkoutbutton1")[3]) {document.getElementsByClassName("checkoutbutton1")[3].style.display = "none";} if (document.getElementsByClassName("checkoutbutton1")[4]) {document.getElementsByClassName("checkoutbutton1")[4].style.display = "none";} } </script> <% set contn=Server.CreateObject("ADODB.Connection") contn.open sDSN querymax = "SELECT cartProdID, cartQuantity FROM cart WHERE cartCompleted = '0' AND cartSessionID='"&escape_string(thesessionid)&"'" Set rsMax = contn.Execute(querymax) Do Until rsMax.EOF if rsMax("cartProdID")= maxprodid then chekqty = rsMax("cartQuantity") if chekqty > maxqty then print "<body onload=""maxFunction("&maxqty&",'"&maxprodid&"')"">" end if end if rsMax.MoveNext Loop rsMax.close contn.Close Set contn = Nothing Set rsMax = Nothing end if 'END SET MAX PURCHASE QUANTITY %>
Edited by - dbdave on 04/24/2020 10:17:12
|
C4009
Ecommerce Template Expert
USA
612 Posts Pre-sales questions only (More Details...)
|
Posted - 04/09/2020 : 09:30:01
Thank you. I will try it today and let you know how it goes. You are the best.
|
dbdave
ECT Moderator
USA
10408 Posts |
Posted - 04/09/2020 : 09:30:06
Of course, if someone is savvy enough, they can bypass it and checkout, but that's highly unlikely.
David
|
dbdave
ECT Moderator
USA
10408 Posts |
Posted - 04/24/2020 : 10:19:06
IF anyone happened to be using this, beside Charles, I have edited the code to add a security fix and simplify the code just a bit. Please replace with this new code.
Thanks, David
|
C4009
Ecommerce Template Expert
USA
612 Posts Pre-sales questions only (More Details...)
|
Posted - 04/24/2020 : 10:55:21
Works like a charm Dave. Thank you so much.
Charles
|
midvalleydrifter001
Ecommerce Template Expert
USA
933 Posts |
Posted - 09/22/2020 : 19:33:32
I would very much be interested in this for PHP
Patrick
|
midvalleydrifter001
Ecommerce Template Expert
USA
933 Posts |
Posted - 01/30/2021 : 21:18:45
David,
Can this be done for PHP?
Patrick
|
dbdave
ECT Moderator
USA
10408 Posts |
Posted - 02/01/2021 : 22:14:56
While my skills with .php are not that strong, I believe I have this worked out and you can see a demo at my .php test site here https://www.floridasurpluswarehouse.com/dev/proddetail.php?prod=inkjet001Add more than three of those to the cart to see the action. Place the code below in the bottom of your cart.php page before the closing </body> tag Be sure to set the product ID and quantity there. <?php //BEGIN SET MAX PURCHASE QUANTITY if (empty($orderid)) { global $rsMax,$maxprodid,$maxqty,$chekqty; $maxprodid = 'inkjet001';//SET YOUR PRODUCT ID HERE (Must be in quotes) $maxqty = 3; //SET YOUR MAX QUANTITY HERE (No quotes) ?> <script> function maxFunction (maxqty,maxid) { alert ('WARNING Checkout disabled\nThe item '+maxid+' has a max allowable purchase of '+maxqty+' units.\nPlease adjust the quantity in your cart to no more than '+maxqty+'.'); if (document.getElementsByClassName("checkoutbutton1")[0]) {document.getElementsByClassName("checkoutbutton1")[0].style.display = "none";} if (document.getElementsByClassName("checkoutbutton1")[1]) {document.getElementsByClassName("checkoutbutton1")[1].style.display = "none";} if (document.getElementsByClassName("checkoutbutton1")[2]) {document.getElementsByClassName("checkoutbutton1")[2].style.display = "none";} if (document.getElementsByClassName("checkoutbutton1")[3]) {document.getElementsByClassName("checkoutbutton1")[3].style.display = "none";} if (document.getElementsByClassName("checkoutbutton1")[4]) {document.getElementsByClassName("checkoutbutton1")[4].style.display = "none";} if (document.getElementsByClassName("cartcheckoutbuttons")[0]) {document.getElementsByClassName("cartcheckoutbuttons")[0].style.display = "none";} } </script> <?php $sSQLmax="SELECT cartProdID,cartQuantity FROM cart WHERE cartCompleted = 0 AND cartSessionID='" . escape_string($thesessionid) . "'"; $resultmax=ect_query($sSQLmax) or ect_error(); if(ect_num_rows($resultmax)>0){ while($rsMax=ect_fetch_assoc($resultmax)){ if ($rsMax['cartProdID']== $maxprodid) { $chekqty = $rsMax['cartQuantity']; if ($chekqty > $maxqty) { ?> <script> window.onload = function() { maxFunction(<?php print $maxqty ?>,<?php print "'$maxprodid'" ?>); }; </script> <?php }}}}} ect_free_result($resultmax); //END SET MAX PURCHASE QUANTITY ?>
Edited by - dbdave on 02/01/2021 22:21:49
|
|
|