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

Woo Checkout Add-Ons Compatibility : PFW-614 #1455

Merged
merged 2 commits into from
May 7, 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
Original file line number Diff line number Diff line change
Expand Up @@ -145,5 +145,6 @@ function ec_clear_session_data() {
unset(WC()->session->post_data);
unset(WC()->session->shiptoname);
unset(WC()->session->payeremail);
unset(WC()->session->validate_data);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,7 @@ public function ec_clear_session_data() {
unset(WC()->session->post_data);
unset(WC()->session->shiptoname);
unset(WC()->session->payeremail);
unset(WC()->session->validate_data);
}

public function ec_is_checkout() {
Expand Down
67 changes: 45 additions & 22 deletions classes/wc-gateway-paypal-express-angelleye.php
Original file line number Diff line number Diff line change
Expand Up @@ -2304,35 +2304,45 @@ public function handle_wc_api() {
} else {
if ( $order_id > 0 && ( $order = wc_get_order( $order_id ) ) && $order->has_status( array( 'pending', 'failed' ) ) ) {
$_POST = WC()->session->get( 'post_data' );
$_POST['post_data'] = WC()->session->get( 'post_data' );
$this->posted = WC()->session->get( 'post_data' );
$chosen_shipping_methods = WC()->session->get('chosen_shipping_methods');
if (isset($_POST['shipping_method']) && is_array($_POST['shipping_method']))
foreach ($_POST['shipping_method'] as $i => $value)
foreach ($_POST['shipping_method'] as $i => $value) {
$chosen_shipping_methods[$i] = wc_clean($value);
WC()->session->set('chosen_shipping_methods', $chosen_shipping_methods);
if (WC()->cart->needs_shipping()) {
// Validate Shipping Methods
WC()->shipping->get_shipping_methods();
$packages = WC()->shipping->get_packages();
WC()->checkout()->shipping_methods = WC()->session->get('chosen_shipping_methods');
}
if (empty($this->posted)) {
$this->posted = array();
$paypal_express_checkout = WC()->session->get( 'paypal_express_checkout' );
if( !empty($paypal_express_checkout['shipping_details']['email'])) {
$this->posted['billing_email'] = $paypal_express_checkout['shipping_details']['email'];
}
if( !empty($paypal_express_checkout['shipping_details']['first_name'])) {
$this->posted['billing_first_name'] = $paypal_express_checkout['shipping_details']['first_name'];
}
if( !empty($paypal_express_checkout['shipping_details']['last_name'])) {
$this->posted['billing_last_name'] = $paypal_express_checkout['shipping_details']['last_name'];
WC()->session->set('chosen_shipping_methods', $chosen_shipping_methods);
if (WC()->cart->needs_shipping()) {
// Validate Shipping Methods
WC()->shipping->get_shipping_methods();
$packages = WC()->shipping->get_packages();
WC()->checkout()->shipping_methods = WC()->session->get('chosen_shipping_methods');
}
$this->posted['payment_method'] = $this->id;
if (empty($this->posted)) {
$this->posted = array();
$paypal_express_checkout = WC()->session->get( 'paypal_express_checkout' );
if( !empty($paypal_express_checkout['shipping_details']['email'])) {
$this->posted['billing_email'] = $paypal_express_checkout['shipping_details']['email'];
}
if( !empty($paypal_express_checkout['shipping_details']['first_name'])) {
$this->posted['billing_first_name'] = $paypal_express_checkout['shipping_details']['first_name'];
}
if( !empty($paypal_express_checkout['shipping_details']['last_name'])) {
$this->posted['billing_last_name'] = $paypal_express_checkout['shipping_details']['last_name'];
}
$this->posted['payment_method'] = $this->id;

}
}

$this->angelleye_check_cart_items();
$order_id = WC()->checkout()->create_order($this->posted);

$validate_data = WC()->session->get( 'validate_data' );
WC()->cart->calculate_totals();
if( !empty($validate_data) ) {
$order_id = WC()->checkout()->create_order($validate_data);
} else {
$order_id = WC()->checkout()->create_order($this->posted);
}

if (is_wp_error($order_id)) {
throw new Exception($order_id->get_error_message());
Expand All @@ -2347,10 +2357,12 @@ public function handle_wc_api() {
do_action('woocommerce_checkout_order_processed', $order_id, $this->posted, $order);
} else {
$_POST = WC()->session->get( 'post_data' );
$_POST['post_data'] = WC()->session->get( 'post_data' );
$this->posted = WC()->session->get( 'post_data' );
}
if ( $order_id == 0 ) {
$_POST = WC()->session->get( 'post_data' );
$_POST['post_data'] = WC()->session->get( 'post_data' );
$this->posted = WC()->session->get( 'post_data' );
$chosen_shipping_methods = WC()->session->get('chosen_shipping_methods');
if (isset($_POST['shipping_method']) && is_array($_POST['shipping_method']))
Expand Down Expand Up @@ -2384,7 +2396,17 @@ public function handle_wc_api() {
$this->posted['payment_method'] = $this->id;
}
$this->angelleye_check_cart_items();
$order_id = WC()->checkout()->create_order($this->posted);

$validate_data = WC()->session->get( 'validate_data' );

WC()->cart->calculate_totals();

if( !empty($validate_data) ) {
$order_id = WC()->checkout()->create_order($validate_data);
} else {
$order_id = WC()->checkout()->create_order($this->posted);
}

if (is_wp_error($order_id)) {
throw new Exception($order_id->get_error_message());
}
Expand Down Expand Up @@ -2853,6 +2875,7 @@ public function angelleye_paypal_express_checkout_redirect_to_paypal($data, $err
if (empty($_POST['woocommerce_checkout_update_totals']) && 0 === $notice_count) {
try {
WC()->session->set('post_data', wp_slash($_POST));
WC()->session->set('validate_data', $data);
if ( isset( $_POST['from_checkout'] ) && 'yes' === $_POST['from_checkout'] ) {
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' );
Expand Down