Link to home
Create AccountLog in
Avatar of JoeFletcher
JoeFletcher

asked on

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.
ASKER CERTIFIED SOLUTION
Avatar of Joe Wu
Joe Wu
Flag of Australia image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of JoeFletcher
JoeFletcher

ASKER

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