Jump to content

How to add custom action in render list


Mukesh Ravi

Recommended Posts

Hi All,

 

 

 

I am using Prestashop 1.5.6

I want add a new custom action (say "new action") in render action list.

I reached to admincontroller but don't know how to do this?

For more clarification I am attaching a screenshot.

 

Please help me.

 

Thanks in Advance...!

post-262404-0-96683600-1395210785_thumb.png

Link to comment
Share on other sites

In AdminProductsController line 2294 you can add a row action (test for example)


	public function renderList()
	{
		$this->addRowAction('edit');
		$this->addRowAction('duplicate');
		$this->addRowAction('delete');
		$this->addRowAction('test');
		return parent::renderList();
	}

Then in the same controller (or in the HelperList) you need to define the displayTestLink. For example this one is copy pasted from the displayEditLink in the HelperList, and changed only the title, from Edit to Test and the path to find the tpl (since we are in the controller)

public function displayTestLink($token = null, $id, $name = null)
	{
		$tpl = $this->createTemplate('helpers/list/list_action_edit.tpl');
		if (!array_key_exists('Test', self::$cache_lang))
			self::$cache_lang['Test'] = $this->l('Test', 'Helper');
	
		$tpl->assign(array(
				'href' => $this->currentIndex.'&'.$this->identifier.'='.$id.'&update'.$this->table.'&token='.($token != null ? $token : $this->token),
				'action' => self::$cache_lang['Test'],
				'id' => $id
		));
	
		return $tpl->fetch();
	}

But you get the idea, you generate the html for each button dinamicaly, the tpl is very simple:

<a href="{$href}" class="edit" title="{$action}">
	<img src="../img/admin/edit.gif" alt="{$action}" />
</a>
  • Like 5
Link to comment
Share on other sites

  • 2 weeks later...

You can have a look at http://doc.prestashop.com/display/PS15/Overriding+default+behaviors#Overridingdefaultbehaviors-Overridingacontroller

 

you can put your AdminProductsController under override/controllers/admin, override the public function renderList() and add your displayXXXLink method

 

don't forget to delete cache/class_index.php if you do it manually.

Link to comment
Share on other sites

  • 1 year later...
  • 5 weeks later...
  • 3 months later...

You can have a look at http://doc.prestashop.com/display/PS15/Overriding+default+behaviors#Overridingdefaultbehaviors-Overridingacontroller

 

you can put your AdminProductsController under override/controllers/admin, override the public function renderList() and add your displayXXXLink method

 

don't forget to delete cache/class_index.php if you do it manually.

Hey man, is it possible to override controller and add custom row action or order products? I can`t even find where should I do it. In AdminProduct or AdminOrders controller? Thanks for any help!

Link to comment
Share on other sites

  • 7 years later...
On 3/21/2014 at 12:40 PM, Enrique Gómez said:

In AdminProductsController line 2294 you can add a row action (test for example)

	public function renderList()
	{
		$this->addRowAction('edit');
		$this->addRowAction('duplicate');
		$this->addRowAction('delete');
		$this->addRowAction('test');
		return parent::renderList();
	}

Then in the same controller (or in the HelperList) you need to define the displayTestLink. For example this one is copy pasted from the displayEditLink in the HelperList, and changed only the title, from Edit to Test and the path to find the tpl (since we are in the controller)

public function displayTestLink($token = null, $id, $name = null)
	{
		$tpl = $this->createTemplate('helpers/list/list_action_edit.tpl');
		if (!array_key_exists('Test', self::$cache_lang))
			self::$cache_lang['Test'] = $this->l('Test', 'Helper');
	
		$tpl->assign(array(
				'href' => $this->currentIndex.'&'.$this->identifier.'='.$id.'&update'.$this->table.'&token='.($token != null ? $token : $this->token),
				'action' => self::$cache_lang['Test'],
				'id' => $id
		));
	
		return $tpl->fetch();
	}

But you get the idea, you generate the html for each button dinamicaly, the tpl is very simple:

<a href="{$href}" class="edit" title="{$action}">
	<img src="../img/admin/edit.gif" alt="{$action}" />
</a>

Thanks a lot
I used your guide like this to create a custom button which is linked to customer page
Although I wanted to have the customer ID to be clickable but this is a good workaround too
 

    public function displayViewCustomerLink($token = null, $id, $name = null)
	{
		$tpl = $this->createTemplate('helpers/list/list_action_view.tpl');
	
		$tpl->assign(array(
            'href' => Context::getContext()->link->getAdminLink(
                'AdminCustomers',
                true,
                [
                    'customerId' => $id,
                    'viewcustomer' => true,
                ]
            ),
            'action' => 'View Customer',
            'id' => $id
		));
	
		return $tpl->fetch();
	}


BEFORE
image.thumb.png.4d3a686b09e7e97c21d09e0f1efac136.png


AFTER
image.thumb.png.54b6ce7b67dd7a7e5dcad7321c357957.png

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...