gjkathome Posted February 3, 2023 Share Posted February 3, 2023 (edited) I am using CubeCart to collect reservations for a meal. Customers can choose starters (£7), mains (£16) and desserts (£7). The venue requires that the minimum order is a main course + one other. Currently I have set the product price to zero and the option prices to £7 or £16 as appropriate. The mains options are required, starter and dessert options are not. That gets the pricing right but doesn't enforce the minimum order rule. Is there any way I can fix this? Many thanks Graham Edited February 3, 2023 by gjkathome Quote Link to comment Share on other sites More sharing options...
bsmither Posted February 4, 2023 Share Posted February 4, 2023 This will require an enhancement to the skin's javascript, as well as writing an enforcement test in the core code. I did something very much like this in CC3. This will be an interesting project for CC6, but no guarantees. Quote Link to comment Share on other sites More sharing options...
bsmither Posted February 7, 2023 Share Posted February 7, 2023 Here is test code to show how Foundation's feature to "validate" form entry data can be used to solve this situation. It is meant to be a separate page request (like, www.store.com/validate.html), but loads two files from the Foundation skin. (So, be sure to have the Foundation skin in CubeCart's /skins/ folder.) The essential part, the "#test" validate object, would be incorporated in the overall collection of validate objects (located in Foundation's javascript file "3.cubecart.validate.js"). <!DOCTYPE html> <html> <head> <script src="skins/foundation/js/vendor/jquery.js"></script> </head> <body> <form id="test"> <select name="main" id="main"> <option value="">Select</option> <option value="Steak">Steak</option> <option value="Chicken">Chicken</option> <option value="Fish">Fish</option> <option value="Tofu">Tofu</option> </select> <select name="entry" id="entry"> <option value="">Select</option> <option value="Cheese">Cheese</option> <option value="Wings">Wings</option> <option value="Rings">Rings</option> <option value="Chili">Chili</option> </select> <select name="dessert" id="dessert"> <option value="">Select</option> <option value="Cake">Cake</option> <option value="Pie">Pie</option> <option value="Sorbet">Sorbet</option> <option value="CheeseCake">CheeseCake</option> </select> <br><input id="submit" type="submit" value="Submit" /> </form> <script src="skins/foundation/js/vendor/jquery.validate.js"></script> <script>function init_add_to_basket(){return false}</script> <script> jQuery(document).ready(function() { $.validator.setDefaults({ errorElement: 'small', errorPlacement: function(error, element) { if (element.attr("name")=="entry" || element.attr("name")=="dessert") { error.insertAfter("#dessert"); } else if (element.is(":radio") || element.is(":checkbox")) { var errorLocation = element.attr('rel'); if ($('#' + errorLocation).length) { error.insertAfter('#' + errorLocation); } else { element.removeClass("error"); alert(error.text()); } } else { error.insertAfter(element); } } }); $("#test").validate({ rules: { main: { required:true }, entry: { required:{depends:function(e){return $("#main option:selected").val().length>0 && $("#dessert option:selected").val().length==0;}} }, dessert:{ required:{depends:function(e){return $("#main option:selected").val().length>0 && $("#entry option:selected").val().length==0;}} } }, groups: { withName: "entry dessert" }, messages: { main: { required: "You must choose a main dish." }, entry: { required: "You must choose either an entry or a dessert, or one of both." }, dessert: { required: "You must choose either an entry or a dessert, or one of both." } }, }); /* Reset Form */ $('input:reset').click(function() { $(this).parents('form:first').validate().resetForm(); }); }); </script> </body> </html> Quote Link to comment Share on other sites More sharing options...
gjkathome Posted February 8, 2023 Author Share Posted February 8, 2023 Many thanks. I will try it. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.