Page 1 of 1

Record shipping module

Posted: Fri Mar 10, 2023 4:32 am
by Pierre_P
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
    }

Re: Record shipping module

Posted: Sat Mar 11, 2023 12:24 am
by ecartz

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
    }

Re: Record shipping module

Posted: Mon Mar 20, 2023 2:34 pm
by Pierre_P
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?