reseller to customer

This commit is contained in:
Almira Krdzic
2018-10-16 06:45:28 +02:00
parent b7ac53d195
commit afab22a30b
37 changed files with 852 additions and 152 deletions

View File

@@ -13,14 +13,17 @@ class Wiaas_Customer {
public static function get_customer_info($customer_id){
$user = get_userdata($customer_id);
$organization_id = wiaas_get_user_organization_id($customer_id);
$result = array(
'id' => $customer_id,
'company_id' => self::get_customer_company_id($customer_id),
'company_id' => $organization_id,
'is_company_admin' => self::get_customer_company_admin_status($customer_id),
'mail' => $user->user_email,
'name' => $user->first_name . ' ' . $user->last_name,
'phone' => self::get_customer_phone_number($customer_id),
'company_name' => self::get_customer_company_name($customer_id),
'company_name' => wiaas_get_organization_name($organization_id),
'vat_code' => self::get_customer_vat_code($customer_id),
'billing_addresses' => self::get_customer_billing_addresses($customer_id),
'profile_addresses' => self::get_customer_profile_addresses($customer_id),
@@ -80,10 +83,6 @@ class Wiaas_Customer {
return get_user_meta($customer_id, 'company_name', true) ?: '';
}
public static function get_customer_company_id($customer_id){
return 0; //TODO: don't hardocde this
}
public static function get_customer_company_admin_status($customer_id){
return 1; //TODO: don't hardcode this
}

View File

@@ -36,6 +36,10 @@ class Wiaas_User_Organization extends WP_User_Taxonomy {
add_action( 'created_' . self::TAXONOMY_NAME, array( __CLASS__, 'on_organization_added' ));
add_action( 'pre_delete_term', array( __CLASS__, 'on_taxonomy_term_will_be_deleted' ), 10, 2);
add_action( 'delete_' . self::TAXONOMY_NAME, array( __CLASS__, 'on_organization_deleted' ));
add_action('acf/save_post', array(__CLASS__, 'on_organization_roles_maybe_updated'));
add_action('set_object_terms', array( __CLASS__, 'on_taxonomy_term_assigned' ), 10, 4);
add_action('deleted_term_relationships', array( __CLASS__, 'on_taxonomy_term_unassigned' ), 10, 3);
@@ -61,6 +65,8 @@ class Wiaas_User_Organization extends WP_User_Taxonomy {
*/
public static function on_organization_added($organization_id) {
self::_create_organization_access_group($organization_id);
do_action('wiaas_organization_created', $organization_id);
}
/**
@@ -73,9 +79,37 @@ class Wiaas_User_Organization extends WP_User_Taxonomy {
if ($taxonomy === self::TAXONOMY_NAME) {
$organization_id = $term_id;
self::_remove_organization_access_group($organization_id);
do_action('wiaas_organization_will_be_deleted', $organization_id);
}
}
/**
* Removes corresponding acces group when organization term is deleted
*
* @param $organization_id id of the organization term
*/
public static function on_organization_deleted($organization_id) {
do_action('wiaas_organization_deleted', $organization_id);
}
/**
* @param string $id acf object id for which data has been updated,
* for organization it will be in format `term_{$organization_id}`
*/
public static function on_organization_roles_maybe_updated($id) {
if ($_POST['taxonomy'] === self::TAXONOMY_NAME) {
$roles = get_field('_wiaas_organization_roles', $id);
//get organization id
$id = absint(str_replace('term_', '', $id));
do_action('wiaas_organization_roles_updated', $id, $roles);
}
}
/**
* Adds user to corresponding access groups when he is assigned to organization.
* User will also be added to child organizations access groups.
@@ -132,10 +166,9 @@ class Wiaas_User_Organization extends WP_User_Taxonomy {
* to access order.
*
* @param $post_id - custom post id (product, order, ...)
* @param $user_id
* @param $organization_id
*/
public static function assign_post_to_user_organization($post_id, $user_id) {
$organization_id = self::get_user_organization_id($user_id);
public static function assign_post_to_organization($post_id, $organization_id) {
self::_assign_post_to_organization($post_id, $organization_id);
}