Post by swguy » Tue Dec 19, 2017 5:36 am

If a serious and unexpected condition occurs, I'd like to do a

Code: Select all

redirect($base->url->link('common/dashboard', 'user_token=' . $base->session->data['user_token'], 'SSL'));
but first set an error message to display on the dashboard. But I don't see any mechanism to do this sort of thing. Am I missing something?

Better Together: Buy one product, get another at a discount.
Discount Chooser: Buy a group of products, get another group at a discount.


User avatar
New member

Posts

Joined
Mon Apr 15, 2013 4:13 am

Post by straightlight » Tue Dec 19, 2017 5:57 am

No OC version posted. Partial solution posted only. However, looking at the code, this would be the complete command line:

Code: Select all

$this->response->redirect($base->url->link('common/dashboard', 'user_token=' . $base->session->data['user_token']));
Take note that the 'SSL' parameter is no longer needed when using the Github master files.

Although, I would need the location from where exactly you are attempting to set an error message and based on which conditions.

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


Regards,
Straightlight
Opencart.com Administrator / Quality Assurance Analyst / Programmer


Legendary Member

Posts

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

Post by swguy » Tue Dec 19, 2017 8:22 am

Version is 3.0.2.0. The redirect works; what doesn't work is setting a message that's displayed on the dashboard. How do I do that?

Better Together: Buy one product, get another at a discount.
Discount Chooser: Buy a group of products, get another group at a discount.


User avatar
New member

Posts

Joined
Mon Apr 15, 2013 4:13 am

Post by straightlight » Tue Dec 19, 2017 8:47 am

Interesting request. In admin/controller/common/dashboard.php file,

find:

Code: Select all

// Dashboard Extensions
add above:

Code: Select all

if (isset($this->session->data['error'])) {
			$data['error_warning'] = $this->session->data['error'];

			unset($this->session->data['error']);
		} else {
			$data['error_warning'] = '';
		}
		
		if (isset($this->session->data['attention'])) {
			$data['attention'] = sprintf($this->language->get('text_login'), $this->url->link('account/login'), $this->url->link('account/register'));
			
			unset($this->session->data['attention']);
		} else {
			$data['attention'] = '';
		}

		if (isset($this->session->data['success'])) {
			data['success'] = $this->session->data['success'];

			unset($this->session->data['success']);
		} else {
			$data['success'] = '';
		}
Then, above your redirect line, you could add those super global keys:

Code: Select all

// Handles errors
$this->session->data['error'] = $this->language->get('error_your_statement');

// Handles attention
$this->session->data['attention'] = $this->language->get('attention_your_statement');

// Handles success
$this->session->data['success'] = $this->language->get('text_success');
Each defined language keys for: error_your_statement, attention_your_statement and text_success needs to be defined in your admin/language/<your_language_code>/common/dashboard.php file.

Then, in your admin/view/template/common/dashboard.twig file,

find:

Code: Select all

</ul>
add right below:

Code: Select all

{% if attention %}
  <div class="alert alert-info"><i class="fa fa-info-circle"></i> {{ attention }}
    <button type="button" class="close" data-dismiss="alert">&times;</button>
  </div>
  {% endif %}
  {% if success %}
  <div class="alert alert-success alert-dismissible"><i class="fa fa-check-circle"></i> {{ success }}
    <button type="button" class="close" data-dismiss="alert">&times;</button>
  </div>
  {% endif %}
  {% if error_warning %}
  <div class="alert alert-danger alert-dismissible"><i class="fa fa-exclamation-circle"></i> {{ error_warning }}
    <button type="button" class="close" data-dismiss="alert">&times;</button>
  </div>
  {% endif %}
This should rectify the issue.

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


Regards,
Straightlight
Opencart.com Administrator / Quality Assurance Analyst / Programmer


Legendary Member

Posts

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

Post by swguy » Tue Dec 19, 2017 8:01 pm

Wow - I was hoping this capability was built in - I guess it will require surgery like the changes you are proposing. Thanks for taking the time to write this up. The idiomatic way to report errors is to use $log->write(some message), so I guess that's what I'll do - I just wanted to surface this particular message so it was more obvious.

Better Together: Buy one product, get another at a discount.
Discount Chooser: Buy a group of products, get another group at a discount.


User avatar
New member

Posts

Joined
Mon Apr 15, 2013 4:13 am

Post by straightlight » Tue Dec 19, 2017 10:54 pm

I would not suggest to output a file output text on screen for monitoring purposes as you'd need to work by line of codes in order to output subjects by specific texts while you could simply use the approach above to output your results with session super global with the browser instead as it is a more dynamic approach rather than from a solid file. ;)

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


Regards,
Straightlight
Opencart.com Administrator / Quality Assurance Analyst / Programmer


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 5 guests