CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Hook to change contribution status for non-monetary
Pages: [1]

Author Topic: Hook to change contribution status for non-monetary  (Read 2042 times)

aspagarino

  • I post occasionally
  • **
  • Posts: 89
  • Karma: 10
  • San Diego Joomla
    • California Center for Sustainable Energy
  • CiviCRM version: CiviCRM 4.3
  • CMS version: Drupal 7
Hook to change contribution status for non-monetary
January 14, 2010, 07:22:39 pm
When someone fill an online form for a non-monetary contribution the status by default is set to "Completed". I need to change the non-monetary contributions to "Pending" using a post hook (as suggested by Kurund).

I have used simple hooks before but I need a little guidance about getting the table information (civicrm_contribution table) into the query and updating the contribution_status_id to 1


Code: [Select]
function joomla_civicrm_post( $op, $objectName, $objectId, &$objectRef ) {

if ( $objectName == 'Contribution' && $op == 'create' ) {

// this is the contribution page we are interested
if ( $objectRef->contribution_page_id != 2) {
        return;
    }


    $tableName = CRM_Core_DAO::getFieldValue( 'CRM_Contribute_DAO_Contribution',
                                              $objectRef,
                                              'table_name' );
   

$sql = "UPDATE $tableName SET contribution_status_id = 1 WHERE entity_id = $objectId";
        CRM_Core_DAO::executeQuery( $sql, CRM_Core_DAO::$_nullArray);
}
}

Thanks in advance for any pointers.
Andres

Open Source is Green

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Hook to change contribution status for non-monetary
January 14, 2010, 07:42:47 pm

Code: [Select]
function joomla_civicrm_post( $op, $objectName, $objectId, &$objectRef ) {

if ( $objectName == 'Contribution' && $op == 'create' ) {

// this is the contribution page we are interested
if ( $objectRef->contribution_page_id != 2) {
        return;
    }

$sql = "UPDATE civicrm_contribution SET contribution_status_id = 1 WHERE entity_id = $objectId";
        CRM_Core_DAO::executeQuery( $sql, CRM_Core_DAO::$_nullArray);
}
}

A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

aspagarino

  • I post occasionally
  • **
  • Posts: 89
  • Karma: 10
  • San Diego Joomla
    • California Center for Sustainable Energy
  • CiviCRM version: CiviCRM 4.3
  • CMS version: Drupal 7
Re: Hook to change contribution status for non-monetary
January 15, 2010, 05:43:22 pm
Thanks Lobo... Got an error with the entity_id.   
Code: [Select]
Array
(
    [callback] => Array
        (
            [0] => CRM_Core_Error
            [1] => handle
        )

    [code] => -19
    [message] => DB Error: no such field
    [mode] => 16
    [debug_info] => UPDATE civicrm_contribution SET contribution_status_id = 1 WHERE entity_id = 86 [nativecode=1054 ** Unknown column 'entity_id' in 'where clause']
    [type] => DB_Error
    [user_info] => UPDATE civicrm_contribution SET contribution_status_id = 1 WHERE entity_id = 86 [nativecode=1054 ** Unknown column 'entity_id' in 'where clause']
    [to_string] => [db_error: message="DB Error: no such field" code=-19 mode=callback callback=CRM_Core_Error::handle prefix="" info="UPDATE civicrm_contribution SET contribution_status_id = 1 WHERE entity_id = 86 [nativecode=1054 ** Unknown column 'entity_id' in 'where clause']"]
)

[/code]
Andres

Open Source is Green

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Hook to change contribution status for non-monetary
January 15, 2010, 08:22:54 pm

use the following update statement

Code: [Select]
$sql = "UPDATE civicrm_contribution SET contribution_status_id = 1 WHERE id = $objectId";

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

aspagarino

  • I post occasionally
  • **
  • Posts: 89
  • Karma: 10
  • San Diego Joomla
    • California Center for Sustainable Energy
  • CiviCRM version: CiviCRM 4.3
  • CMS version: Drupal 7
Re: Hook to change contribution status for non-monetary
January 18, 2010, 06:14:57 pm
Like always thank you Lobo... it worked!  :D

I also realized that I needed to change the status to pending is 2 (SET contribution_status_id = 2) just in case someone out there is doing the same.



Andres

Open Source is Green

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Hook to change contribution status for non-monetary

This forum was archived on 2017-11-26.