Custom Shipping Endpoint, get customer email

Hey guys,

We have a free product offer we're working on. I came up with the idea of trying to prevent abuse by using the custom shipping endpoint to hit our server where I'd like to do the following:

1. check for the free product in the cart (done)
2. grab customer details (can't find their email in the cart_details array)
3. grab customer's orders via the API (I can do that)
4. check if they've already purchased this free product. If so, remove this new one from the cart.

Does that logic sound decent to you? Is there a smarter way I can do this? Or, how can I grab the customer details along with the cart details in the custom shipping endpoint?

Thanks as always!

-Jacob

Comments
  • fc_adamfc_adam FoxyCart Team
    @jacobdubail,

    Interesting approach. As long as the store is shipping with live rates, that could work - although it might make the shipping rate request a bit lengthy. For receiving the customer email - we recently added in custom fields support for the custom shipping endpoint. You can see details on that here: https://wiki.foxycart.com/v/2.0/shipping#custom_shipping_endpoint - the javascript approach detailed would probably work best for you here.

    As an alternative approach - you could do a custom ajax request after the customer has entered their email. The endpoint you hit will need to be secured with HTTPS, but that request could happen in the background.
  • Thanks @fc_adam! Your approach is much better. Just got that working.

    Last piece that I can't figure out is adding/displaying errors in the cart once an item is removed. I'd like to add a custom message of some kind, but using FC.util.addError('cart', 'message'); doesn't work. Mind pointing me in the right direction?

    Thanks,
    Jacob
  • fc_adamfc_adam FoxyCart Team
    @jacobdubail,

    Good question - you'll need to trigger a re-render to have the new error message display, like FC.checkout.render(); - that should then display your new error.
Sign In or Register to comment.