Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2009
    Posts
    169
    Plugin Contributions
    2

    help question Passing variable to function process_button()

    Hey All,

    I'm trying to pass a custom variable to the following function that appears in my Payment Gateway module.

    The custom variable is created like this inside classes/order.php like this:

    PHP Code:
        $getordercount $db->Execute("select date_purchased
                            from " 
    TABLE_ORDERS "
                            where customers_id = '" 
    . ((int)$_SESSION['customer_id']) . "'");

       
    $orderCount = ($getordercount->RecordCount()) + 1;

       
    $customOID =  'WOOHOO'sprintf("%05d", ((int)$_SESSION['customer_id'])) . 'R' sprintf("%03d",$orderCount); 
    What I'm using this for is a custom order reference - so basically I use it in place of the Order ID - BUT REMEMBER, I DO NOT REPLACE THE ORDER ID that stays as is and is unaffected.

    Now I've managed to pass the $customOID to the process_button() function in the payment module by adding the following in classes/order.php within the function cart() function, like this:

    PHP Code:
        $this->orderef = array('orderef' => $customOID); 
    And then I call it in the payment module's process_button() like this:
    PHP Code:
    $order->orderef['orderef']; 
    I don't like this solution, it seems wrong. Though it works, it just feels wrong. Any guidance? Thanks.

  2. #2
    Join Date
    Jul 2012
    Posts
    16,733
    Plugin Contributions
    17

    Default Re: Passing variable to function process_button()

    Looking at other examples of using the process_button functionality, I saw at least two different things. One was to use a hidden (or not hidden) field on the checkout_payment page such that when the payment is submitted the data within the form from the payment page would be carried over to the checkout_confirmation page where the post data could be read and passed further on to your "next" operation. Otherwise could store as a session variable, or if going to keep with the $order like that, then could "append" it as an additional key to any of the applicable internal variables. Further that could be done using an observer class instead of having to modify the core code in order to append this extra variable/array key to the associated internal variable.

    All that also doesn't really include a proper evaluation of whether this is the correct use of that function either, just trying to answer the question asked from a small world view. I have my suspicions that there is something else amiss.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  3. #3
    Join Date
    Mar 2009
    Posts
    169
    Plugin Contributions
    2

    Default Re: Passing variable to function process_button()

    YES!

    Thanks..

    I originally tried a session variable, but my problem was I was not assigning inside the function cart() function in classes/order.php.

    I was assigning it in a higher up function, therefore it was returning a NULL value and throwing an error.

    Completely forgot when finally finding the correction function to retry the SESSION VAR approach.

    Thanks for jump starting my brain mate!

  4. #4
    Join Date
    Jul 2012
    Posts
    16,733
    Plugin Contributions
    17

    Default Re: Passing variable to function process_button()

    Quote Originally Posted by yaseent View Post
    YES!

    Thanks..

    I originally tried a session variable, but my problem was I was not assigning inside the function cart() function in classes/order.php.

    I was assigning it in a higher up function, therefore it was returning a NULL value and throwing an error.

    Completely forgot when finally finding the correction function to retry the SESSION VAR approach.

    Thanks for jump starting my brain mate!
    Be sure that if you use the session variable approach that you handle the session variable properly as well, ie. it gets cleared, reset, reassigned as applicable based on possible flow directions and operations. Then there's the question of whether that data needs to be generated every time an order is created off of the cart, or if it is only at certain times of processing and is the data available at that point to get your "unique" value, etc...
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

 

 

Similar Threads

  1. Replies: 6
    Last Post: 23 Sep 2011, 08:12 AM
  2. function to get cPath by passing the products_id?
    By rajoo.sharma in forum General Questions
    Replies: 2
    Last Post: 14 Aug 2009, 07:09 AM
  3. Passing variable to contact us for To field in store settings
    By MaxBodine in forum General Questions
    Replies: 4
    Last Post: 6 May 2009, 09:19 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR