Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Updated shipping address during order not saved


jmroth

Recommended Posts

If I make my order up to the checkout_confirmation page and then go back (via the links provided at the bottom of the checkout pages) to the shipping page and change my address, the new address is correctly used for the paypal transaction and also for the confirmation mail, but the info in the orders table in the database is not updated.

 

Therefore, looking at the order with the admin tool does not reflect the correct order. Also, one should not use the orders table for further processing (i.e. generating shipment info), since that data can be wrong.

 

The problem is that the paypal payment module confirmation() function does not account for that situation...

 

(The same goes for the billing address of course)

Edited by jmroth
Link to comment
Share on other sites

  • 2 weeks later...

I think I have solved most of these problems, although I cannot provide you with a contribution since I have too many other contributions installed.

I can however provide an overview: checkout_process.php contains mostly three/four parts:

- initialization

- insertion of order into database tables (starting with

   function confirmation() {
     global $cartID, $cart_PayPal_Standard_ID, $customer_id, $languages_id, $order, $order_total_modules;
     global $cart; // JM

     /*
      * check if the order_id  AND  cart_id matches our session
      */

     if (tep_session_is_registered('cartID')) {
       $insert_order = false;
       $update_order = false; //JM

       if (tep_session_is_registered('cart_PayPal_Standard_ID')) {
         $order_id = substr($cart_PayPal_Standard_ID, strpos($cart_PayPal_Standard_ID, '-')+1);

         $curr_check = tep_db_query("select currency from " . TABLE_ORDERS . " where orders_id = '" . (int)$order_id . "'");
         $curr = tep_db_fetch_array($curr_check);

         if ( ($curr['currency'] != $order->info['currency']) || ($cartID != substr($cart_PayPal_Standard_ID, 0, strlen($cartID))) ) {
           $check_query = tep_db_query('select orders_id from ' . TABLE_ORDERS_STATUS_HISTORY . ' where orders_id = "' . (int)$order_id . '" limit 1');

           if (tep_db_num_rows($check_query) < 1) {
             tep_db_query('delete from ' . TABLE_ORDERS . ' where orders_id = "' . (int)$order_id . '"');
             tep_db_query('delete from ' . TABLE_ORDERS_TOTAL . ' where orders_id = "' . (int)$order_id . '"');
             tep_db_query('delete from ' . TABLE_ORDERS_STATUS_HISTORY . ' where orders_id = "' . (int)$order_id . '"');
             tep_db_query('delete from ' . TABLE_ORDERS_PRODUCTS . ' where orders_id = "' . (int)$order_id . '"');
             tep_db_query('delete from ' . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . ' where orders_id = "' . (int)$order_id . '"');
             tep_db_query('delete from ' . TABLE_ORDERS_PRODUCTS_DOWNLOAD . ' where orders_id = "' . (int)$order_id . '"');
           }

           $insert_order = true;
         } else {
           $update_order = true; //JM
         }
       } else {
         $insert_order = true;
       }

         $order_totals = array();
         if (is_array($order_total_modules->modules)) {
           reset($order_total_modules->modules);
           while (list(, $value) = each($order_total_modules->modules)) {
             $class = substr($value, 0, strrpos($value, '.'));
             if ($GLOBALS[$class]->enabled) {
               for ($i=0, $n=sizeof($GLOBALS[$class]->output); $i<$n; $i++) {
                 if (tep_not_null($GLOBALS[$class]->output[$i]['title']) && tep_not_null($GLOBALS[$class]->output[$i]['text'])) {
                   $order_totals[] = array('code' => $GLOBALS[$class]->code,
                                           'title' => $GLOBALS[$class]->output[$i]['title'],
                                           'text' => $GLOBALS[$class]->output[$i]['text'],
                                           'value' => $GLOBALS[$class]->output[$i]['value'],
                                           'sort_order' => $GLOBALS[$class]->sort_order);
                 }
               }
             }
           }
         }

         // need to insert order before actual processing since IPN looks it up :-)
         // however must not update stock until payment -> IPN

       if ($insert_order == true) {
         echo " <!--@@INSERT--> " ;
         require('inc/insertorder.php');

         $cart_PayPal_Standard_ID = $cartID . '-' . $insert_id;
         tep_session_register('cart_PayPal_Standard_ID');
       }

       if ($update_order === true) {
         echo " <!--@@UPDATE--> " ;
         require('inc/updateorder.php');
       }

       // JM - log the confirmation page
       if (isset($order_id) || isset($insert_id)) {
         if (isset($order_id)) $id = $order_id;
         if (isset($insert_id)) $id = $insert_id;
         $sql_data_array = array('orders_id' => $id,
                                 'orders_status_id' => MODULE_PAYMENT_PAYPAL_STANDARD_PREPARE_ORDER_STATUS_ID,
                                 'date_added' => 'now()',
                                 'customer_notified' => '0',
                                 'comments' => 'paypal->confirmation()');
         //tep_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array);
         $cart->order_id = $id;
       }

     }

     return false;
   }

 

where update_order.php mainly contains the same thing than insert_order.php (that is the part of the code from checkout_process.php mentioned at the top), where the insert statements have been replaced by updates, so part of it would i.e. look like

 

tep_db_query("DELETE FROM ".TABLE_ORDERS_TOTAL." WHERE orders_id='". (int)$order_id ."'");
for ($i=0, $n=sizeof($order_totals); $i<$n; $i++) {
 $sql_data_array = array('orders_id' => (int)$order_id,
                         'title' => $order_totals[$i]['title'],
                         'text' => $order_totals[$i]['text'],
                         'value' => $order_totals[$i]['value'],
                         'class' => $order_totals[$i]['code'],
                         'sort_order' => $order_totals[$i]['sort_order']);
 tep_db_perform(TABLE_ORDERS_TOTAL, $sql_data_array);
}

 $customer_notification = (SEND_EMAILS == 'true') ? '1' : '0';
 $sql_data_array = array('orders_id' => (int)$order_id,
                         'orders_status_id' => $order->info['order_status'],
                         'date_added' => 'now()',
                         'customer_notified' => $customer_notification,
                         'comments' => $order->info['comments']);
 tep_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array, 'update', 'orders_id='.(int)$order_id);

 //kgt - discount coupons
if( tep_session_is_registered( 'coupon' ) && is_object( $order->coupon ) ) {
 $sql_data_array = array( 'coupons_id' => $order->coupon->coupon['coupons_id'],
                          'orders_id' => (int)$order_id );

 $check_query = tep_db_query("select orders_id from " . TABLE_DISCOUNT_COUPONS_TO_ORDERS . " where orders_id = '" . (int)$order_id . "'");
 if (tep_db_num_rows($check_query)) {
   tep_db_perform( TABLE_DISCOUNT_COUPONS_TO_ORDERS, $sql_data_array, 'update', 'orders_id='.(int)$order_id);//update
 } else {
   tep_db_perform( TABLE_DISCOUNT_COUPONS_TO_ORDERS, $sql_data_array); //insert
 }
}
 //end kgt - discount coupons

 

Maybe in the future one could provide this modular structure directly... or maybe this is already the case for osC3 , dunno...

Edited by jmroth
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...