This seems to be driving me absolutely nuts…. I’m hoping someone can help me:
I’m using the simple_commerce_perform_actions_end hook to do some further processing - but it doesn’t seem to be executing (or it’s erroring and I have no way of trapping the error)
This is what I have :
class Hippo_mpu_ext
{
var $name = 'Hippo Member Payment Update';
var $version = '1.0.0';
var $description = 'Updates the member data for a user once the IPN notification has completed from PayPal';
var $settings_exist = 'n';
var $docs_url = '';
// -------------------------------
// Constructor
// -------------------------------
function Hippo_mpu_ext($settings=''){
$this->EE =& get_instance();
}
public function __construct($settings=FALSE)
{
$this->EE =& get_instance();
}
function update_members() {
$memberId = $this->post('custom'); // member id passed from SCM
$qty = $this->post('quantity'); // quantity passed from SCM
$status = $this->post('payment_status'); // Payment Status passed from SCM
if ($status=='Completed') // we only want to execute this if the transaction is completed (i.e. sold)
{
$query = $this->EE->db->query('update exp_member_data set m_field_id_1 = m_field_id_1 +'.$qty.' where member_id='.$memberId);
}
}
// --------------------------------
// Activate Extension
// --------------------------------
function activate_extension()
{
$this->EE->db->insert('extensions', array(
'class' => 'Hippo_mpu_ext',
'hook' => 'simple_commerce_perform_actions_end',
'method' => 'update_members',
'settings' => '',
'priority' => 1,
'version' => $this->version,
'enabled' => 'y'
));
}
// --------------------------------
// Update Extension
// --------------------------------
function update_extension ( $current='' )
{
}
// END
// --------------------------------
// Disable Extension
// --------------------------------
function disable_extension()
{
$this->EE->db->delete('exp_extensions', array('class' => get_class($this)));
}
// END
}How can I get debug from this extension since it’s got no front end interaction?
I think it’s a case of not seeing the woods for the trees, but it’s really bugging me now :(
TIA
Carl
Hi Carl,
Forgive me if I’m stating the obvious, but shouldn’t
$this->post('custom');be
$this->EE->input->post('custom');That’s about all I can see that is “wrong” with this piece of code. While I’m at it… wouldn’t it be safer to grab the current member_id from the session instead of the POST array?
And a little trick I always pull to keep things PHP4 compatible, but all the code in the same place:
function Hippo_mpu_ext($settings='')
{
$this->__construct($settings);
}Greetz, Wouter
(or it’s erroring and I have no way of trapping the error)
Carl,
I’d suggest adding in your own error logging method. Maybe while you’re testing you could add a number of CP logged items upon successes and failures within the add-on. Then you can review the CP Log and see what all happened. I do this often when I’m testing methods that aren’t easily tested with a UI in the end.
Okay… so I just read up on that hook and it seems there IS a $this->post array, so I stand corrected on that. But are you sure you can access it like that? In the docs it says it’s an array, so wouldn’t that be $this->post[‘custom’]
Whenever I need to debug something I just throw in little piece of code like this:
// Debug this value and kill the process
echo "<pre>".print_r($value, true)."</pre>
<p>”;
exit;Then I just move it down the line to see where I start getting unexpected results. It might be a bit excessive, but it works for me and at least I know where the problem occurs.
In you extension it would be the $this->post array that’s most interesting to debug and if the process doesn’t get killed if you placed it right after the function definition, the hook doesn’t get called at all.
Greetz, Wouter
Hi All, Thanks for the many replies and lots of ideas….
I had originally looked for $this->post[‘custom’] and this was returning nothing, so I used the CP Logging functionality to see what seems to be passed (thanks for this Erik), and $this->post seems to not exist (despite the docs http://ellislab.com/expressionengine/user-guide/development/extension_hooks/module/simple_commerce/index.html#simple_commerce_perform_actions_end telling me it should).
However, since this is being executed as part of a post by PayPal on the IPN Notification, it posts all the information and that is available to me, so the way I did it was as follows:
foreach($_POST as $key => $value)
{
$this->post[$key] = $this->EE->security->xss_clean($value);
}All the Post data is then available to me. (as far as I can see, this needs to be done this way, because PayPal posts all the data as a single string and I have to convert it to an array).
Also Wouter, thanks for the php4 compatibility info - normally, I’d add that but on this occasion I’m in control of server/php version so figured there was no point 😊
Cheers,
C.
Not sure about this and haven’t tested it, but does the following work?
function update_members($obj, $row)
{
$memberId = $obj->post('custom'); // member id passed from SCM
$qty = $obj->post('quantity'); // quantity passed from SCM
$status = $obj->post('payment_status'); // Payment Status passed from SCM
if ($status=='Completed') // we only want to execute this if the transaction is completed (i.e. sold)
{
$query = $this->EE->db->query('update exp_member_data set m_field_id_1 = m_field_id_1 +'.$qty.' where member_id='.$memberId);
}
}Reading the docs again, the $this->post, might refer to the $this obj that is passed through the hook.
Greetz, Wouter
Hi Carl,
I’m guessing that Wouter has offered the solution to your troubles - based on the docs, my suggestion would also have been to add parameters to your update_members() function call.
As to how you might debug your add-on, if you’re on EE2 you might be better advised to use the log_message() functions that come from CodeIgniter itself. See CI’s Error Handling user guide page for more, but basically you can do:
log_message('debug', 'Extension hook has been called');
...
log_message('error', 'Hook has been called, but $this seems undefined.');Cheers, John
Sorry, I neglected to tell you where to find the logs generated by log_message(). First, go into your config.php file and search for “Error Logging Threshold”. There is a config setting with 5 possible levels to set:
$config['log_threshold'] = 4; // 4 will log all messagesOnce you turn on logging (anything higher than 0), look here for the log file of the day:
/system/codeigniter/system/logs/yyyy-mm-dd.php
HTH, John
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.