How To Show The Total Number Of Active Vendors On The Backend

Hello, this code {$general_stats.companies.total_companies|number_format} counts the number of sellers on the backend, i want it to count only the active vendors, I tried adding this "AND companies.status = 'A'" but it didn't work, any help is appreciated

Hello

Where did you try add condition "AND companies.status = 'A'"

Best regards

Robert

I tried adding this as an if condition before the code it'self, but i can't get it to work. this is the dashboard on the backend it shows all vendors but i want it to show only the number of vendors that are active

Hello

Please show complete sql query.

Best regards

Robert

Hello, this code {$general_stats.companies.total_companies|number_format} counts the number of sellers on the backend, i want it to count only the active vendors, I tried adding this "AND companies.status = 'A'" but it didn't work, any help is appreciated

Where did you add this condition?

Where did you add this condition?

public_html/design/backend/templates/views/index/index.tpl

If I'm understanding correctly, I think you're a bit confused. Template variables are set in PHP code and passed to templates.
So your use of:

{$general_stats.companies.total_companies|number_format}

will only get you what is stored in the registry as $general_stats.companies. I'd suggest you set your own variable and then use hooks to position the info where you want it. I.e. in app/addons/my_changes/controllers/backend/companies.post.php do something like:

if( $_SERVER['REQUEST_METHOD'] == 'GET' ) {
  $active_companies = db_get_field("SELECT count(*) FROM ?:companies where status='A'");
  Tygh::$app['view']->assign('active_companies', $active_companies);
}

And then use it in your template as:

{__("active_companies")}: {$active_companies}

If I'm understanding correctly, I think you're a bit confused. Template variables are set in PHP code and passed to templates.
So your use of:

{$general_stats.companies.total_companies|number_format}

will only get you what is stored in the registry as $general_stats.companies. I'd suggest you set your own variable and then use hooks to position the info where you want it. I.e. in app/addons/my_changes/controllers/backend/companies.post.php do something like:

if( $_SERVER['REQUEST_METHOD'] == 'GET' ) {
  $active_companies = db_get_field("SELECT count(*) FROM ?:companies where status='A'");
  Tygh::$app['view']->assign('active_companies', $active_companies);
}

And then use it in your template as:

{__("active_companies")}: {$active_companies}

Thank you so much fro the idea, worked great. i have another thing I'm trying to figure out, I'm trying to check if company on the frontend already exist then show error message, it checks the email but i want it to also check if a company name on the front end already exists, this is what i have tried, any help is appreciated.

//check if the entered company name already exists in the database

if (!isset($user_data['company'])) {
$user_data['company'] = db_get_field("SELECT email FROM ?:users WHERE user_id = ?i", $user_id);
}
$is_exist = fn_is_user_exists($user_id, $user_data);
//show error message if true
if ($is_exist) {
fn_set_notification('E', __('error'), __('error_user_exists'), '', 'user_exist');
return false;
}

Not sure where you're getting the code. If 'company' isn't set, not sure why you'd set it to email. If you want to set $is_exist based on the $email of the user or $user_data['company'] then I'd change it to something like:

$is_exist = !db_get_field("SELECT user_id FROM ?:users WHERE email=?s", $email) && !db_get_field("SELECT company FROM ?:companies WHERE company=?s and lang_code=?s", $user_data['company'], DESCR_SL);

UNTESTED - also is a general statement, may not be specific to the code you're referencing or to your needs.

Not sure where you're getting the code. If 'company' isn't set, not sure why you'd set it to email. If you want to set $is_exist based on the $email of the user or $user_data['company'] then I'd change it to something like:

$is_exist = !db_get_field("SELECT user_id FROM ?:users WHERE email=?s", $email) && !db_get_field("SELECT company FROM ?:companies WHERE company=?s and lang_code=?s", $user_data['company'], DESCR_SL);

UNTESTED - also is a general statement, may not be specific to the code you're referencing or to your needs.

This helped, thanks