WPCV / wpcv-woo-civi-integration

A WordPress plugin that creates CiviCRM Contributions, Memberships and Participants from WordCommerce Orders and keeps WordCommerce Customer Accounts in sync with CiviCRM Contact data.
GNU Affero General Public License v3.0
4 stars 8 forks source link

Error generated when saving an address in WooCommerce #46

Closed pixel-paul closed 1 year ago

pixel-paul commented 1 year ago
Software Version
CiviCRM 5.62.1
WC 7.8.1
PHP 8.2
WP 6.2.2

An error is thrown when saving an address in WooCommerce (/my-account/edit-address/billing/):

Uncaught TypeError: call_user_func_array(): Argument #1 ($callback) must be a valid callback, class WPCV_Woo_Civi_Contact_Email does not have a method "sync_wp_user_woocommerce_email"

Linked to a missing method, sync_wp_user_woocommerce_email in /wpcv-woo-civi-integration-main/includes/classes/class-woo-civi-contact-email.php :

// Sync WooCommerce and CiviCRM email for User/Contact.
add_action( 'woocommerce_customer_save_address', [ $this, 'sync_wp_user_woocommerce_email' ], 10, 2 );
christianwach commented 1 year ago

@pixel-paul Thanks for the report. I'll post a fix shortly.

pixel-paul commented 1 year ago

Thanks @christianwach. A similar error is also generated in the WPCV_Woo_Civi_Contact_Phone class for sync_wp_user_woocommerce_phone

christianwach commented 1 year ago

@pixel-paul I can fix the acton callbacks very easily, however this is code that was largely inherited from the previous plugin... and so when I do fix the callbacks on my dev sites I find a whole heap of problems with the sync processes.

Would you or your client be prepared to (or able to) sponsor the code fixes and testing? My email's on my profile if you want to get in touch that way.

pixel-paul commented 1 year ago

Yes, it looks like the sync_wp_user_woocommerce_email (for example) should be sync_woo_to_civicrm

I would be very doubtful that they would be able to contribute to this, however I would be able to help.

When I corrected the issue, the sync appeared (at least without too much digging) to work....

christianwach commented 1 year ago

Yes, it looks like the sync_wp_user_woocommerce_email (for example) should be sync_woo_to_civicrm

Yep, that gets the code running again. It's just it doesn't work as expected.

This is compounded by WooCommerce Contacts created via the "My Account" screen not receiving the proper Sub-type.

There could be further CiviCRM-to-Woo oddities but that's as far as I got.

pixel-paul commented 1 year ago

OK, so quite significant issues.

Has this happened because of any recent changes? It has been some time since I have looked into the profile syncing and I have just started testing this part of our installation and noticed these issues.

christianwach commented 1 year ago

Has this happened because of any recent changes?

@pixel-paul Having had a dig around, I'm not convinced this code ever worked as expected (though yes the mis-named callback issue is my mistake). I was sponsored to rebuild the previous plugin to the extent that I was able to within the budget, and Contact/Customer syncing just didn't make the cut.

pixel-paul commented 1 year ago

Ok, I'm going to start debugging this further and see what I can figure out. By the looks of things, names sync ok....

christianwach commented 1 year ago

No need @pixel-paul I have a branch that's mostly there... will push tomorrow for you to test.

pixel-paul commented 1 year ago

Hi @christianwach, that sounds great, thank you. I'll be able to test as soon as you need.

Thanks again!

christianwach commented 1 year ago

@pixel-paul Feedback on https://github.com/christianwach/wpcv-woo-civi-integration/tree/profile appreciated.

pixel-paul commented 1 year ago

Hi @christianwach - where would you like me to leave feedback / bugs?

christianwach commented 1 year ago

@pixel-paul Let's keep the discussion in one place - so here is probably best.

pixel-paul commented 1 year ago

Hi @christianwach, ok no problem.

I've tested with the profile branch of your fork and I can confirm that the addresses and email are syncing correctly now.

I have found a few bugs:

CV -> WC

  1. When saving a record in CiviCRM, an error is generated (this doesn't always happen and appears to only happen if there is no website entered):

    Could not delete Website id 50

  2. Changing Nickname in CiviCRM does not save

  3. Adding a website does not save

WC -> CV

  1. Display Name <—> Nickname sync does not work (I am assuming that this is meant to happen?)

Settings

These are my WPCV settings:

image

Many thanks,

Paul

christianwach commented 1 year ago

Could not delete Website id 50

@pixel-paul I'll need a backtrace to assess if this is a problem with this plugin or your install.

christianwach commented 1 year ago

Display Name <—> Nickname sync does not work (I am assuming that this is meant to happen?)

@pixel-paul This has not been a feature of this plugin to date - you'd need to commission additional functionality.

christianwach commented 1 year ago

Adding a website does not save

@pixel-paul There's no website as part of the Woo Customer Profile, so this is outside the scope of this plugin.

pixel-paul commented 1 year ago

@pixel-paul I'll need a backtrace to assess if this is a problem with this plugin or your install.

OK, I think you are correct in that the changes you have made are working correctly. The issue I think we are now looking at must be related to one of the other sync plugins. I'm running a clean WP 6.2.2 and these plugins:

  1. Woocommerce 7.8.1
  2. CiviCRM 5.62.1
  3. CiviCRM Profile Sync 0.6.2
  4. CiviCRM Member Sync 0.6.0
  5. CiviCRM Admin Utilities 1.0.0

When I register an account in Woocommerce, it is synced through to Civi. I can then add a billing address and a shipping address - both sync with Civi (and vice versa). I then add (for example) a website address in CiviCRM, which updates (although takes a very long time), and then when I try and update (for example), 'Last Name', it does not save (with no clear errors generated). I'll need more time to debug this as it is relatively sporadic.

Thanks for the hard work to connect up the WooCommerce addresses!

Paul

christianwach commented 1 year ago

@pixel-paul I've merged my fixes into the main repo. If you get to the source of the issues you've been having, let me know and we can look at resolving them.

pixel-paul commented 1 year ago

Thanks @christianwach - I've been caught up in another project, but will get back to you hopefully very soon!

pixel-paul commented 1 year ago

I've tested this further and it is working as it should.

Many thanks for the fixes and time spent @christianwach.