Page 1 of 1

Hide Product Page Edit button

Posted: Sun Nov 11, 2012 5:44 pm
by vijay.priyani
Hi, all i want to hide the Edit and delete button if user(other then admin) is logged in the admin section. user can add products but can not modify the products of other. admin can add or modify all products of other.

Re: Hide Product Page Edit button

Posted: Sun Nov 11, 2012 6:24 pm
by pprmkr
Edit admin/controller/catalog/product.php

At line 11 add:

Code: Select all

$this->data['user_can_add'] = ($this->user->getUserName() == 'admin');
At line 350 change:

Code: Select all

			$action[] = array(
				'text' => $this->language->get('text_edit'),
				'href' => $this->url->link('catalog/product/update', 'token=' . $this->session->data['token'] . '&product_id=' . $result['product_id'] . $url, 'SSL')
			);
Into:

Code: Select all

			if( $this->data['user_can_add'] ) {
			$action[] = array(
				'text' => $this->language->get('text_edit'),
				'href' => $this->url->link('catalog/product/update', 'token=' . $this->session->data['token'] . '&product_id=' . $result['product_id'] . $url, 'SSL')
			);}
Edit admin/view/template/catalog/product_list.tpl
At line 17 change:

Code: Select all

<a onclick="$('form').submit();" class="button"><?php echo $button_delete; ?></a>
Into:

Code: Select all

<?php if( $user_can_add ) {;?><a onclick="$('form').submit();" class="button"><?php echo $button_delete; ?></a><?php }?>
Show the button Delete and link Edit only if username = admin

But if user is clever and edits the url and changes the route to route=catalog/product/update and adds product_id=1 he is able to edit product 1

To prevent that add some logic to function update()

Re: Hide Product Page Edit button

Posted: Sun Nov 11, 2012 7:20 pm
by vijay.priyani
Thanks,@pprmkr

Edit button is gone. But delete button is still there. when i am attempting to delete something. its shows a warning. snapshot attached.
I am also attaching the both files where the code is overwritten.

Once again thanks PPrmkr. You are amazing

Re: Hide Product Page Edit button

Posted: Sun Nov 11, 2012 9:08 pm
by pprmkr
Checked the files and works OK.

Little change: second delete button removed from tpl-file.