mecachisenros / woocommerce_civicrm

GNU Affero General Public License v3.0
14 stars 16 forks source link

"CiviCRM Contribution could not be created" #24

Closed netzih closed 3 years ago

netzih commented 5 years ago

When adding a purchase nothing gets sent to civicrm despite it saying contact contribution updated (in the notes). However when I update the order to completed I'm seeing "CiviCRM Contribution could not be created". Do I need to install some extension in Civi? Or is the WP plugin enough?

netzih commented 5 years ago

Adding that when a new person makes a purchase in the notes on the order I'm seeing "CiviCRM Contact could not be found or created" What am I missing?

wdgordon commented 4 years ago

I am experiencing similar problems to @netzih above:

For my existing user...

When new order created:

When you try to view the 'WooCommerce Orders' tab in CiviCRM for the existing contact who made the order:

My server error logs contains several errors of this sort: May 07 11:39:27 [info] Not able to get custom group May 07 11:39:30 [info] Not able to get custom field May 07 11:39:31 [info] Not able to get custom field May 07 11:39:31 [info] Not able to add contribution May 07 11:44:58 [info] Not able to add/update address or phone May 07 11:44:59 [info] Not able to find contribution May 07 11:45:51 [info] Not able to add contribution

Running the following: Wordpress 5.4.1 WooCommerce 4.0.1 CiviCRM 5.23.0.

mjwright commented 4 years ago

The parameters passed to the CiviCRM Contact Create API do not include the contact type which is a required parameter. To fix the problem, add the 3 lines at the bottom of this code block (the else clause) to includes/class-woocommerce-civicrm-manager.php

`

public function add_update_contact( $cid, $order ){
    // Allow to bypass contact update
    if(true === apply_filters('woocommerce_civicrm_bypass_add_update_contact', false, $cid, $order)){
        return $cid;
    }
    $action = 'create';

    $contact = array();
    if( $cid != 0 ){
        try {
            $params = array(
                'contact_id' => $cid,
                'return' => array( 'id', 'contact_source', 'first_name', 'last_name' , 'contact_type'),
            );
            $contact = civicrm_api3( 'contact', 'getsingle', $params );
        } catch ( CiviCRM_API3_Exception $e ){
            CRM_Core_Error::debug_log_message( __( 'Not able to find contact', 'woocommerce-civicrm' ) );
            return FALSE;
        }
    }
    else{
        $contact['contact_type'] = 'Individual';
    }

`

netzih commented 3 years ago

The parameters passed to the CiviCRM Contact Create API do not include the contact type which is a required parameter. To fix the problem, add the 3 lines at the bottom of this code block (the else clause) to includes/class-woocommerce-civicrm-manager.php

`

public function add_update_contact( $cid, $order ){
  // Allow to bypass contact update
  if(true === apply_filters('woocommerce_civicrm_bypass_add_update_contact', false, $cid, $order)){
      return $cid;
  }
  $action = 'create';

  $contact = array();
  if( $cid != 0 ){
      try {
          $params = array(
              'contact_id' => $cid,
              'return' => array( 'id', 'contact_source', 'first_name', 'last_name' , 'contact_type'),
          );
          $contact = civicrm_api3( 'contact', 'getsingle', $params );
      } catch ( CiviCRM_API3_Exception $e ){
          CRM_Core_Error::debug_log_message( __( 'Not able to find contact', 'woocommerce-civicrm' ) );
          return FALSE;
      }
  }
  else{
      $contact['contact_type'] = 'Individual';
  }

`

This seems to have worked and it is now creating new contacts, however it is still not creating the contributions. Anything else that can be stopping it from creating the contribution?

netzih commented 3 years ago

I closed this issue since I did not have this issue on a different site that I installed this plugin on, However going back to the original site where I did have this problem I am still having this issue and getting "CiviCRM Contribution could not be created" in the order notes. I am wondering if maybe when I deleted the plugin and reinstalled it some of the settings and information stayed along and did not get removed totally from the woocommerce database.

EDIT: To add when logged in as existing user and placing an order, the order comes up in the woocommerce orders tab on civicrm but does not come up as a contribution and WooCommerce order notes shows contribution could not be created.

mecachisenros commented 3 years ago

@netzih should be fixed on latest master branch.