• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 347
  • Last Modified:

How to pass a variable from one module to another and then into mysql

I'm customizing Zen Cart, an open source shopping cart program based on PHP and MySQL.  I really don't know too much about PHP... just enough to alter some code but not really write it. So I'm not sure what you need to help me out, so I'll include as much as I can reckon matters.

I have a variable ($shipping_methods_types) inside a function called quote within a class / module called ups.  $shipping_methods_types contains the available UPS methods (not the chosen method - the available methods). For example, it'll contain: 1DA,2DA,GND.

I want to store that value in a field called shipping_allowed in the orders table.

It looks like the place to insert it is in a function called create within a class called order.  When the customer places the order, it seems that code runs.  There's a portion of the function that seems to take all the variables and insert it into the orders table through $sql_data_array. I've been able to put in a dummy value into the shipping_allowed field by adding this code: $sql_data_array[shipping_allowed] = 'dummy value';  after the long the list of other variables. Just a snippet of that code:

    $sql_data_array = array('customers_id' => $_SESSION['customer_id'],
                            'customers_name' => $this->customer['firstname'] . ' ' . $this->customer['lastname'],
                            'customers_company' => $this->customer['company'],
                            ....
                            'ip_address' => $_SESSION['customers_ip_address'] . ' - ' . $_SERVER['REMOTE_ADDR']
                            );

    $sql_data_array[shipping_allowed] = 'dummy value';

    zen_db_perform(TABLE_ORDERS, $sql_data_array);


My problem is that I don't know how to pass the real value of $shipping_methods_types from the UPS module to the create function.
0
JoeFletcher
Asked:
JoeFletcher
  • 2
1 Solution
 
nizsmoDeveloperCommented:
How about using a session variable to temporary store your variable $shipping_methods_types:

$_SESSION["temp_shipping_method_types"] = $shipping_methods_types;

Then getting it out again in the create function.

Let me know how you go.
0
 
JoeFletcherAuthor Commented:
Dude, you rock. That worked! I was hoping there'd be an easy way like that.  One last question: what if there's no value (null?) for $shipping_methods_types?  Will it make a difference?  For example when I store, and/or when I call it again, which is:

$sql_data_array = array('customers_id' => $_SESSION['customer_id'],
                                               ...
      'shipping_allowed' => $_SESSION['temp_shipping_method_types'],
                                               ...
zen_db_perform(TABLE_ORDERS, $sql_data_array);
0
 
nizsmoDeveloperCommented:
Glad it worked. You can additionally add an IF statement to check whether $shipping_methods_types is null:

if($_SESSION["temp_shipping_method_types"] != null)
{
// Do what you need to do here...
}

It should not make a difference though.

Also you can set a default value for $shipping_methods_types, as below:

if($_SESSION["temp_shipping_method_types"] == null)
{
$_SESSION["temp_shipping_method_types"] = "N/A";
}

Therefore, these always a value in shipping_method_types, and the string value "N/A" represents that the user has not selected anything.

Hope that clarifies it up.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now