Using the endpoint /jsonapi/carts I can see the "address" but not custom fields such as "field_phone" etc
"billing_information": {
"address": {
"country_code": "IT",
"locality": "Como",
"postal_code": "22100",
"organization": "My Company",
...
}
}
Indeed, the order_profile computed field workaround is considering only fields of type "address" and "commerce_tax_number", see https://git.drupalcode.org/project/commerce_api/-/blob/8.x-1.x/src/Plugi...
I guess we need a patch to handle more field types.
| Comment | File | Size | Author |
|---|---|---|---|
| #25 | 3145942-25.patch | 10.1 KB | jsacksick |
| #24 | 3145942-24.patch | 9.46 KB | jsacksick |
| #22 | 3145942-22.patch | 9.46 KB | jsacksick |
| #18 | Screen Shot 2022-01-03 at 11.35.16 AM.png | 112.2 KB | mglaman |
| #16 | commerce_api-custom-profile-fields-not-included-in-order_profile-field-3145942-15.patch | 1.43 KB | katerwater |
Issue fork commerce_api-3145942
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
mglamanWhat we'll need to do, is add another elseif
If it's a `telephone` field, we can borrow this from the actual field definition:
If it's a string field, same difference.
Comment #3
p4trizio commentedI worked on a patch, I hope it's going in the right direction
Comment #4
mglaman👍looks right, but patches generated by Intellij fail to apply, I can work on the tests. But applying this to your project should unblock you
Comment #5
p4trizio commentedComment #6
p4trizio commentedJust realized also email field types are missing.
The following patch allows use of email field type and the special TypedData Map for the "data" field
Comment #7
p4trizio commentedAllowed fields alphabetically sorted
Comment #8
mglamanThanks @p4trizio. I wonder if there is a way to make this "smart", so we don't need a defined allowed list. On one hand, it makes it testable and guaranteed. On the other hand, it makes it a pain with unexpected results. Early on I didn't have time to find a pattern for "perfection." But some of these simpler field types might make it easier. Phone, Email, String all have the same data definition.
Comment #9
giuseppe87 commentedHi,
I don't know if this is relatable to this issue or worthy of a stand-alone: there is discrepancy between the billing\shipping information returned by commerce_api - "/jsonapi/carts" - and the profiles returned by json_api - "/jsonapi/profile/customer".
The first gives e.g. for billing profile:
While the latter gives:
Aka: commerce_api gives the value of the "extra" fields of the profile as object, while json_api as string.
What's more, commerce_api logically requires an object as value of the "extra-field" to patch the billing\shipping profiles and crashes with a simple string.
Considering that it may be necessary to access to both resources, this requires boilerplate code to adapt those two different "format".
I wonder if it could be possible - and sensible - to make commerce_api return the values as json_api does.
Comment #10
p4trizio commentedThanks @Giuseppe87
attached a patch that in my opinion simplifies things a little bit, hope it works
Comment #11
mglamanComment #12
Marko B commentedI was working on the same thing, but I did full datatype thing for telephone. Where you end up with
$data_definition = PhoneNumberDataDefinition::create('phone_number')->setLabel(t('Telephone number'));but seems Patrizio solution also works, so probably extra abstraction I added is obsolete.
Comment #13
jsacksick commentedI'd privilege the approach from #10, although It could use some refactoring. Regarding the patch from #12, there's no reason to define a new datatype.
Comment #14
katerwater commentedI confirm #10 works, but in my case I have a custom boolean field, which is missing in the list.
Comment #15
katerwater commentedAdded boolean field, based on #10
Comment #16
katerwater commentedPrevious one didn't work.
Comment #17
mglamanFrom #10, it seems like we're just missing having the
elsereturn the field item definition. Compound fields are the tricky ones which require serialization. Or maybe I was just around all around and we could have just usedgetItemDefinition.Comment #18
mglamanNevermind. One of the reasons was to prevent displaying all of the fields.
Comment #20
mglamanI tossed up a new idea in https://git.drupalcode.org/project/commerce_api/-/merge_requests/10. This excludes entity keys. It doesn't exclude all base fields as someone may implement a base field. And I don't like explicitly just checking FieldConfig.
Comment #21
jsacksick commentedI guess something is wrong with the code from the MR.
I applied the patch, and I have a field called "field_mobile" which is supposed to contain data, and currently returns NULL.
Oh... I think this is due to OrderProfileItemList.php that wasn't updated. :)
Comment #22
jsacksick commentedComment #24
jsacksick commentedComment #25
jsacksick commentedComment #27
jsacksick commentedWent ahead and committed the patch.