Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to return order custom field data in AJAX response #1002

Closed
elivz opened this issue Sep 11, 2019 · 6 comments
Closed

Option to return order custom field data in AJAX response #1002

elivz opened this issue Sep 11, 2019 · 6 comments
Labels
💡 enhancement Ideas and suggestions
Milestone

Comments

@elivz
Copy link

elivz commented Sep 11, 2019

Description

Currently, the JSON representation of a cart (either in the response to an AJAX call or via craft.commerce.orders.cartArray(craft.commerce.carts.cart) does not include any Order Fields that have been set up. I assume this is for performance reasons, but there are a lot of cases where one might want/need that data. For example, I am creating an AJAX-powered cart, and need to be able to retrieve and save custom field data. Saving works fine (via the commerce/cart/update-cart action, but there appears to be no way to get that data back out, short of creating a custom endpoint. Am I missing something?

If you prefer not to include that data by default, maybe you could add an event to modify the cart data, similar to how we can use EVENT_AFTER_CAPTURE_PRODUCT_SNAPSHOT to add data to the line item snapshot?

@bossanova808
Copy link
Contributor

bossanova808 commented Sep 16, 2019

For context, you might want to read the various recent issues on this:
https://github.com/craftcms/commerce/issues?utf8=%E2%9C%93&q=is%3Aissue+snapshot+data

And this is, I think, the event you can use to force particular custom fields to be added:
https://docs.craftcms.com/commerce/api/v2/craft-commerce-events-customizeproductsnapshotfieldsevent.html#public-properties

@elivz
Copy link
Author

elivz commented Sep 16, 2019

I believe those links only apply to retrieving product custom fields. What I am looking for is a similar system to include order custom field data in the AJAX response.

@bossanova808
Copy link
Contributor

Right you are! Silly me, read that too quickly, sorry for the noise.

A similar approach would make sense here...

@lukeholder lukeholder added 3.0-alpha 💡 enhancement Ideas and suggestions labels Sep 18, 2019
@lukeholder lukeholder added this to the 3.0 milestone Sep 24, 2019
@britteninc
Copy link

Hey @elivz , I found this issue and I have a similar use case. I am wondering how you structured your ajax post call to get it to return custom order field data?

@elivz
Copy link
Author

elivz commented Jun 9, 2020

I didn't. Looks like @lukeholder added a new EVENT_MODIFY_CART_INFO event for the purpose in Commerce 3, but the project I needed this for is still on v2, so I haven't had a chance to play around with it yet.

@britteninc
Copy link

Ok great. No problem. I figured out another solution in the meantime. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💡 enhancement Ideas and suggestions
Projects
None yet
Development

No branches or pull requests

3 participants