As you can see, I use this method to store my session,
but sometimes it will not working, but sometimes workings well.
This function is to check cart is exist or not.
protected function Check_Cart() {
$this->cart_no = MDL_Cart::get_session_cart_no($this->company_no, $this->group_buy_no);
if($this->cart_no === '') {
MDL_Cart::Add_new_cart();
}
}
and I will call this funcrion first to check cart is exist in session or not.
protected function Request_Get_Cart_All_Data() {
$check_cart = $this->Check_Cart();
// ...
}
Then I will use this function to get session
protected function Get_Cart_Order_Type() {
$cart_no = MDL_Cart::get_session_cart_no($this->company_no, $this->group_buy_no);
// ...
}
And I use this method to store my session.
Add_new_cart() {
Session::forget('group_cart_data.' . $company_no);
Session::put('group_cart_data.' . $company_no, $cart_no);
Session::save();
}
public static function get_session_cart_no($company_no, $group_buy_no = null) {
if ($group_buy_no) {
return Session::get('group_cart_data.' . $company_no);
} else {
return Session::get('cart_data.' . $company_no);
}
}
When I get session, only Request_Get_Cart_All_Data() has the session, but Get_Cart_Order_Type() cannot get the same session, why?
I’m sure that the session is been writed at Request_Get_Cart_All_Data() because I print the session out to look.