Hey hey hello,
from the very beginning I missed the automatic creation of company profiles when registering a new user and the synchronisation of activation/deactivation with the basic profile. Below I add a trivial solution to the problem, which may be useful to someone in the future.
Possible Solution:
Step 1: Add on the end code to functions.php file in plugin folder (plugins -> business_profile):
/* Create business profile after user complate register */
function wg_create_business_profile($user_id = 0)
{
$bpr_plugin = 'business_profile/index.php ';
if (is_int($user_id) && $user_id > 0 && osc_plugin_is_installed($bpr_plugin) && osc_plugin_is_enabled($bpr_plugin)) {
$bpr_user = ModelBPR::newInstance()->getSellerByUserId($user_id);
if (empty($bpr_user)) {
$user_data = User::newInstance()->findByPrimaryKey($user_id);
$profile_identifier = strtolower(osc_sanitize_username($user_data['s_name']));
$data = array(
'fk_i_user_id' => $user_id,
's_identifier' => $profile_identifier,
'b_enabled' => 0,
'b_verified' => 0
);
$result = ModelBPR::newInstance()->insertProfile($data);
return $result;
}
}
return false;
}
/* Activate / deactivate business profile */
function wg_activ_deactiv_business_profile($user)
{
if (empty($user) || !isset($user['pk_i_id'])) {
return false;
}
$bpr_plugin = 'business_profile/index.php';
if (osc_plugin_is_installed($bpr_plugin) && osc_plugin_is_enabled($bpr_plugin)) {
$bpr_user = ModelBPR::newInstance()->getSellerByUserId($user['pk_i_id']);
if ($user['b_active'] == 1 && !empty($bpr_user)) {
$result = ModelBPR::newInstance()->deactivateProfile($bpr_user['pk_i_id']);
} elseif ($user['b_active'] == 0 && !empty($bpr_user)) {
$result = ModelBPR::newInstance()->activateProfile($bpr_user['pk_i_id']);
} else {
$result = false;
}
return $result;
}
}
Step 2: Next (on the end of file) add code to index.php file in plugin folder (plugins -> business_profile):
/* Create business profile after user complate register */
osc_add_hook('user_register_completed', 'wg_create_business_profile');
/* If activate user, activate business profile */
osc_add_hook('activate_user', 'wg_activ_deactiv_business_profile');
/* If deactivate user, deactivate business profile */
osc_add_hook('deactivate_user', 'wg_activ_deactiv_business_profile');
I hope it will help someone. Have fun!