Jump to content

[SOLVED] Edit customer from group list view PS 1.5.6.2


dokorek

Recommended Posts

Hi

 

I need to add to detailed view of customers in selected group (controller=AdminGroups) availability to edit customer (action edit link to customer edit page)- see screenshot:

post-365740-0-95284700-1407238376_thumb.png

 

 

I've edited AdminGroupsController.php to see how many orders customer have and how many they paid:

protected function renderCustomersList($group)
	{
		$genders = array(0 => '?');
		$genders_icon = array('default' => 'unknown.gif');
		
		foreach (Gender::getGenders() as $gender)
		{
			$genders_icon[$gender->id] = '../genders/'.(int)$gender->id.'.jpg';
			$genders[$gender->id] = $gender->name;
		}

		$this->table = 'customer_group';
		$this->lang = false;
		$this->list_id = 'customer_group';
		$this->actions = array();
		$this->bulk_actions = false;
		$this->list_no_link = true;

		$this->fields_list = (array(
				'id_customer' => array('title' => $this->l('ID'), 'width' => 15,'prefix' => '<b>', 'suffix' => '</b>',  'align' => 'center', 'filter_key' => 'c!id_customer'),

				//'id_gender' => array('title' => $this->l('Titles'), 'align' => 'center', 'width' => 50,'icon' => $genders_icon, 'list' => $genders),
				'firstname' => array('title' => $this->l('First name'), 'align' => 'left'),
				'lastname' => array('title' => $this->l('Last name'), 'align' => 'left'),
				'email' => array('title' => $this->l('Email address'), 'width' => 150, 'align' => 'left', 'filter_key' => 'c!email', 'orderby' => true),
				//'birthday' => array('title' => $this->l('Birth date'), 'width' => 150, 'align' => 'right', 'type' => 'date'),
				'nb' => array('title' => $this->l('Orders'), 'width' => 100,),
				'wartosc' => array('title' => $this->l('Wartość'), 'width' => 150,),
				'date_add' => array('title' => $this->l('Register date'), 'width' => 150, 'align' => 'right', 'type' => 'date'),
				'active' => array('title' => $this->l('Enabled'),'align' => 'center','width' => 20, 'active' => 'status','type' => 'bool')
			));
		$this->_select = 'c.*, co.*, SUM( co.`total_paid_real`) AS wartosc, COUNT( co.`id_customer`) AS nb
		';
		$this->_join = '
		LEFT JOIN `'._DB_PREFIX_.'customer` c ON (a.`id_customer` = c.`id_customer`)
		LEFT JOIN `'._DB_PREFIX_.'orders` co ON (co.`id_customer` = c.`id_customer`)
		';
		$this->_where = 'AND a.`id_group` = '.(int)$group->id.' AND c.`deleted` != 1';
		$this->_group = 'GROUP BY co.`id_customer`';
		self::$currentIndex = self::$currentIndex.'&viewgroup';

		$this->addRowAction('test');
		$this->processFilter();
		return parent::renderList();
	}

I have made function displayTestLink but i cant get $id_customer value to made it works

public function displayTestLink($token = null, $id, $id_customer, $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' => 'index.php?controller=AdminCustomers&id_customer='.$id_customer.'&updatecustomer&token='.($token != null ? $token : $this->token),
				'action' => self::$cache_lang['Test'],
				'id' => $id,
				'idc' => $idc
		));
	
		return $tpl->fetch();
	}

please help me

post-365740-0-95284700-1407238376_thumb.png

Edited by dokorek (see edit history)
Link to comment
Share on other sites

I have solution :) it is very simple

 

You must add:

$this->identifier = 'id_customer';

$this->addRowAction('edit');

 

and function:

	public function displayEditLink($token, $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' => 'index.php?controller=AdminCustomers&id_customer='.$id.'&updatecustomer&token='.Tools::getAdminTokenLite('AdminCustomers'),
				'action' => self::$cache_lang['Test'],
				'id' => $id
		));
	
		return $tpl->fetch();
	}

my code from AdminGroupsController.php

protected function renderCustomersList($group)
	{
		$genders = array(0 => '?');
		$genders_icon = array('default' => 'unknown.gif');
		
		foreach (Gender::getGenders() as $gender)
		{
			$genders_icon[$gender->id] = '../genders/'.(int)$gender->id.'.jpg';
			$genders[$gender->id] = $gender->name;
		}

		$this->table = 'customer_group';
		$this->lang = false;
		$this->list_id = 'customer_group';

		$this->identifier = 'id_customer';
		$this->actions = array();
		$this->bulk_actions = false;
		$this->list_no_link = true;

		$this->fields_list = (array(
				'id_customer' => array('title' => $this->l('ID'), 'width' => 15,'prefix' => '<b>', 'suffix' => '</b>',  'align' => 'center', 'filter_key' => 'c!id_customer'),
				'firstname' => array('title' => $this->l('First name'), 'align' => 'left'),
				'lastname' => array('title' => $this->l('Last name'), 'align' => 'left'),
				'email' => array('title' => $this->l('Email address'), 'width' => 150, 'align' => 'left', 'filter_key' => 'c!email', 'orderby' => true),
				'nb' => array('title' => $this->l('Orders'), 'width' => 100,),
				'wartosc' => array('title' => $this->l('Wartość'), 'width' => 150,),
				'date_add' => array('title' => $this->l('Register date'), 'width' => 150, 'align' => 'right', 'type' => 'date'),
				'active' => array('title' => $this->l('Enabled'),'align' => 'center','width' => 20, 'active' => 'status','type' => 'bool')
			));
		$this->_select = 'c.*, co.*, SUM( co.`total_paid_real`) AS wartosc, COUNT( co.`id_customer`) AS nb, co.`id_customer` AS id_customer
		';
		$this->_join = '
		LEFT JOIN `'._DB_PREFIX_.'customer` c ON (a.`id_customer` = c.`id_customer`)
		LEFT JOIN `'._DB_PREFIX_.'orders` co ON (co.`id_customer` = c.`id_customer`)
		';
		$this->_where = 'AND a.`id_group` = '.(int)$group->id.' AND c.`deleted` != 1';
		$this->_group = 'GROUP BY co.`id_customer`';
		self::$currentIndex = self::$currentIndex.'&viewgroup'.'&id_group='.(int)$group->id;

		$this->addRowAction('edit');
		$this->processFilter();
		return parent::renderList();
	}

	public function displayEditLink($token, $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' => 'index.php?controller=AdminCustomers&id_customer='.$id.'&updatecustomer&token='.Tools::getAdminTokenLite('AdminCustomers'),
				'action' => self::$cache_lang['Test'],
				'id' => $id
		));
	
		return $tpl->fetch();
	}
Edited by dokorek (see edit history)
Link to comment
Share on other sites

  • 2 months later...

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...