- 🇻🇳Vietnam cp19112000
I suggest using a different flag to handle custom logic instead of using copy_to_address_book (s.t like owner_presave_event_dispatched)
You can set owner_presave_event_dispatched to TRUE before adding a profile and then patch into the code "Make sure the billing profile is owned by the order, not the customer"
In my case, I customized some events in ProfileOwnerEvents to ensure the duplicated profile keeps owner_presave_event_dispatched TRUE and the owner is the customer. I don't want to use copy_to_address_book because the duplicated profile set copy_to_address_book to FALSE and set address_book_profile_id to the old profile, which made relationships between two profilesif ($billing_profile->getData('owner_presave_event_dispatched')) { $event = new ProfileOwnerEvent($billing_profile); $event_dispatcher = \Drupal::service('event_dispatcher'); $event_dispatcher->dispatch($event, ProfileOwnerEvents::PROFILE_OWNER_PRESAVE); $billing_profile = $event->getProfile(); $this->setData('owner_presave_event_dispatched', FALSE); }