Edit product link in backend in Opencart 3

Today we add link to edit product on product page for user who have role on admin.

In catalog/controller/product/product.php after line

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

add

$data['show_edit_box'] = false;
$data['verdad_token'] = false;
if (isset($this->session->data['user_token'])) {
$check = $this->db->query("select * from ".DB_PREFIX."user where user_id=".(int)$this->session->data['user_id']);
if($check->num_rows>0) {
 $check = $check->row;
 if ($check['user_group_id']==1) {
  $data['show_edit_box'] = true;
  $data['verdad_token'] = $this->session->data['user_token'];
  $data['server'] = HTTPS_SERVER;
 }
}
}

After that in file catalog/view/theme/your_theme_name/template/product/product.twig after line

{{ header }}

add code

{% if show_edit_box==true %}
  <a class="edit-button" href="{{ server }}/admin/index.php?route=catalog/product/edit&user_token={{ verdad_token }}&product_id={{ product_id }}" target="_blank">Edit product</a>
{% endif %}

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.
The comment language code.