Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
This is technically not our bug, but let's track it.
The billing profile is referenced using an entity_reference_revisions field.
Views integration is broken for base fields of custom field types, so there's no way to add a billing profile relationship from an order view. This needs to be fixed in core: #2337515: Allow @FieldType to customize views data.
Comment | File | Size | Author |
---|---|---|---|
#17 | 2819603-17-Order-profile-relationships.patch | 1.53 KB | aleix |
Issue fork commerce-2819603
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
mike.vindicate CreditAttribution: mike.vindicate commentedI needed to retrieve the correct address information to search on in a view.
As a workaround I used hook_views_query_alter.
For this to work add the following relations to the view via the interface:
User
User -> Profile
Probably can be done cleaner/better, but this worked for me.
Comment #3
kamkejj CreditAttribution: kamkejj as a volunteer commentedThanks mike.stijlloos, this fix came at just the right time and is working for us.
Comment #4
SpleshkaThanks, #2 works for us as well. It really came just 1h ahead of me searching for the solution :)
Comment #5
vasikeThis is actually an "Entity Reference Revisions" issue
#2799479-34: Views doesn't recognize relationship to host
I updated the previous patch to include the relationship for base fields - the commerce profile fields case.
So please follow the related issue and maybe you could help having a solution here (and there).
Comment #6
maxplus CreditAttribution: maxplus commentedHi vasike,
thanks your patch https://www.drupal.org/node/2799479#comment-12080741 solved this issue for me.
Now I can add the billing profile relation to my view and access all separate billing profile fields in my view fields.
Great!
Comment #7
Dave KopecekUpdate to #6
I was able to create a views relationship from order to profile and add anonymous customer profiles address fields using patch #91 2799479-91-DO_NOT_COMMIT.patch found here:
https://www.drupal.org/project/entity_reference_revisions/issues/2799479...
Patch committed against:
core 8.8.1
entity_reference_revisions 8.x-1.7
Patches #108 did NOT work and caused Broken/Missing handlers and broke several views.
Comment #8
Artem Rudnitskiy CreditAttribution: Artem Rudnitskiy as a volunteer commentedI was creating views for advanced order search , where I needed to add filters by billing and shipping profile.
I used hook_views_data_alter and add relationship between the billing profile and order (Order->Billing Profile) and shipping profile with shipment (Order->Shipment->Shipping Profile (need to use aggregation)). For me it work perfect.
Here is my code:
Comment #9
lunk rat CreditAttribution: lunk rat commented@Warlord Rudy your hook in #8 works great. Thank you!
Comment #10
cobenash#8 works great. Thanks!
Comment #11
markdcCan you please explain where I put this code? (I'm not a developer.) How do I connect this code to my custom view? Thanks!
Comment #12
lunk rat CreditAttribution: lunk rat commented@markdc the code in #8 goes into a custom module. You need to create a custom module and paste the code for the hook in your module's
.module
file. It might seem daunting but it's worthwhile to keep at it until you are comfortable with the general principles of hooks.You might check out a tutorial, e.g., an explanation of hooks:
https://drupalize.me/tutorial/what-are-hooks?p=2766
And an overview of creating custom modules:
https://drupalize.me/tutorial/create-info-file-module?p=2766
Comment #13
hockey2112 CreditAttribution: hockey2112 commented#8 worked great, thanks!
Comment #14
khaldoon_masud CreditAttribution: khaldoon_masud as a volunteer commented#8 worked like a charm. Should be included in the contrib module.
Comment #15
a.dmitriiev CreditAttribution: a.dmitriiev at 1xINTERNET commentedCode in #8 worked for me too! Thanks! And yes, maybe it is time to add it to contrib module? But one part in commerce module and another in commerce shipment one. @Artem Rudnitskiy maybe you can create an MR or provide a patch?
Comment #17
aleix CreditAttribution: aleix at Communia commentedIt works for me too. Adding #8 as MR to order submodule, and patch for composer purposes.
Comment #20
jsacksick CreditAttribution: jsacksick at Centarro commentedCommitted, thanks everyone!
Comment #23
jsacksick CreditAttribution: jsacksick at Centarro commentedJust FYI... Moved the commerce_shipment part to commerce_shipping as I don't think this belongs to commerce core. Unfortunately realized that right after tagging a commerce_shipping release, so it'll go into the next commerce_shipping release.
Comment #24
hockey2112 CreditAttribution: hockey2112 commentedI am trying to use the custom module in #8 to allow my list of orders to be searchable based on the first or last name of the billing or shipping profile, but I am not seeing any way to add such a filter in my View. Can someone please direct me on where I can add that?