Jump to content

Editing table costumers in backoffice (adding field)


powerwave

Recommended Posts

Hello,

 

i need some help please about adding a field in customers BO table.

 

the field or the column must be named "points" and his value is the number of points that the customer got in module loyalty.

 

 

what i did:

 

in the class customer.php i added a field named points and a function:

 

public $points;
public function pointOfCustumer($id_customer){
 return Customer::getPoint($id_customer);

}
public static function getPoint($id_customer)
{
 $sql='SELECT SUM(points) FROM `'._DB_PREFIX_.'loyalty` WHERE `id_customer`='.$id_customer.' AND `id_loyalty_state`=2';
 return (int)Db::getInstance()->getValue($sql);
}

 

 

if the file AdminCustomersController.php on the constructor, i added

 

'points' => array(
               'title' => $this->l('Points'),
               'width' => 'auto'
           ),

 

i have to use somewhere maybe something like:

'totalPoints' => $this->context->customer->pointOfCustumer($this->context->customer->id),

 

and give the value to 'Points' in the constructor

 

 

yes, i'm a beginner and sorry for my bad english :s

 

thank's for reading this, and if you have any idea, SOS

Link to comment
Share on other sites

Technically you don't need to add anything to the ps_customer table, but want to assign a value to a Customer object from another table.

 

I think your best bet is to modify the LoyaltyModule to produce the points you want. Your selection criteria (above) is a subset of the LoyaltyModule::getPointsByCustomer(), so adding a LoyaltyModule::getValidationPointsByCustomer() method should be simple.

 

When you have that working, override Customer to just include:

public $loyalty_points;

and override the constructor to assign the loyalty points total you want to see to the Customer object with something like:

public function __construct( $id = null, $id_lang = null, $id_shop = null ) {
  parent::__construct( $id, $id_lang, $id_shop );
  $this->loyalty_points = LoyaltyModule::getValidationPointsByCustomer( $this->id );
}

 

Then go into AdminCustomersController and override the constructor to have the new data be visible. I suggest something like:

$this->fields_list = array(
[...]
'loyalty_points' => array(
'title' => $this->l('Points'),
'width' => 20,
'search' => false,
'align' => 'center'
),
[...]

and you should get a listing of the loyalty points in the customer list.

 

HTH,

Edited by Terragg (see edit history)
  • Like 1
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...