Blocking specific sku won't added in cart or checout

We pass the product added in cart using url

Foe ex : https://cart.domain.com/cart?name=productname&price=3.99&code=ABC1&weight=1.25&quantity=1

How to block ABC1 product that not added in cart or redirect to my site home page..

Please give any suggestions..

Thanks,
Clickhere2shop
Comments
  • brettbrett FoxyCart Team
    Hi @clickhere2shop. Are you wanting a specific product to simply never be added to the cart?

    You could approach that in a few ways, either blocking the cart at the template level or with a quick bit of javascript. You could add a bit of js to the template config header or footer to loop through the FC.json.items, find the offending product, remove it, and redirect. Would that make sense? If you need help figuring that out, let us know.

    To avoid this in the future, though, you could look at using the `expires` parameter:
    https://wiki.foxycart.com/v/2.0/cheat_sheet
    That'll ensure none of your cart links last longer than you might intend.
  • We tried passing JS like FC.json.items it did not work, Do you have a sample script that I can use. Please Suggest
  • fc_adamfc_adam FoxyCart Team
    @clickhere2shop,

    The JSON object you can access from your FoxyCart store is read-only, sorry for the confusion there - you won't be able to make direct edits of the object.

    Instead what you'll want to do is make a JSONP request to the cart to update a product quantity. You can see details on that at http://wiki.foxycart.com/static/redirect/jsonp - and as an example:
    var product_id = 0;
    for (var i = 0; i < FC.json.items.length; i++) {
    if (FC.json.items[i].code == "ABC1") {
    product_id = FC.json.items[i].id;
    }
    }

    if (product_id > 0) {
    FC.client.request('https://' + FC.settings.storedomain + '/cart?cart=update&quantity=0&id=' + product_id).done(function(dataJSON) {
    FC[FC.json.context].render();
    });
    }
    The above code will loop through the cart, trying to find one with a code of "ABC1". If it finds one, it then removes that from the cart and re-renders the page. You'll probably just want to do that on page load - so you can make use of our events to run in when the page is ready:
    FC.client.on("ready.done", function() {
    // Include code here
    });
Sign In or Register to comment.