[solved] minimum price for a gift certificate

sunsurfsunsurf Member
in Help edited November 2012
Hello Team Foxycart,

I am doing some updates on a foxycart 0.7.2 shop.

We're just starting to sell gift certificates to customers and letting the customer manually enter the amount on the page using this code in the form: $<input type="text" name="price" value="" />

How do I set a minimum price of $55?

Thanks in advance.
Comments
  • fc_adamfc_adam FoxyCart Team
    @sunsurf,

    You'd have to add some javascript to your page that performs an action if that field is less than $55 - either alerting the user, pushing that text input value up to $55, both of those or something else entirely.
  • Hi Adam,

    Ah ok, I thought there would have been some quick foxy trick with a hidden form field.

    Are you able to help with the code as I am a javascript dunce?

    For this instance I would like an error message at the top of the cart - like the code you wrote for me to make sure that a customer has to order one of the products with a particular category code.

    And not let the cart proceed to checkout:
    without making a price $55 or greater for the certificate
    or removing it totally from the cart

    I will whisper the code to that js file and store for your info.

    Thanks Adam.
  • fc_adamfc_adam FoxyCart Team
    edited November 2012
    @sunsurf,

    Something like this should do it - it'll actually prevent the add to cart from happening at all, so they won't even get to the cart. You'll need to paste this on the page where you have the voucher form, and make sure it's included after the normal foxycart includes:
    <script type="text/javascript">
    jQuery(document).ready(function() {
    	fcc.events.cart.preprocess.add(function(e, arr) {
    		if (jQuery(e).find("input.minimum[name^='price']").length == 1) {
    			var price = jQuery(e).find("input.minimum[name^='price']:first");
    			if (price.val() < 55) {
    				alert("This product needs to be a minimum of $55. Please modify the product and try again");
    				return false;
    			}
    		}
    	});
    });
    </script>
    

    Also, you'll need to give a class to the price input that you want to be kept to a minimum amount, with a class of 'minimum'.
  • GENIUS!!!

    Thank you so much Adam - that is brilliant!

    Absolutely love your work.

    That works perfectly.

    Cheers mate.
  • Hey Adam,

    I am toying with having the error alert inline, next to the text field (.cart span.error) - to be consistent with the style of errors / reminders on the checkout page.

    This code seems to be working but thought I should check if that is the correct way to do it .

    Essentially, to show the error message span only when the price is too low.
    jQuery(document).ready(function() {
    	fcc.events.cart.preprocess.add(function(e, arr) {
    		if (jQuery(e).find("input.minimum[name^='price']").length == 1) {
    			var price = jQuery(e).find("input.minimum[name^='price']:first");
                            $('.cart span.error').removeClass('active')
     			if (price.val() < 55) {
                                     $('.cart span.error').addClass('active')				
                                     return false;
    			}
    		}
    	});
    });
    

    Do those 2 little tweaks pass the Adam test?


  • fc_adamfc_adam FoxyCart Team
    @sunsurf,

    It looks fine - as long as it acts like it should in the browser you're all good :)

    Actually - I'd move this line
    $('.cart span.error').removeClass('active')
    

    To be right after this line:
    fcc.events.cart.preprocess.add(function(e, arr) {
    
  • Brilliant, thanks Adam.
    line moved and working.
    Thanks again
Sign In or Register to comment.