Skip to content

Commit

Permalink
Add rule based condition, PFWMA-266
Browse files Browse the repository at this point in the history
  • Loading branch information
kcppdevelopers committed Jan 3, 2022
1 parent bd1329d commit a367b89
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,56 @@ public function angelleye_get_account_for_ec_parallel_payments($gateways, $gatew
if (empty($passed_rules['buyer_countries'])) {
continue;
}



$buyer_states = get_post_meta($value->ID, 'buyer_states', true);
if (!empty($buyer_states)) {
foreach ($buyer_states as $buyer_states_key => $buyer_states_value) {
if (!empty($order_id) && $order_id > 0) {
$order = wc_get_order($order_id);
$billing_state = version_compare(WC_VERSION, '3.0', '<') ? $order->billing_state : $order->get_billing_state();
$shipping_state = version_compare(WC_VERSION, '3.0', '<') ? $order->shipping_state : $order->get_shipping_state();
if (!empty($billing_state) && $billing_state == $buyer_states_value) {
$passed_rules['buyer_states'] = true;
break;
} elseif (!empty($shipping_state) && $shipping_state == $buyer_states_value) {
$passed_rules['buyer_states'] = true;
break;
}
} else {
$post_checkout_data = WC()->session->get('post_data');
if (empty($post_checkout_data)) {
$billing_state = version_compare(WC_VERSION, '3.0', '<') ? WC()->customer->get_state() : WC()->customer->get_billing_state();
$shipping_state = version_compare(WC_VERSION, '3.0', '<') ? WC()->customer->get_state() : WC()->customer->get_shipping_state();
if (!empty($billing_state) && $billing_state == $buyer_states_value) {
$passed_rules['buyer_states'] = true;
break;
} elseif (!empty($shipping_state) && $shipping_state == $buyer_states_value) {
$passed_rules['buyer_states'] = true;
break;
}
} else {
if (!empty($post_checkout_data['billing_state']) && $post_checkout_data['billing_state'] == $buyer_states_value) {
$passed_rules['buyer_states'] = true;
break;
} elseif (!empty($post_checkout_data['shipping_state']) && $post_checkout_data['shipping_state'] == $buyer_states_value) {
$passed_rules['buyer_states'] = true;
break;
}
}
}
}
} else {
$passed_rules['buyer_states'] = true;
}
if (empty($passed_rules['buyer_states'])) {
continue;
}




$postcode_string = get_post_meta($value->ID, 'postcode', true);
if (!empty($postcode_string)) {
$postcode = explode(',', $postcode_string);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,32 @@ public function angelleye_get_multi_account_by_order_total_latest($gateways, $ga
unset($passed_rules);
continue;
}


$buyer_states = get_post_meta($value->ID, 'buyer_states', true);
if (!empty($buyer_states)) {
foreach ($buyer_states as $buyer_states_key => $buyer_states_value) {
if (!empty($gateway_setting->id) && $gateway_setting->id == 'paypal_pro_payflow') {
if (!empty($order_id) && $order_id > 0) {
$order = wc_get_order($order_id);
$billing_state = version_compare(WC_VERSION, '3.0', '<') ? $order->billing_state : $order->get_billing_state();
$shipping_state = version_compare(WC_VERSION, '3.0', '<') ? $order->shipping_state : $order->get_shipping_state();
if (!empty($billing_state) && $billing_state == $buyer_states_value) {
$passed_rules['buyer_states'] = true;
} elseif (!empty($shipping_state) && $shipping_state == $buyer_states_value) {
$passed_rules['buyer_states'] = true;
}
}
}
}
} else {
$passed_rules['buyer_states'] = true;
}
if (empty($passed_rules['buyer_states'])) {
unset($result[$key]);
unset($passed_rules);
continue;
}

$postcode_string = get_post_meta($value->ID, 'postcode', true);
if (!empty($postcode_string)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,34 @@ public function angelleye_woocommerce_paypal_args($request, $order) {
unset($passed_rules);
continue;
}

$buyer_states = get_post_meta($value->ID, 'buyer_states', true);
if (!empty($buyer_states)) {
foreach ($buyer_states as $buyer_states_key => $buyer_states_value) {
if (!empty($gateway_setting->id) && $gateway_setting->id == 'paypal') {
if (!empty($order_id) && $order_id > 0) {
$order = wc_get_order($order_id);
$billing_state = version_compare(WC_VERSION, '3.0', '<') ? $order->billing_state : $order->get_billing_state();
$shipping_state = version_compare(WC_VERSION, '3.0', '<') ? $order->shipping_state : $order->get_shipping_state();
if (!empty($billing_state) && $billing_state == $buyer_states_value) {
$passed_rules['buyer_states'] = true;
break;
} elseif(!empty($shipping_state) && $shipping_state == $buyer_states_value) {
$passed_rules['buyer_states'] = true;
break;
}
}
}
}
} else {
$passed_rules['buyer_states'] = true;
}
if (empty($passed_rules['buyer_states'])) {
unset($result[$key]);
unset($passed_rules);
continue;
}

$postcode_string = get_post_meta($value->ID, 'postcode', true);
if (!empty($postcode_string)) {
$postcode = explode(',', $postcode_string);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ jQuery( "#angelleye_multi_account" ).submit(function( event ) {
return true;
}
var total_not_empty_fields = 0;
var paypal_express_field_names = [ "woocommerce_priority", "woocommerce_paypal_express_api_user_role", "woocommerce_paypal_express_api_user", "buyer_countries", "store_countries", "pfwst_shipping_class", "product_categories", "product_tags", "product_list", "woocommerce_paypal_express_api_condition_value", "currency_code", "card_type", "postcode" ];
var paypal_express_field_names = [ "woocommerce_priority", "woocommerce_paypal_express_api_user_role", "woocommerce_paypal_express_api_user", "buyer_countries", "buyer_states", "store_countries", "pfwst_shipping_class", "product_categories", "product_tags", "product_list", "woocommerce_paypal_express_api_condition_value", "currency_code", "card_type", "postcode" ];
jQuery.each( paypal_express_field_names, function( i, name ) {
if( jQuery('#' + name).val() !== '' && jQuery('#' + name).val() !== 'all' && jQuery('#' + name).val() !== '0' && jQuery('#' + name).val() !== null && jQuery('#' + name).val() !== undefined) {
total_not_empty_fields = total_not_empty_fields + 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ function column_default($item, $column_name) {
$other_condition = '<p class="description">' . sprintf('When Buyer country is %s', implode(',', $buyer_countries)) . '</p>';
}
}
$buyer_states = get_post_meta($item['ID'], 'buyer_states', true);
if ($buyer_states) {
if ($buyer_states != 'all') {
$other_condition .= '<p class="description">' . sprintf('When Buyer state is %s', implode(',', $buyer_states)) . '</p>';
}
}
$postcode = get_post_meta($item['ID'], 'postcode', true);
if (!empty($postcode)) {
$other_condition .= '<p class="description">' . sprintf('When Buyer Postal/Zip Code %s', $postcode) . '</p>';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public function angelleye_paypal_for_woocommerce_multi_account_rule_save_dokan($
'product_categories' => '',
'product_tags' => '',
'buyer_countries' => '',
'buyer_states' => '',
'woocommerce_priority' => '',
'angelleye_multi_account_choose_payment_gateway' => 'paypal_express',
'store_countries' => '',
Expand Down Expand Up @@ -195,6 +196,7 @@ public function angelleye_paypal_for_woocommerce_multi_account_rule_save_wc_vend
'product_categories' => '',
'product_tags' => '',
'buyer_countries' => '',
'buyer_states' => '',
'woocommerce_priority' => '',
'angelleye_multi_account_choose_payment_gateway' => 'paypal_express',
'store_countries' => '',
Expand Down

0 comments on commit a367b89

Please sign in to comment.