The Foxy forums are on the move!

We're in the process of moving our forums over to a new system, and so these forums are now read-only.
If you have a question about your store in the meantime, please don't hesitate to reach out to us via email.

Is there a way to set the min quantity in cart for a category?

flinx777flinx777 Member
in Bugs & Feature Requests edited January 2012
I'm building a Foxy Cart (using version 071) setup for a client where he wants to require a minimum quantity of products in a category. I've been able to build the jQuery to require the minimum before being able to add to cart no problem. It's a situation where they're doing a mix-and-match wholesale page that requires a min of 100 products before being able to add them to the cart. Not a problem so far. But once they've add all the products into the cart, I need a way to require they keep at least a minimum number in the cart or they'll get an error message stating they didn't meet the minimum requirement. So if for example they added 5 different products adding up to at least 100 and they deleted one of the products from the cart bringing them under the min of 100, they can't checkout.

I came across this thread but it's coding to set the minimum total products in the cart (and doesn't seem to be category specific):

http://forum.foxycart.com/discussion/4949/what-is-the-best-way-to-validate-minimum-quantity-per-type-of-product/p1

The problem in this situation is that on the site we have product sections where a minimum is not required and the link to the above code allows you to set a minimum for the cart for all products (which would be a problem if the customer went somewhere else on the site and wanted to add just 1 product to cart where a min is not required).

Is there anyway to write a statement to put in the cart saying that if the total number of products that are part of category "Wholesale" is not 100, they can not check out?

I came across this too:

http://wiki.foxycart.com/v/0.6.0/faqs#set_a_maximum_or_minimum_quantity_on_the_cart_or_order

After reading this last posting, I attempted to write a little of my own code that didn't seem to work. Here it is:


<script type="text/javascript" charset="utf-8">
/* <![CDATA[ */
function cart_quantity_check() {
// remove checkout capability if wholesale category products are less than 100
if (fc_json.product_count < 100 && fc_json.category == "wholesale") {
fc_HideCheckout();
// Display a notification message
$j("span.fc_cart_notice").html("Please order 100 wholesale products or more.");
}
}
$j(document).ready(function(){
// The setTimeout gets around a Thickbox issue.
setTimeout("cart_quantity_check()", 0);
});
/* ]]> */
</script>


Thanks!
Tagged:
Comments
  • flinx777flinx777 Member
    edited January 2012
    Just updated the code and got it working. Here's the solution here if anyone needs it down the road:


    <style type="text/css">
    .display_none {
    display: none !important;
    }
    span.fc_cart_notice {
    color: red;
    font-weight: bold;
    left: 210px;
    position: absolute;
    top: 18px;
    }
    </style>
    <script type="text/javascript" charset="utf-8">
    /* <![CDATA[ */
    // Get the total quantity of products that have the category "wholesale" and add them together
    var wholesale_count = 0;
    for (i=0; i< fc_json.products.length; i++) {
    if (fc_json.products[i].category == "wholesale") {
    wholesale_count += fc_json.products[i].quantity;
    }
    }
    // Used for Firefox console function to debug (you can safely remove this line of code)
    // console.info(wholesale_count); (you can safely remove this line of code)

    // function to check the wholesale products to determine if they add up to the required amount
    function cart_quantity_check() {
    // loop through all the products in the cart
    for (i = 0; i< fc_json.products.length; i++)
    // Used for Firefox console function to debug (you can safely remove this line of code)
    // {console.info(fc_json.products[i].quantity);} (you can safely remove this line of code)
    {
    // remove checkout capability if "wholesale" category products are less than 100
    if (wholesale_count < 100 && fc_json.products[i].category == "wholesale") {
    // Remove the checkout button from the cart by adding CSS to the button to hide it
    $(".fc_cart_checkout").addClass("display_none");
    // Display a notification message by appending the following message
    $("#fc_cart_form").append("<span class='fc_cart_notice'>To receive the wholesale discount, <br /> please order 100 wholesale products or more.</span>");
    }
    }
    }
    $(document).ready(function(){
    // The setTimeout gets around a Thickbox issue.
    setTimeout("cart_quantity_check()", 0);
    });
    /* ]]> */
    </script>
  • lukeluke FoxyCart Team
    Thanks @flinx777! Glad you got it working.
  • Thanks to @brett for the help!
Sign In or Register to comment.