Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
kcppdevelopers committed May 22, 2020
2 parents e5f4baa + 49d8fb9 commit 7895fa7
Show file tree
Hide file tree
Showing 3 changed files with 257 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,14 @@ function column_default($item, $column_name) {
$user_info = '';
if ($condition_user) {
if ($condition_user != 'all') {
$user_info = '<p class="description">' . sprintf('When User ID is %s', $condition_user) . '</p>';
$user = get_user_by( 'id', $condition_user );
$user_string = sprintf(
esc_html__( '%1$s (#%2$s %3$s)', 'woocommerce' ),
$user->display_name,
absint( $user->ID ),
$user->user_email
);
$user_info = '<p class="description">' . sprintf('When Author is %s', $user_string) . '</p>';
}
}
$other_condition = '';
Expand Down Expand Up @@ -76,7 +83,7 @@ function column_default($item, $column_name) {

add_thickbox();
$product_text = '';
if (!empty($product_ids)) {
if (!empty($product_ids) && is_array($product_ids)) {
$products = $product_ids;
$product_text .= '<a href="#TB_inline?width=600&height=550&inlineId=modal-window-' . esc_attr($item['ID']) . '" class="thickbox" title="Products added in Trigger Condition">Products</a>';
$product_text .= '<div id="modal-window-' . esc_attr($item['ID']) . '" style="display:none;">';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,238 @@
<?php

/**
* This class defines all code necessary to run during the plugin's activation.
*
* @since 1.0.0
* @package Paypal_For_Woocommerce_Multi_Account_Management
* @subpackage Paypal_For_Woocommerce_Multi_Account_Management/includes
* @author Angell EYE <[email protected]>
*/
class Paypal_For_Woocommerce_Multi_Account_Management_Vendor {

private $plugin_name;
private $version;

public function __construct($plugin_name, $version) {
$this->plugin_name = $plugin_name;
$this->version = $version;
}

public function angelleye_paypal_for_woocommerce_multi_account_rule_save_dokan($vendor_id) {
try {
if (function_exists('dokan')) {
if (!dokan_is_user_seller($vendor_id)) {
return;
}
$post_id = $this->angelleye_is_vendor_account_exist($vendor_id);
if ($post_id != false) {
$user = get_user_by('id', $vendor_id);
$dokan_profile_settings = get_user_meta($vendor_id, 'dokan_profile_settings', true);
if( !empty($dokan_profile_settings['payment']['paypal']['email'])) {
$email = $dokan_profile_settings['payment']['paypal']['email'];
}
if (empty($email)) {
$email = get_user_meta($vendor_id, 'billing_email', true);
}
if (empty($email)) {
$email = $user->user_email;
}
if (!empty($email)) {
update_post_meta($post_id, 'woocommerce_paypal_express_sandbox_email', $email);
update_post_meta($post_id, 'woocommerce_paypal_express_email', $email);
}
$user_string = sprintf(
esc_html__('%1$s (#%2$s %3$s)', 'woocommerce'), $user->display_name, absint($user->ID), $user->user_email
);
$woocommerce_paypal_express_account_name = get_post_meta($post_id, 'woocommerce_paypal_express_account_name', true);
if (empty($woocommerce_paypal_express_account_name)) {
update_post_meta($post_id, 'woocommerce_paypal_express_account_name', $user_string);
}
} else {
$user = get_user_by('id', $vendor_id);
$user_string = sprintf(
esc_html__('%1$s (#%2$s %3$s)', 'woocommerce'), $user->display_name, absint($user->ID), $user->user_email
);
$my_post = array(
'post_title' => $user_string,
'post_content' => '',
'post_status' => 'publish',
'post_author' => $vendor_id,
'post_type' => 'microprocessing'
);
$post_id = wp_insert_post($my_post);
$email = get_user_meta($vendor_id, 'pv_paypal', true);
if (empty($email)) {
$email = get_user_meta($vendor_id, 'billing_email', true);
}
if (empty($email)) {
$user = get_user_by('id', $vendor_id);
$email = $user->user_email;
}
$microprocessing_key_array = array(
'woocommerce_paypal_express_enable' => 'on',
'woocommerce_paypal_express_testmode' => 'on',
'woocommerce_paypal_express_account_name' => $user_string,
'woocommerce_paypal_express_sandbox_email' => $email,
'woocommerce_paypal_express_sandbox_merchant_id' => '',
'woocommerce_paypal_express_sandbox_api_username' => '',
'woocommerce_paypal_express_sandbox_api_password' => '',
'woocommerce_paypal_express_sandbox_api_signature' => '',
'woocommerce_paypal_express_email' => $email,
'woocommerce_paypal_express_merchant_id' => '',
'woocommerce_paypal_express_api_username' => '',
'woocommerce_paypal_express_api_password' => '',
'woocommerce_paypal_express_api_signature' => '',
'woocommerce_paypal_express_api_condition_field' => 'transaction_amount',
'woocommerce_paypal_express_api_condition_sign' => 'greaterthan',
'woocommerce_paypal_express_api_condition_value' => '0',
'woocommerce_paypal_express_api_user_role' => 'all',
'woocommerce_paypal_express_api_user' => $vendor_id,
'woocommerce_paypal_express_api_product_ids' => 'a:0:{}',
'product_categories' => '',
'product_tags' => '',
'buyer_countries' => '',
'woocommerce_priority' => '',
'angelleye_multi_account_choose_payment_gateway' => 'paypal_express',
'store_countries' => '',
'shipping_class' => 'all',
'currency_code' => '',
'ec_site_owner_commission' => '',
'ec_site_owner_commission_label' => ''
);
foreach ($microprocessing_key_array as $key => $value) {
update_post_meta($post_id, $key, $value);
}
update_post_meta($post_id, 'vendor_id', $vendor_id);
}
}
} catch (Exception $ex) {

}
}

public function angelleye_paypal_for_woocommerce_multi_account_rule_save_wc_vendor($vendor_id) {
try {
if (class_exists('WCV_Vendors')) {
if (!WCV_Vendors::is_pending($vendor_id) && !WCV_Vendors::is_vendor($vendor_id)) {
return;
}
$post_id = $this->angelleye_is_vendor_account_exist($vendor_id);
if ($post_id != false) {
$user = get_user_by('id', $vendor_id);
$email = get_user_meta($vendor_id, 'pv_paypal', true);
if (empty($email)) {
$email = get_user_meta($vendor_id, 'billing_email', true);
}
if (empty($email)) {
$email = $user->user_email;
}
if (!empty($email)) {
update_post_meta($post_id, 'woocommerce_paypal_express_sandbox_email', $email);
update_post_meta($post_id, 'woocommerce_paypal_express_email', $email);
}
$user_string = sprintf(
esc_html__('%1$s (#%2$s %3$s)', 'woocommerce'), $user->display_name, absint($user->ID), $user->user_email
);
$woocommerce_paypal_express_account_name = get_post_meta($post_id, 'woocommerce_paypal_express_account_name', true);
if (empty($woocommerce_paypal_express_account_name)) {
update_post_meta($post_id, 'woocommerce_paypal_express_account_name', $user_string);
}
} else {
$user = get_user_by('id', $vendor_id);
$user_string = sprintf(
esc_html__('%1$s (#%2$s %3$s)', 'woocommerce'), $user->display_name, absint($user->ID), $user->user_email
);
$my_post = array(
'post_title' => $user_string,
'post_content' => '',
'post_status' => 'publish',
'post_author' => $vendor_id,
'post_type' => 'microprocessing'
);
$post_id = wp_insert_post($my_post);
$email = get_user_meta($vendor_id, 'pv_paypal', true);
if (empty($email)) {
$email = get_user_meta($vendor_id, 'billing_email', true);
}
if (empty($email)) {
$user = get_user_by('id', $vendor_id);
$email = $user->user_email;
}
$microprocessing_key_array = array(
'woocommerce_paypal_express_enable' => 'on',
'woocommerce_paypal_express_testmode' => 'on',
'woocommerce_paypal_express_account_name' => $user_string,
'woocommerce_paypal_express_sandbox_email' => $email,
'woocommerce_paypal_express_sandbox_merchant_id' => '',
'woocommerce_paypal_express_sandbox_api_username' => '',
'woocommerce_paypal_express_sandbox_api_password' => '',
'woocommerce_paypal_express_sandbox_api_signature' => '',
'woocommerce_paypal_express_email' => $email,
'woocommerce_paypal_express_merchant_id' => '',
'woocommerce_paypal_express_api_username' => '',
'woocommerce_paypal_express_api_password' => '',
'woocommerce_paypal_express_api_signature' => '',
'woocommerce_paypal_express_api_condition_field' => 'transaction_amount',
'woocommerce_paypal_express_api_condition_sign' => 'greaterthan',
'woocommerce_paypal_express_api_condition_value' => '0',
'woocommerce_paypal_express_api_user_role' => 'all',
'woocommerce_paypal_express_api_user' => $vendor_id,
'woocommerce_paypal_express_api_product_ids' => 'a:0:{}',
'product_categories' => '',
'product_tags' => '',
'buyer_countries' => '',
'woocommerce_priority' => '',
'angelleye_multi_account_choose_payment_gateway' => 'paypal_express',
'store_countries' => '',
'shipping_class' => 'all',
'currency_code' => '',
'ec_site_owner_commission' => '',
'ec_site_owner_commission_label' => ''
);
foreach ($microprocessing_key_array as $key => $value) {
update_post_meta($post_id, $key, $value);
}
update_post_meta($post_id, 'vendor_id', $vendor_id);
}
}
} catch (Exception $ex) {

}
}

public function angelleye_paypal_for_woocommerce_multi_account_rule_save($vendor_id) {
try {
$dokan_profile_settings = get_user_meta($vendor_id, 'dokan_profile_settings', true);
if (!empty($dokan_profile_settings)) {
$this->angelleye_paypal_for_woocommerce_multi_account_rule_save_dokan($vendor_id);
} else {
$this->angelleye_paypal_for_woocommerce_multi_account_rule_save_wc_vendor($vendor_id);
}
} catch (Exception $ex) {

}
}

public function angelleye_is_vendor_account_exist($vendor_id) {
$args = array(
'post_type' => 'microprocessing',
'meta_query' => array(
array(
'key' => 'vendor_id',
'value' => $vendor_id
)
),
'fields' => 'ids'
);
$query = new WP_Query($args);
$duplicates = $query->posts;
if (!empty($duplicates)) {
if (!empty($query->posts[0])) {
return $query->posts[0];
}
}
return false;
}

}
10 changes: 10 additions & 0 deletions includes/class-paypal-for-woocommerce-multi-account-management.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ private function load_dependencies() {
require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-paypal-for-woocommerce-multi-account-management-wp-list-table.php';
require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-paypal-for-woocommerce-multi-account-management-list-data.php';
require_once plugin_dir_path(dirname(__FILE__)) . 'includes/angelleye-multi-account-function.php';
require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-paypal-for-woocommerce-multi-account-management-vendor.php';



Expand Down Expand Up @@ -182,6 +183,15 @@ private function define_admin_hooks() {
//$this->loader->add_filter('woocommerce_paypal_args', $paypal, 'angelleye_woocommerce_paypal_args', 10, 2);
$this->loader->add_action('woocommerce_create_refund', $express_checkout, 'own_woocommerce_create_refund', 10, 2);
$this->loader->add_filter('angelleye_multi_account_need_shipping', $express_checkout, 'own_angelleye_multi_account_need_shipping', 10, 3);

$vendor = new Paypal_For_Woocommerce_Multi_Account_Management_Vendor($this->get_plugin_name(), $this->get_version());
$this->loader->add_action('personal_options_update', $vendor, 'angelleye_paypal_for_woocommerce_multi_account_rule_save');
$this->loader->add_action('edit_user_profile_update', $vendor, 'angelleye_paypal_for_woocommerce_multi_account_rule_save');
$this->loader->add_action('user_register', $vendor, 'angelleye_paypal_for_woocommerce_multi_account_rule_save');
$this->loader->add_action('profile_update', $vendor, 'angelleye_paypal_for_woocommerce_multi_account_rule_save');
$this->loader->add_action('wcv_pro_store_settings_saved', $vendor, 'angelleye_paypal_for_woocommerce_multi_account_rule_save');
$this->loader->add_action('dokan_new_seller_created', $vendor, 'angelleye_paypal_for_woocommerce_multi_account_rule_save');
$this->loader->add_action('dokan_store_profile_saved', $vendor, 'angelleye_paypal_for_woocommerce_multi_account_rule_save');
}

/**
Expand Down

0 comments on commit 7895fa7

Please sign in to comment.