Get the name of an item being removed from the cart?

mwkdesignmwkdesign Member
in General edited February 2016
Suppose I want to warn customers when they remove certain items from their cart.

Our store sells highly configurable electronics. For example, if they get a cellular base station, then, they need to also buy a wireless plan. Otherwise the merchant will be getting an angry call from a frustrated customer.

So I'd like to warn a customer when they try to remove certain items from their cart.

So I tried this code from your cheatsheet:


FC.client.on("cart-item-remove", function (params) {
if (params.itemPrice == 0) {
alert("You cannot remove free products from your cart");
return false;
}
});


But I don't understand how `params` really works. It seems to just be an ID.

Is there a way I can use something like the code above to get the actual name or category of the item being removed?
Tagged:
Comments
  • fc_adamfc_adam FoxyCart Team
    @mwkdesign,

    Perhaps a better approach here would be to bundle the required products with the products they're tied to. So if someone purchases a base station - it comes bundled with the wireless plan product - and they can't remove the plan without also removing the base station. Would that work? You can see information on setting up product bundles at https://wiki.foxycart.com/v/2.0/products#product_grouping_bundling_ensembles
  • mwkdesignmwkdesign Member
    edited February 2016
    Wow, that is interesting! I had been using the "price_2" convention to add everything at once, but that creates no relationship between the items. And I see bundling even works when the parent is a one-time charge and the child is a subscription. That's really cool! So-- What if they want several base stations? In my situation, I only want to sell them a single wireless plan which would cover them all. Can the quantities differ between parent/child items?
  • fc_jedfc_jed FoxyCart Team
    @mwkdesign

    Certainly! Even though the existence of the child products depend on the parent product, the quantity is independent of each other. You can set a different quantity and other parameters for child products. The key thing is to have the parent_code equal to the code of the parent product.
  • Sweet. Bundling works great. Thank you!

    Just for my own edification, if I ever would want to throw up a prompt when a customer removes a certain item — Is there some version of that code above which could extract details about the item being removed? Is that even possible?
  • fc_adamfc_adam FoxyCart Team
    @mwkdesign,

    I haven't tested to confirm - but prior to deletion you should be able to get the product details from the JSON object, based on the ID of the product being deleted.
Sign In or Register to comment.