Enable login by role both on frontend and backend
This commit is contained in:
@@ -19,9 +19,9 @@ class Wiaas_Shop {
|
||||
// update prices search terms for package after prices extras have been updated
|
||||
add_action('wiaas_package_prices_extras_set', array(__CLASS__, 'update_package_prices_search_terms'), 10, 4);
|
||||
|
||||
// create new shop if organization was assigned commercial lead role
|
||||
// or remove shop if commercial lead role was removed for organization
|
||||
add_action('wiaas_organization_roles_updated', array(__CLASS__, 'maybe_manage_shop_for_commercial_lead'), 10, 2);
|
||||
// remove customer shop relationships for all deactivated and removed shops
|
||||
add_action('wiaas_organization_roles_updated', array(__CLASS__, 'remove_deactivated_shop'));
|
||||
add_action('wiaas_organization_deleted', array(__CLASS__, 'remove_shop'));
|
||||
}
|
||||
|
||||
public static function get_shop_customers($owner_id) {
|
||||
@@ -86,18 +86,24 @@ class Wiaas_Shop {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates shop for new shop owner (organization with commercial lead role) or
|
||||
* deletes existing shop if that role has been removed
|
||||
* Remove shop for organization that is no longer commercial lead
|
||||
*
|
||||
* @param int $owner_id
|
||||
* @param array $roles
|
||||
*/
|
||||
public static function maybe_manage_shop_for_commercial_lead($owner_id, $roles) {
|
||||
$is_commercial_lead = in_array('commercial_lead', $roles);
|
||||
public static function remove_deactivated_shop($owner_id) {
|
||||
$roles = wiaas_get_organization_roles($owner_id);
|
||||
|
||||
$is_commercial_lead ?
|
||||
self::_maybe_create_shop($owner_id) :
|
||||
self::_maybe_remove_shop($owner_id);
|
||||
if (! in_array('commercial_lead', $roles)) {
|
||||
self::remove_shop($owner_id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* remove shop
|
||||
* @param int $owner_id
|
||||
*/
|
||||
public static function remove_shop($owner_id) {
|
||||
Wiaas_Shop_DB::remove_shop($owner_id);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -132,7 +138,7 @@ class Wiaas_Shop {
|
||||
* $extra_price_payment_type => {
|
||||
* @type bool visible Indicates if payment type is visible to customer
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
* @param array $old_cl_extras {
|
||||
* $extra_price_payment_type => {
|
||||
* @type bool visible Indicates if payment type is visible to customer
|
||||
@@ -156,49 +162,6 @@ class Wiaas_Shop {
|
||||
|
||||
// PRIVATE
|
||||
|
||||
/**
|
||||
* Each shop will be registered as product attribute.
|
||||
* This will persist shops information into database.
|
||||
* Also every attribute has taxonomy associated with it which will enable us to have multiple
|
||||
* catalogues in one shop
|
||||
*
|
||||
* @param int $owner_id
|
||||
*/
|
||||
private static function _maybe_create_shop($owner_id) {
|
||||
$shop_name = 'wiaas_shop_' . $owner_id;
|
||||
|
||||
$attribute_id = wc_attribute_taxonomy_id_by_name($shop_name);
|
||||
|
||||
if ($attribute_id === 0) {
|
||||
// create shop attribute
|
||||
wc_create_attribute(array( 'slug' => $shop_name, 'name' => 'Shop' ));
|
||||
|
||||
$taxonomy_name = wc_attribute_taxonomy_name($shop_name);
|
||||
|
||||
// since attribute taxonomies are registered once on load
|
||||
// we will register new attribute taxonomy here so default catalogue can be added
|
||||
register_taxonomy($taxonomy_name, array('product'));
|
||||
|
||||
// add default catalogue option to shop
|
||||
wp_insert_term( 'Default Catalogue', $taxonomy_name);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deleted associated attribute for shop. This will effectively remove shop and all of its potential catalogues
|
||||
*
|
||||
* @param int $owner_id
|
||||
*/
|
||||
private static function _maybe_remove_shop($owner_id) {
|
||||
// get corresponding attribute for shop
|
||||
$attribute_id = wc_attribute_taxonomy_id_by_name('wiaas_shop_' . $owner_id);
|
||||
|
||||
// if shop attribute exists then remove it
|
||||
if ($attribute_id > 0) {
|
||||
wc_delete_attribute($attribute_id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate search terms from cl extras
|
||||
*
|
||||
@@ -242,7 +205,7 @@ class Wiaas_Shop {
|
||||
foreach ($cl_extras_per_customer as $customer_id => $visible) {
|
||||
|
||||
$terms[] = '_' . $owner_id . '_customer_' . $customer_id . '_' .
|
||||
($visible ? 'visible' : 'hidden');
|
||||
($visible ? 'visible' : 'hidden');
|
||||
}
|
||||
|
||||
return $terms;
|
||||
|
||||
Reference in New Issue
Block a user