Quick edit from OpenCart 2x product page
I came across this technique on the netsh.pp.ua website, I post it here so as not to forget. The reception was tested on 2.3.
First, add a function in the system/library/url.php file
public function linkEditProduct($route, $args = '', $secure = false) {
if ($this->ssl && $secure) {
$url = $this->ssl . 'admin/index.php?route=' . $route;
} else {
$url = $this->url . 'admin/index.php?route=' . $route;
}
if ($args) {
if (is_array($args)) {
$url .= '&' . http_build_query($args);
} else {
$url .= str_replace('&', '&', '&' . ltrim($args, '&'));
}
return $url;
}
}
Next, add the text for the edit product button in catalog/language/en-us/product/product.php
$_['text_button_edit'] = 'Edit Product';
Next, let's add some code to the catalog/controller/product/product.php controller. Finding a string
$product_info = $this->model_catalog_product->getProduct($product_id);
(I found two such lines, I added after the first one) and after it we add
$data['button_edit_product'] = $this->language->get('text_button_edit');
A couple of lines below will be if ($product_info) { add
if(!empty($this->session->data['user_id']) && !empty($this->session->data['token'])){
$data['edit_product'] = '<a class="btn btn-warning btn-lg btn-block" href="'.$this->url->linkEditProduct('catalog/product/edit', 'token=' . $this->session->data['token'].'&product_id='.$product_id, 'true').'" target="_blank" rel="noopener">'.$data['button_edit_product'].'</a>';
}
Now add in the template file catalog/view/theme/default/template/product/product.tpðÊÉíU ðÊÉíU ЛÉÉíU ™ÉÉíU XÊÉíU ÊÉíU @ ÊÉíU edit_product; } ?>
Now we have on the product page a button for editing the product, which would be displayed only for the logged in user.