Post by Slim-Designs » Tue Jun 12, 2018 5:51 am

Hi everyone,
I’m quite new to OC, so go easy on me!

Is there a way to suspend an account? So that the user can’t buy anything and if they try to log into their account, it says
‘Your account is currently suspended. Please click here(link here) to speak to the store owner.’

Because all I can see is a way to do it is by going into the customers details and editing their account by switching ‘status’ to disabled which gives this image;
Image

Which is not what I want.

Any help is gratefully received!

Newbie

Posts

Joined
Thu Jun 07, 2018 12:38 am

Post by paulfeakins » Tue Jun 12, 2018 5:16 pm

For something custom like this it's probably best to post a job and pay a developer from the Commercial Support forum.

For quick, professional OpenCart support please email info@antropy.co.uk


User avatar
Active Member

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - Reigate, Surrey, United Kingdom

Post by straightlight » Tue Jun 12, 2018 10:15 pm

Suspending a session account must be done for proper reasons, normally, due to policy reasons. Suspending a user account in order to edit his account wouldn't be a justified reason for the customer. I would rather suggest the use of an account maintenance system tool for specific users by adding a specific maintenance page to the store when an account has to be set under maintenance. However, it would indeed require a custom job or custom extension that can be downloaded in order to accomplish this.

The most generated errors being found on Opencart forum originates from contributed programming. The increased counters are caused by posted redundancies of the same solutions that were already provided prior.

F. Rules:

- viewtopic.php?f=176&t=200480
- viewtopic.php?f=176&t=200804


Regards,
Straightlight


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by straightlight » Tue Jun 12, 2018 11:31 pm

I prefer to publish this particular feature myself in accordance to RFC and PCI compliance. The following has been tested on OC v3.0.3.0b release. Feel free to create a VQMod / OCMod extension with it.

In admin/controller/customer/customer.php file,

find:

Code: Select all

if (isset($this->request->post['safe'])) {
add above:

Code: Select all

if (isset($this->request->post['maintenance'])) {
			$data['maintenance'] = $this->request->post['maintenance'];
		} elseif (!empty($customer_info)) {
			$data['maintenance'] = $customer_info['maintenance'];
		} else {
			$data['maintenance'] = true;
		}
In admin/language/<your_language>/customer/customer.php file,

add at the bottom:

Code: Select all

$_['entry_maintenance'] = 'Maintenance';
In admin/model/customer/customer.php file,

find all instances of:

Code: Select all

status = '" . (int)$data['status'] . "',
replace all with:

Code: Select all

status = '" . (int)$data['status'] . "', maintenance = '" . (int)$data['maintenance'] . "', 

In admin/view/template/customer/customer_form.twig file,

find:

Code: Select all

<div class="form-group row">
                          <label class="col-sm-2 col-form-label">{{ entry_status }}</label>
add above:

Code: Select all

<div class="form-group row">
                          <label class="col-sm-2 col-form-label">{{ entry_maintenance }}</label>
                          <div class="col-sm-10">
                            <div class="btn-group btn-group-toggle" data-toggle="buttons">
                              {% if maintenance %}
                                <label class="btn btn-success active"><input type="radio" name="maintenance" value="1" checked="checked"/> {{ text_yes }}</label>
                                <label class="btn btn-danger"><input type="radio" name="maintenance" value="0"/> {{ text_no }}</label>
                              {% else %}
                                <label class="btn btn-success"><input type="radio" name="maintenance" value="1"/> {{ text_yes }}</label>
                                <label class="btn btn-danger active"><input type="radio" name="maintenance" value="0" checked="checked"/> {{ text_no }}</label>
                              {% endif %}
                            </div>
                          </div>
                        </div>
In system/config/catalog.php file,

find:

Code: Select all

'startup/maintenance',
add right below:

Code: Select all

'startup/customer_maintenance',
In system/library/cart/customer.php file,

find:

Code: Select all

private $telephone;
add right below:

Code: Select all

private $maintenance;
Then, find all instances of:

Code: Select all

$this->telephone = $customer_query->row['telephone'];
add below each:

Code: Select all

$this->maintenance = $customer_query->row['maintenance'];
Then, find:

Code: Select all

$this->telephone = '';
add right below:

Code: Select all

$this->maintenance = '';
Then, find:

Code: Select all

public function getTelephone() {
add above:

Code: Select all

public function isOnMaintenance() {
    return $this->maintenance;
}
In catalog/model/account/customer.php file (optional),

find:

Code: Select all

public function addTransaction($customer_id, $description, $amount = '', $order_id = 0) {
add above:

Code: Select all

public function disableMaintenance() {
    $this->db->query("UPDATE `" . DB_PREFIX . "customer` SET maintenance = '0' WHERE customer_id = '" . (int)$this->customer->getId() . "'");
}
In catalog/controller/startup folder, create a new PHP file called: customer_maintenance.php . Then, add the following content:

Code: Select all

<?php
class ControllerStartupCustomerMaintenance extends Controller {
	public function index() {
		if ($this->customer->isOnMaintenance()) {
			// Route
			if (isset($this->request->get['route']) && $this->request->get['route'] != 'startup/router') {
				$route = $this->request->get['route'];
			} else {
				$route = $this->config->get('action_default');
			}			
			
			$ignore = array(
				'common/language/language',
				'common/currency/currency'
			);
			
			// Show site if logged in as admin
			$this->user = new Cart\User($this->registry);

			if ((substr($route, 0, 17) != 'extension/payment' && substr($route, 0, 3) != 'api') && !in_array($route, $ignore) && !$this->user->isLogged()) {
				return new Action('common/customer_maintenance');
			}
		}
	}
}
Note: Make sure to create this new file with UTF-8 from a reliable text editor.

In your catalog/controller/common folder, create a new file called: customer_maintenance.php . Then, add the following content:

Code: Select all

<?php
class ControllerCommonCustomerMaintenance extends Controller {
	public function index() {
	        $this->customer->logout();
	        
		$this->load->language('common/customer_maintenance');

		$this->document->setTitle($this->language->get('heading_title'));

		if ($this->request->server['SERVER_PROTOCOL'] == 'HTTP/1.1') {
			$this->response->addHeader('HTTP/1.1 503 Service Unavailable');
		} else {
			$this->response->addHeader('HTTP/1.0 503 Service Unavailable');
		}

		$this->response->addHeader('Retry-After: 3600');

		$data['breadcrumbs'] = array();

		$data['breadcrumbs'][] = array(
			'text' => $this->language->get('text_customer_maintenance'),
			'href' => $this->url->link('common/customer_maintenance', 'language=' . $this->config->get('config_language'))
		);

		$data['message'] =$this->language->get('text_message');

		$data['header'] = $this->load->controller('common/header');
		$data['footer'] = $this->load->controller('common/footer');

		$this->response->setOutput($this->load->view('common/customer_maintenance', $data));
	}
}
In your catalog/language/<your_language>/common folder, create a new file called: customer_maintenance.php . Then, add the following content:

Code: Select all

<?php
// Heading
$_['heading_title']    = 'Maintenance';

// Text
$_['text_customer_maintenance'] = 'Maintenance';
$_['text_message']     = '<h1 style="text-align:center;">We are currently performing some maintenance on your account. <br/>Your account session should be restored shortly. Please check back soon.</h1>';
On your Opencart database, in PHPMyAdmin, on your customer table, execute the following query in the SQL tab:

Code: Select all

ALTER TABLE `oc_customer` ADD `maintenance` INT(1) NOT NULL AFTER `email`;
Note: Change the: oc_ with your actual database table prefix name.

This should provide what you need.

The most generated errors being found on Opencart forum originates from contributed programming. The increased counters are caused by posted redundancies of the same solutions that were already provided prior.

F. Rules:

- viewtopic.php?f=176&t=200480
- viewtopic.php?f=176&t=200804


Regards,
Straightlight


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON
Who is online

Users browsing this forum: No registered users and 7 guests