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.

Feedback after add to cart (for specific product, not complete cart)

RolfRolf Member
in Help edited October 2012
In my application I need to talk to the PHP backend after a product has been added to the cart. Maybe the product will be added to a backup-database-cart as well, or in any case generate a correct response message for the customer that perhaps includes some special offer values depending on the product.

I'm using JSONP to send an add to cart request to FoxyCart using a HMAC form. As far as I can tell there is no response that specifically tells me what product I just added, correct? I have the form data (I sent to FC server), so should I trust that it is the same? How do I know that the add to cart was successful .. should I check the JSON response messages.errors for specific things before "assuming" that everything was OK?

I mean, I don't want to give incorrect feedback to the customer telling them that it all went OK etc. when it actually went wrong, or when the product added to the cart in the end isn't 100% the stuff that was sent in the first place (for whatever reason).

Or maybe this is some stuff that is never going to happen anyway? ;)

Cheers,
Rolf


PS > I will also use the postprocess event to do stuff with the entire cart (like update a mini cart or store it in the db as backup), but then I use the current (local) FC.json object fetched after cart_update. But that is after the fact..
Comments
  • brettbrett FoxyCart Team
    @Rolf, those are some really great questions :)
    Let us discuss privately for a moment and we'll get back to you.
  • lukeluke FoxyCart Team
    Hey @Rolf. We're still asking questions and working things out with this behind the scenes, but one idea you may be able to run with is to compare the cart json prior to the cart activity and then after it (using the preprocess and postprocess hooks) and using that to decide how the contents of the cart changed.

    We're also thinking through whether a cart activity with a name but no price should throw an error or add a $0 product.
  • @luke, @brett, thanks for giving it a thought. I was actually planning the "compare json pre and post" idea as a first implementation.

    I thought about asking you to just add another property to the json response with the contents of what was received on your end (and then processed), so that we (FC users) can (if you want) compare that to what we have sent over in the first place. It's like saying: "this is what we got from you and this got added to the cart, it's up to you to compare it to whatever..."

    Comparing the json prior and post and then use the "difference" to compare it to what I think it should be (using the original form data for example) is about the same thing.

    No price products
    Sending over products with no price should throw an error. If it is a free product then I can specify a value of 0 for the price and that value is hashed to prevent hacking. If someone would hack the form and remove the price entirely it could be seen as a $0 product which might be not the case.

    Or, maybe, in HMAC signed form data (or string) you could require one additional value that tells FC what fields to expect. Like the user is telling the FC server to expect name/price/description and if I'm then sending over 5 other fields then you should not trust it. Or, maybe this is too much ;)

    Error in response
    Overall I'm not seeing messages.error in use in the documentation, but it does exist in the fc.json object, so I wondered when this was used by FC.


  • fc_adamfc_adam FoxyCart Team
    @Rolf,
    Overall I'm not seeing messages.error in use in the documentation, but it does exist in the fc.json object, so I wondered when this was used by FC.

    The messages node will include any messages that would have been displayed in the cart - so errors of maximum/minimum quantity, missing required parameters (title) or malformed values. If nothing is in these nodes then the add to cart should have been successful, but that's not the best way to tell either.

    Thanks for your additional thoughts, we'll continue to discuss this amongst the team
  • brettbrett FoxyCart Team
    Hi @Rolf.
    Good points. I've asked Adam to confirm the specifics (running out to trick or treat), but removing the price won't add a product at $0. Rather, it won't add the product at all. We did this way back when so you could set the "price" input as a checkbox, and if the checkbox wasn't checked, the product wouldn't be added. (Where the name and other options are hidden or other inputs.) If you've got a main product and some add-ons, or a giant order form with tons of products as checkboxes, this approach can make sense.

    As far as the link/form signing, we have thought about another value that'd include required fields, but often products have optional or dynamic options. It starts to unravel a little. On the documentation we do recommend keeping in mind that product options _can_ be removed, so if you have options that modify the price we recommend setting the base price high, then modifying the price down as needed (with price-modifying options). We're the only system (as far as we're aware) that takes as advanced an approach as we have, while still allowing the flexibility we do. But there are some caveats and things to be aware of.

    I'll let @luke and @fc_adam respond to the other bits :)
    Happy halloween.
  • @brett,
    The $0/checkbox thing makes sense yes. I don't see a reason to change it.

    The flexibility to add "configurable" products to the cart was the reason I started to mess with FC in the first place ;) - in the end (in this case) I setup a product completely before sending it to the cart and there are no additional modifiers. I'm just thinking about the need/wish to verify the cart after adding a product. Not so mucht to prevent fraud, but more because I show a message to the customer like "we just added X with options Y and Z to your cart, oh and btw- because you did that, here's a promo..." This message is constructed with the data sent to FC, so before showing it to the customer I do want to verify that the thing I say is actually in the cart :)

    For the moment I will just compare the previous with the new cart (fc.json), no biggie.

    PS > again, it could be I'm just overly verifying stuff, on other sites/shops I also do not double check the cart after stuff was put in all the time, so not sure why I want to now, maybe because it's pushed to some other server
Sign In or Register to comment.