Javascript and hmac - Prevent a product from being added to the cart

loopedlooped Member
I am attempting to use the following example from your Javascript documentation:
FC.client.on('cart-submit', function(params, next){
var product1_exists = false;
if(!jQuery.isEmptyObject(FC.json.items)) {
jQuery.each(FC.json.items, function(i, item){
if(item.category == "Product1") {
product1_exists = true;
if( == "Product2" && product1_exists) {
else {
The script was not working so I checked the value by doing alert( The response was 'undefined' .
This is also the case for and
With alert(JSON.stringify( I get the following results for my product:

Does this mean that using the javascript cannot return the values when the hmac product validation is being used ?
Or is there something else obvious that I am missing?
  • fc_adamfc_adam FoxyCart Team

    Ah - that would cause issues for that snippet. As the params is the data that has come from the form, that means it'll include the hash too if it's there.

    You can still make it work - but you just need to take a slightly different approach. Something like this should work - put it at the start of the function, and then check against the category variable in the rest of the snippet:

    var category = "";
    for (var name in {
    if (name.indexOf("category") == 0) {
    category =[name];
    What it does is loops through all the variables in and checks if the attribute starts with "category". If it does, it gets the value and saves it into the new variable.
  • loopedlooped Member
    Thank you very much for providing a clear explanation and solution to my issue.
    It is working well now.
Sign In or Register to comment.