This is probably the scariest hack I’ve done yet to mod.simple_commerce.php. Before I start, I have to remind people that it will be overwritten with an upgrade, and that the new code will silently throw out any transactions that used to work. Definitely use at your own risk. We have a paypal email and an admin email for every transaction, and if we don’t get one, we know to check it out.
I had everything working before I realized that users had to log in before buying anything. That was unacceptable to me, but I didn’t want to redo everything. So I looked at the code to see what I could do.
And they were right. You had to have a login id for it to work. Hmmm…
I created a “Guest” account in the “Guests” group. It turned out to be id 15 on my system.
I added the following code to the section where they check to see if the user is valid, before they did any of the checks:
if ( $this->post['custom'] == '0' )
$this->post['custom'] = $this->guest_id; /** this is the guest account in our system */
I had earlier set $this->guest_id = 15; up at the top of the file. I suppose I could have queried it too, of course.
This worked fine until we wanted to send the customer an email. So I added this where we determine the email address $to
if ( $this->post['custom'] != $this->guest_id )
{
$to = $this->post['payer_email'];
}
else
{
$result = $DB->query("SELECT email FROM exp_members WHERE member_id = '".$DB->escape_str($this->post['custom'])."'");
$to = $result->row['email'];
}
if ( $to != '' )
{
And be sure to put the closing ‘}’ at the appropriate place (after the customer email template code, before the admin email template code).
Note: I never tested this last one, because we decided to not send the email.
Good luck.
Category:Commerce -> PayPal Category:Hacks
