Open to all! Ask other shopowners for help.
Pierre_P
Contributor
Posts: 144 Joined: Fri Mar 12, 2021 5:06 am
Phoenix Version: v1.1.0.6
Has thanked: 21 times
Been thanked: 11 times
Post
by Pierre_P » Fri Mar 10, 2023 4:32 am
Need bit help on session variables.
This is from a really old module.
It is used to record the shipping method used upon checkout.
Code: Select all
public function execute() {
global $PHP_SELF, $customer_id, $order_id, $shipping, $shipping_module;
if ( isset($_SESSION['customer_id']) || isset($_SESSION['customer_is_guest'])) {
switch ( basename($PHP_SELF) ) {
case 'checkout_confirmation.php' :
if (!isset($_SESSION['shipping_module'])) {
$_SESSION['shipping_module'] = $_SESSION['shipping']['id'];
$shipping_module = $shipping['id'];
}
break;
case 'checkout_success.php' :
if ( isset($_SESSION['shipping_module'] )) {
unset($_SESSION['shipping_module']);
$sql_data_array = array('shipping_module' => $shipping_module);
$GLOBALS['db']->perform('orders', $sql_data_array, 'update' , "orders_id = '" . (int)$order_id . "'");
}
} // end switch page
} // endif customer_id registered
}
ecartz
Core Team
Posts: 3084 Joined: Tue Nov 05, 2019 6:02 pm
Phoenix Version:
Has thanked: 4 times
Been thanked: 208 times
Post
by ecartz » Sat Mar 11, 2023 12:24 am
Code: Select all
public function execute() {
global $order_id;
if ( isset($_SESSION['customer_id']) || isset($_SESSION['customer_is_guest'])) {
switch ( basename(Request::get_page()) ) {
case 'checkout_confirmation.php' :
if (!isset($_SESSION['shipping_module'])) {
$_SESSION['shipping_module'] = $_SESSION['shipping']['id'];
}
break;
case 'checkout_success.php' :
if ( isset($_SESSION['shipping_module'] )) {
$sql_data_array = ['shipping_module' => $_SESSION['shipping_module']];
unset($_SESSION['shipping_module']);
$GLOBALS['db']->perform('orders', $sql_data_array, 'update' , "orders_id = " . (int)$order_id);
}
} // end switch page
} // endif customer_id registered
}
Pierre_P
Contributor
Posts: 144 Joined: Fri Mar 12, 2021 5:06 am
Phoenix Version: v1.1.0.6
Has thanked: 21 times
Been thanked: 11 times
Post
by Pierre_P » Mon Mar 20, 2023 2:34 pm
Hello
@ecartz
a) I did pick up example downloadable products is recorded in database as null. Not much worries with this.
b) Then i have a payment module(custom coded) that also are not recording the shipping method - also shows null.
This module leaves my site to complete the transaction and is redirected back with
Code: Select all
Href::redirect( $Linker->build( 'checkout_success.php' ) ); if successfully
With the above i guess that $_SESSION['shipping_module'] cannot be stored if i'm correct with:
Code: Select all
$_SESSION['shipping_module'] = $_SESSION['shipping']['id'];
Alternative way to do this perhaps?