Re: [GCO4OSC] Problem with the logic that adds customers to the google_checkout table

70 views
Skip to first unread message
Message has been deleted

Ropu

unread,
Nov 7, 2007, 9:35:02 AM11/7/07
to google-checkout-f...@googlegroups.com
Hey! nice catch!!

you are right!

im adding that patch!

thx again

ropu



On 11/4/07, ZachAnderson < zach.a...@baby-wise.com> wrote:

I believe there may be an error in how the responsehandler.php file
decides when to add records to the google_checkout table. Right now
those records are made only when a customer is new to both the osC
customers table and they don't already exist in the google_checkout
table. So a customer who already has their email address on record
with the site, but is using google checkout for the first time will
never have a record created matching their buyer_id to their
customer_id.

This may not seem like a big deal, but those records are used in a
join for the $google_answer query in orders.php and without them the
status of your orders on the google checkout website won't be updated
when the information is updated in osC. So, for example, you push the
order to shipped and provide tracking information, that information
will never make it to the customer's google checkout account and no
errors will be generated. This is only for customers who already had
an account on your site before they used google checkout for a
purchase. There are probably other times where not having the
google_checkout records will have an effect, but this is what led me
to start digging.

I was able to fix it by pulling the insert statement out of the if
condition it was in and instead running a query to check and see if
the customer_id already has a matching record in google_checkout.
There may be a more elegant way to do this, but it seems to work and
its straightforward.

Its worth saying that I may be misinterpreting the intent of something
in the code, if that's the case, please just let me know so I can fix
my install as well ;) Thanks for all the hard work Ropu, I hope this
helps and, if there's a problem, can be fixed in the next release.

Here's the original code from responsehandler.php -

//    Check if the email exists
      $customer_exists = tep_db_fetch_array(tep_db_query("select
customers_id from " .
      TABLE_CUSTOMERS . " where customers_email_address = '" .
      gc_makeSqlString($gc_data[$root]['buyer-billing-address']
['email']['VALUE']) . "'"));

//    Check if the GC buyer id exists
      $customer_info = tep_db_fetch_array(tep_db_query("select
gct.customers_id from " .
          $googlepayment->table_name . " gct " .
          " inner join " .TABLE_CUSTOMERS . " tc on gct.customers_id =
tc.customers_id ".
          " where gct.buyer_id = " .
          gc_makeSqlString($gc_data[$root]['buyer-id']['VALUE'])));

      $new_user = false;
//    Ignore session to avoid mix of Cart-GC sessions/emails
//    GC email is the most important one
      if ($customer_exists['customers_id'] != '') {
        $customer_id = $customer_exists['customers_id'];
        tep_session_register('customer_id');
      }
      else if($customer_info['customers_id'] != ''){
        $customer_id = $customer_info['customers_id'];
        tep_session_register('customer_id');
      }
      else {
        list ($firstname, $lastname) =
            explode(' ', gc_makeSqlString($gc_data[$root]['buyer-
billing-address']['contact-name']['VALUE']), 2);
        $sql_data_array = array (
          'customers_firstname' => $firstname,
          'customers_lastname' => $lastname,
          'customers_email_address' => $gc_data[$root]['buyer-billing-
address']['email']['VALUE'],
          'customers_telephone' => $gc_data[$root]['buyer-billing-
address']['phone']['VALUE'],
          'customers_fax' => $gc_data[$root]['buyer-billing-address']
['fax']['VALUE'],
          'customers_default_address_id' => 0,
          'customers_password' =>
tep_encrypt_password(gc_makeSqlString($gc_data[$root]['buyer-id']
['VALUE'])),
          'customers_newsletter' => $gc_data[$root]['buyer-marketing-
preferences']['email-allowed']['VALUE']=='true'?1:0
        );
        if (ACCOUNT_DOB == 'true') {
          $sql_data_array['customers_dob'] = 'now()';
        }
        tep_db_perform(TABLE_CUSTOMERS, $sql_data_array);
        $customer_id = tep_db_insert_id();
        tep_session_register('customer_id');
        tep_db_query("insert into " . TABLE_CUSTOMERS_INFO . "
                                      (customers_info_id,
customers_info_number_of_logons,

customers_info_date_account_created)
                                 values ('" . (int) $customer_id . "',
'0', now())");
        tep_db_query("insert into " . $googlepayment->table_name . "
" .
                      " values ( " . $customer_id . ", " .
                      $gc_data[$root]['buyer-id']['VALUE'] . ")");
        $new_user = true;
      }

---------------------------------------

*** I really only changed from the 'else' statement down, so that
section is below, with the small changes I made ***

      else {
        list ($firstname, $lastname) =
            explode(' ', gc_makeSqlString($gc_data[$root]['buyer-
billing-address']['contact-name']['VALUE']), 2);
        $sql_data_array = array (
          'customers_firstname' => $firstname,
          'customers_lastname' => $lastname,
          'customers_email_address' => $gc_data[$root]['buyer-billing-
address']['email']['VALUE'],
          'customers_telephone' => $gc_data[$root]['buyer-billing-
address']['phone']['VALUE'],
          'customers_fax' => $gc_data[$root]['buyer-billing-address']
['fax']['VALUE'],
          'customers_default_address_id' => 0,
          'customers_password' =>
tep_encrypt_password(gc_makeSqlString($gc_data[$root]['buyer-id']
['VALUE'])),
          'customers_newsletter' => $gc_data[$root]['buyer-marketing-
preferences']['email-allowed']['VALUE']=='true'?1:0
        );
        if (ACCOUNT_DOB == 'true') {
          $sql_data_array['customers_dob'] = 'now()';
        }
        tep_db_perform(TABLE_CUSTOMERS, $sql_data_array);
        $customer_id = tep_db_insert_id();

        tep_session_register('customer_id');
        tep_db_query("insert into " . TABLE_CUSTOMERS_INFO . "
                                      (customers_info_id,
customers_info_number_of_logons,

customers_info_date_account_created)
                                 values ('" . (int) $customer_id . "',
'0', now())");
        $new_user = true;
      }
      $customer_in_gc = tep_db_fetch_array(tep_db_query("select
gct.customers_id from " .

$googlepayment->table_name . " gct " .
                                                             " where
gct.buyer_id = " . gc_makeSqlString($gc_data[$root]['buyer-id']
['VALUE'])));

      if($customer_in_gc['customer_id'] == '') {
        tep_db_query("insert into " . $googlepayment->table_name . "
" .
                            " values ( " . $customer_id . ", " .
                            $gc_data[$root]['buyer-id']['VALUE'] . ")");
       }





--
.-. --- .--. ..-
R  o  p  u
Reply all
Reply to author
Forward
0 new messages