test
This commit is contained in:
@@ -21,9 +21,9 @@ class Wiaas_Shop {
|
||||
|
||||
// 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);
|
||||
add_action('wiaas_organization_roles_updated', array(__CLASS__, 'remove_deactivated_shop'));
|
||||
|
||||
add_action('wiaas_organization_deleted', array(__CLASS__, 'maybe_remove_shop'));
|
||||
add_action('wiaas_organization_deleted', array(__CLASS__, 'remove_shop'));
|
||||
}
|
||||
|
||||
public static function get_shop_customers($owner_id) {
|
||||
@@ -88,18 +88,16 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -107,8 +105,8 @@ class Wiaas_Shop {
|
||||
*
|
||||
* @param int $owner_id
|
||||
*/
|
||||
public static function maybe_remove_shop($owner_id) {
|
||||
self::_maybe_remove_shop($owner_id);
|
||||
public static function remove_shop($owner_id) {
|
||||
Wiaas_Shop_DB::remove_shop($owner_id);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -167,51 +165,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);
|
||||
}
|
||||
|
||||
Wiaas_Shop_DB::remove_shop($owner_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate search terms from cl extras
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user