Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP error Call to a member function get() on null, PFW-664 #1477

Merged
merged 4 commits into from
Jul 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions angelleye-includes/angelleye-conditional-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@
* @return bool
*/
function is_angelleye_ec_review_page() {
if (!class_exists('WooCommerce') || WC()->session == null) {
return false;
}
$paypal_express_checkout = WC()->session->get('paypal_express_checkout');
$paypal_express_checkout = angelleye_get_session('paypal_express_checkout');
if (isset($paypal_express_checkout['token']) && !empty($paypal_express_checkout['token']) && isset($paypal_express_checkout['payer_id']) && !empty($paypal_express_checkout['payer_id'])) {
return true;
} else {
Expand Down
66 changes: 66 additions & 0 deletions angelleye-includes/angelleye-session-functions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fantastic Job @kcppdevelopers
I like this function file to handle the sessions.


if (!function_exists('angelleye_set_session')) {

function angelleye_set_session($key, $value) {
try {
if (!class_exists('WooCommerce') || !function_exists('WC')) {
return false;
}
if (WC()->session == null) {
WC()->initialize_session();
}
if (WC()->session) {
WC()->session->set($key, $value);
} else {
return false;
}
} catch (Exception $ex) {

}
}

}
if (!function_exists('angelleye_get_session')) {

function angelleye_get_session($key) {
try {
if (!class_exists('WooCommerce') || !function_exists('WC')) {
return false;
}
if (WC()->session == null) {
WC()->initialize_session();
}
if (WC()->session) {
$angelleye_session = WC()->session->get($key);
return $angelleye_session;
} else {
return false;
}
} catch (Exception $ex) {

}
}

}
if (!function_exists('angelleye_unset_session')) {

try {

function angelleye_unset_session($key) {
if (!class_exists('WooCommerce') || !function_exists('WC')) {
return false;
}
if (WC()->session == null) {
WC()->initialize_session();
}
if (WC()->session) {
WC()->session->__unset($key);
unset(WC()->session->$key);
}
}

} catch (Exception $ex) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function maybe_handle_paypal_express_api_call() {
}

function angelleye_express_checkout_cartflow($bool) {
$post_data = WC()->session->get('post_data');
$post_data = angelleye_get_session('post_data');
if (!empty($post_data)) {
if (!empty($post_data['_wcf_flow_id'])) {
$order_bump = get_post_meta($post_data['_wcf_checkout_id'], 'wcf-pre-checkout-offer', true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ public function ec_get_checkout_url($action) {
}

public function ec_is_express_checkout() {
if ( ! class_exists( 'WooCommerce' ) || WC()->session == null ) {
return false;
}
$paypal_express_checkout = WC()->session->get( 'paypal_express_checkout' );
$paypal_express_checkout = angelleye_get_session( 'paypal_express_checkout' );
if( isset($paypal_express_checkout['token']) && !empty($paypal_express_checkout['token']) && isset($paypal_express_checkout['payer_id']) && !empty($paypal_express_checkout['payer_id']) ) {
return true;
} else {
Expand All @@ -63,7 +60,7 @@ public function ec_redirect_after_checkout() {
'redirect' => $this->ec_get_checkout_url('set_express_checkout'),
);
if ((isset($_POST['terms']) || isset($_POST['legal'])) && wc_get_page_id('terms') > 0) {
WC()->session->set( 'paypal_express_terms', 1);
angelleye_set_session( 'paypal_express_terms', 1);
}
if (is_ajax()) {
if ($this->ec_is_version_gte_2_4()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ public function add_to_cart_redirect($url = null) {
if (isset($_REQUEST['express_checkout']) || isset($_REQUEST['express_checkout_x'])) {
wc_clear_notices();
if ((isset($_POST['wc-paypal_express-new-payment-method']) && $_POST['wc-paypal_express-new-payment-method'] == 'true') || ( isset($_GET['ec_save_to_account']) && $_GET['ec_save_to_account'] == true)) {
WC()->session->set('ec_save_to_account', 'on');
angelleye_set_session('ec_save_to_account', 'on');
} else {
unset(WC()->session->ec_save_to_account);
}
Expand All @@ -354,10 +354,7 @@ public function add_to_cart_redirect($url = null) {

public function ec_get_session_data($key = '') {
try {
if (!class_exists('WooCommerce') || WC()->session == null) {
return false;
}
$session_data = WC()->session->get('paypal_express_checkout');
$session_data = angelleye_get_session('paypal_express_checkout');
if (isset($session_data[$key])) {
$session_data = $session_data[$key];
}
Expand All @@ -380,7 +377,7 @@ public function ec_set_checkout_post_data() {
if (!$this->function_helper->ec_is_express_checkout() || !$this->ec_get_session_data('shipping_details')) {
return;
}
$post_data = WC()->session->get('post_data');
$post_data = angelleye_get_session('post_data');
foreach ($this->ec_get_session_data('shipping_details') as $field => $value) {
if (!empty($value)) {
if ('state' == $field) {
Expand Down Expand Up @@ -534,10 +531,10 @@ public function ec_add_body_class($classes) {
if (!class_exists('WooCommerce') || WC()->session == null) {
return $classes;
}
$paypal_express_terms = WC()->session->get('paypal_express_terms');
$paypal_express_terms = angelleye_get_session('paypal_express_terms');
if ($this->ec_is_checkout() && $this->function_helper->ec_is_express_checkout()) {
$classes[] = 'express-checkout';
if ($this->show_on_checkout && isset($paypal_express_terms)) {
if ($this->show_on_checkout && $paypal_express_terms === true) {
$classes[] = 'express-hide-terms';
}
}
Expand All @@ -560,8 +557,8 @@ public function ec_terms_express_checkout($checked_default) {
if (!$this->ec_is_available() || !$this->function_helper->ec_is_express_checkout()) {
return $checked_default;
}
$paypal_express_terms = WC()->session->get('paypal_express_terms');
if ($this->show_on_checkout && isset($paypal_express_terms)) {
$paypal_express_terms = angelleye_get_session('paypal_express_terms');
if ($this->show_on_checkout && $paypal_express_terms === true) {
$checked_default = true;
}
return $checked_default;
Expand All @@ -583,7 +580,7 @@ public function ec_is_checkout() {
}

public function ec_order_received_text($text, $order) {
$held_order_received_text = WC()->session->get('held_order_received_text');
$held_order_received_text = angelleye_get_session('held_order_received_text');
if ($order && $order->has_status('on-hold') && isset($held_order_received_text)) {
$text = $held_order_received_text;
unset(WC()->session->held_order_received_text);
Expand Down Expand Up @@ -957,7 +954,7 @@ public function angelleye_ship_to_different_address_checked($bool) {
if (!class_exists('WooCommerce') || WC()->session == null) {
return $bool;
}
$post_data = WC()->session->get('post_data');
$post_data = angelleye_get_session('post_data');
if (!empty($post_data['ship_to_different_address']) && $post_data['ship_to_different_address'] == '1') {
return 1;
}
Expand Down Expand Up @@ -1048,7 +1045,7 @@ public function wc_ajax_update_shipping_costs() {
WC()->shipping->reset_shipping();
WC()->cart->calculate_totals();
if ((isset($_POST['wc-paypal_express-new-payment-method']) && $_POST['wc-paypal_express-new-payment-method'] == 'true') || ( isset($_GET['ec_save_to_account']) && $_GET['ec_save_to_account'] == true)) {
WC()->session->set('ec_save_to_account', 'on');
angelleye_set_session('ec_save_to_account', 'on');
} else {
unset(WC()->session->ec_save_to_account);
}
Expand All @@ -1068,7 +1065,7 @@ public function angelleye_ajax_generate_cart() {
$url = add_query_arg('ec_save_to_account', 'true', $url);
}
if ((isset($_POST['wc-paypal_express-new-payment-method']) && $_POST['wc-paypal_express-new-payment-method'] == 'true') || ( isset($_GET['ec_save_to_account']) && $_GET['ec_save_to_account'] == true)) {
WC()->session->set( 'ec_save_to_account', 'on' );
angelleye_set_session( 'ec_save_to_account', 'on' );
$url = add_query_arg('ec_save_to_account', 'true', $url);
} else {
unset(WC()->session->ec_save_to_account);
Expand Down Expand Up @@ -1155,7 +1152,7 @@ public function angelleye_paypal_for_woocommerce_page_title($page_title) {
if (!class_exists('WooCommerce') || WC()->session == null) {
return $page_title;
}
$paypal_express_checkout = WC()->session->get('paypal_express_checkout');
$paypal_express_checkout = angelleye_get_session('paypal_express_checkout');
if (!is_admin() && is_main_query() && in_the_loop() && is_page() && is_checkout() && !empty($paypal_express_checkout)) {
remove_filter('the_title', array($this, 'angelleye_paypal_for_woocommerce_page_title'));
return $this->review_title_page;
Expand Down Expand Up @@ -1382,7 +1379,7 @@ public function angelleye_ec_force_to_display_checkout_page_js() {
if (AngellEYE_Utility::is_cart_contains_subscription() == true) {
return apply_filters('angelleye_ec_force_to_display_checkout_page', true);
}
$paypal_express_terms = WC()->session->get('paypal_express_terms');
$paypal_express_terms = angelleye_get_session('paypal_express_terms');
if (wc_get_page_id('terms') > 0 && apply_filters('woocommerce_checkout_show_terms', true)) {
if ($this->disable_term) {
return apply_filters('angelleye_ec_force_to_display_checkout_page', false);
Expand Down
Loading