Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Obtain $order_id value from within payment module


Guest

Recommended Posts

Hi all,

 

So this will hopefully be a really simple question to answer; I am trying to get the order id for the current order from within the code of a payment module that I am creating.

 

Any help will be gratefully accepted.

 

 

Cheers,

Paul

Link to comment
Share on other sites

Hi All,

 

Ok, solved my problem; I wanted the order number within the payment module code so that I could update the status of orders based on a certain condition. I didn't realise (stupidly) that the "$order_id" variable isn't initialized until after the payment module has added the order to the database.

 

The solution that worked for me: I moved the code that updates the order status in the database to the "after_process()" function in my payment module, and fed it the "$insert_id" variable that is available there.

 

 

Cheers,

Paul

Link to comment
Share on other sites

  • 4 weeks later...

Hi,

 

How can I help you Mario, give me a few more details about what you are trying to achieve and I will do the best I can for you.

 

Cheers,

Paul

Link to comment
Share on other sites

hi Cyburg

 

i believe that from your post that you could get the $order_id from one payment module that you has developing, can u tel me how you do it ? i need the same from one module that i developing but the array $order dont have it .

 

Regards,

MV

Edited by webpt
Link to comment
Share on other sites

  • 2 months later...
Hi All,

 

Ok, solved my problem; I wanted the order number within the payment module code so that I could update the status of orders based on a certain condition. I didn't realise (stupidly) that the "$order_id" variable isn't initialized until after the payment module has added the order to the database.

 

The solution that worked for me: I moved the code that updates the order status in the database to the "after_process()" function in my payment module, and fed it the "$insert_id" variable that is available there.

 

 

Cheers,

Paul

 

 

If I understand you correctly, you put the code in from checkout_process into the after_process function of your module. How did you keep it from processing twice ? I think

 

if $$payment->module != $myPaymentModule

 

before the database update in the checkout_process should work. This would allow other methods of payment to access the file with standard functionality.

 

Any advice would be appreciated

Link to comment
Share on other sites

MY REPLY TO A PM ABOUT THIS TOPIC:

 

Hi,

 

I was working on a new payment module when I had that particular issue, I assume you are also making a custom payment module?

 

When I wrote that particular payment module, I needed to update the record in the database for the order I was working with; I needed to add some data to the order whilst the payment module was being processed at checkout.

 

My first attempts to do this failed because I had placed my code (the code to update the order in database) in the "before_process()" function of my payment module; I scratched my head for ages wondering why I couldn't obtain an order ID to work with.

 

Then I realised that there isn't any order ID available in the "before_process()" function, because at that stage the order hasn't even been inserted into the database, and the order ID is only autogenerated by MySQL when the database insert for the order takes place.

 

In my case the solution was simple, I just moved my custom code to the "after_process()" function in my payment module; at this stage of the process, the ID of the inserted order is available, you can access the value by using the global variable "$insert_id".

 

Here is my "after_process()" function:

 

	function after_process() {
  global $insert_id;

  // set the order account status flag
  tep_db_query("update " . TABLE_ORDERS . " set order_on_account = 2 where orders_id = '" . (int)$insert_id . "'");

  // set the order status flag
  tep_db_query("update " . TABLE_ORDERS . " set orders_status = " . MODULE_PAYMENT_PO_ORDER_STATUS_ID . ", last_modified = now() where orders_id = '" . (int)$insert_id . "'");
}

 

 

Hopefully, you will be able to do your processing in the "after_process()" function of your new payment module; let me know how you get on.

 

I will also post this message to the thread I originally started on this topic, in the hope that it might provide more complete information to anyone else facing the same issue.

 

 

Cheers,

Paul

 

 

P.S. Apologies for not getting back to you much much sooner Mario; I am always extremely busy at work, and I rarely find time to visit the forum.

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.
Note: Your post will require moderator approval before it will be visible.

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...