Jump to content

Add e-mail to suppliers


Recommended Posts

I found these codes and way but I haven´t in override\controllers\admin the file AdminSuppliersController.php and in override\classes the file Supplier.php:

 

1. table ps_supplier: to add field "email" (VARCHAR(128)

 

2. override\controllers\admin\AdminSuppliersController.php file

<?php
class AdminSuppliersController extends AdminSuppliersControllerCore
{
public function renderForm()
{
 // loads current warehouse
 if (!($obj = $this->loadObject(true)))
  return;
 $this->fields_form = array(
  'legend' => array(
   'title' => $this->l('Suppliers'),
   'image' => '../img/admin/suppliers.gif'
  ),
  'input' => array(
   array(
 'type' => 'hidden',
 'name' => 'id_address',
   ),
   array(
 'type' => 'text',
 'label' => $this->l('Name:'),
 'name' => 'name',
 'size' => 40,
 'required' => true,
 'hint' => $this->l('Invalid characters:').' <>;=#{}',
   ),
   array(
 'type' => 'text',
 'label' => $this->l('E-mail address:'),
 'name' => 'email',
 'size' => 33,
 'required' => true
   ),
    array(
 'type' => 'text',
 'label' => $this->l('Phone:'),
 'name' => 'phone',
 'size' => 15,
 'maxlength' => 16,
 'desc' => $this->l('Phone number of this supplier')
   ),
   array(
 'type' => 'text',
 'label' => $this->l('Address:'),
 'name' => 'address',
 'size' => 100,
 'maxlength' => 128,
 'required' => true
   ),
   array(
 'type' => 'text',
 'label' => $this->l('Address:').' (2)',
 'name' => 'address2',
 'size' => 100,
 'maxlength' => 128,
   ),
   array(
 'type' => 'text',
 'label' => $this->l('City:'),
 'name' => 'city',
 'size' => 20,
 'maxlength' => 32,
 'required' => true,
   ),
   array(
 'type' => 'select',
 'label' => $this->l('State'),
 'name' => 'id_state',
 'options' => array(
  'id' => 'id_state',
  'query' => array(),
  'name' => 'name'
 )
   ),
   array(
 'type' => 'text',
 'label' => $this->l('Postal Code/Zip Code:'),
 'name' => 'postcode',
 'size' => 10,
 'maxlength' => 12,
 'required' => true,
   ),
   array(
 'type' => 'select',
 'label' => $this->l('Country:'),
 'name' => 'id_country',
 'required' => true,
 'default_value' => (int)$this->context->country->id,
 'options' => array(
  'query' => Country::getCountries($this->context->language->id, false),
  'id' => 'id_country',
  'name' => 'name',
 ),
 'desc' => $this->l('Country where the state, region or city is located')
   ),
   array(
 'type' => 'textarea',
 'label' => $this->l('Description:'),
 'name' => 'description',
 'cols' => 60,
 'rows' => 10,
 'lang' => true,
 'hint' => $this->l('Invalid characters:').' <>;=#{}',
 'desc' => $this->l('Will appear in supplier list')
   ),
   array(
 'type' => 'file',
 'label' => $this->l('Logo:'),
 'name' => 'logo',
 'display_image' => true,
 'desc' => $this->l('Upload supplier logo from your computer')
   ),
   array(
 'type' => 'text',
 'label' => $this->l('Meta title:'),
 'name' => 'meta_title',
 'lang' => true,
 'hint' => $this->l('Forbidden characters:').' <>;=#{}'
   ),
   array(
 'type' => 'text',
 'label' => $this->l('Meta description:'),
 'name' => 'meta_description',
 'lang' => true,
 'hint' => $this->l('Forbidden characters:').' <>;=#{}'
   ),
   array(
 'type' => 'tags',
 'label' => $this->l('Meta keywords:'),
 'name' => 'meta_keywords',
 'lang' => true,
 'hint' => $this->l('Forbidden characters:').' <>;=#{}',
 'desc' => $this->l('To add "tags" click in the field, write something, then press "Enter"')
   ),
   array(
 'type' => 'radio',
 'label' => $this->l('Enable:'),
 'name' => 'active',
 'required' => false,
 'class' => 't',
 'is_bool' => true,
 'values' => array(
  array(
   'id' => 'active_on',
   'value' => 1,
   'label' => $this->l('Enabled')
  ),
  array(
   'id' => 'active_off',
   'value' => 0,
   'label' => $this->l('Disabled')
  )
 )
   )
  ),
  'submit' => array(
   'title' => $this->l('   Save   '),
   'class' => 'button'
  )
 );
 // loads current address for this supplier - if possible
 $address = null;
 if (isset($obj->id))
 {
  $id_address = Address::getAddressIdBySupplierId($obj->id);
  if ($id_address > 0)
   $address = new Address((int)$id_address);
 }
 // force specific fields values (address)
 if ($address != null)
 {
  $this->fields_value = array(
   'id_address' => $address->id,
   'phone' => $address->phone,
   'address' => $address->address1,
   'address2' => $address->address2,
   'postcode' => $address->postcode,
   'city' => $address->city,
   'id_country' => $address->id_country,
   'id_state' => $address->id_state,
  );
 }
 else
  $this->fields_value = array(
   'id_address' => 0,
   'id_country' => Configuration::get('PS_COUNTRY_DEFAULT')
  );

 if (Shop::isFeatureActive())
 {
  $this->fields_form['input'][] = array(
   'type' => 'shop',
   'label' => $this->l('Shop association:'),
   'name' => 'checkBoxShopAsso',
  );
 }
 // set logo image
 $image = ImageManager::thumbnail(_PS_SUPP_IMG_DIR_.'/'.$this->object->id.'.jpg', $this->table.'_'.(int)$this->object->id.'.'.$this->imageType, 350, $this->imageType, true);
 $this->fields_value['image'] = $image ? $image : false;
 $this->fields_value['size'] = $image ? filesize(_PS_SUPP_IMG_DIR_.'/'.$this->object->id.'.jpg') / 1000 : false;

//  CAN NOT BE return parent::renderForm();
   return AdminControllerCore::renderForm();
 }

}

 

3. override\classes\Supplier.php extends SupplierCore

/* RKT2 */
public $email;
public function __construct($id = null, $id_lang = null)
{
parent::__construct($id, $id_lang);
}
}

 

4. classes/Supplier.php

public static $definition = array(
'table' => 'supplier',
'primary' => 'id_supplier',
'multilang' => true,
'fields' => array(
'name' => array('type' => self::TYPE_STRING, 'validate' => 'isCatalogName', 'required' => true, 'size' => 64),
//RKT2
'email' => array('type' => self::TYPE_STRING, 'validate' => 'isEmail', 'required' => true, 'size' => 128),
//RKT2
'active' => array('type' => self::TYPE_BOOL),
'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
// Lang fields
'description' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName'),
'meta_title' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 128),
'meta_description' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 255),
'meta_keywords' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 255),
),
);

Link to comment
Share on other sites

  • 2 years later...

It works for me THANX :)



 

class Supplier extends SupplierCore
{

	/** @var string Email */
	public $email;

	public static $definition = array(
		'table' => 'supplier',
		'primary' => 'id_supplier',
		'multilang' => true,
		'fields' => array(
			'name' => 				array('type' => self::TYPE_STRING, 'validate' => 'isCatalogName', 'required' => true, 'size' => 64),
			// added email to supplier
			'email' => 				array('type' => self::TYPE_STRING, 'validate' => 'isEmail', 'required' => false, 'size' => 128),
			// END added email to supplier
			'active' => 			array('type' => self::TYPE_BOOL),
			'date_add' => 			array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
			'date_upd' => 			array('type' => self::TYPE_DATE, 'validate' => 'isDate'),

			// Lang fields
			'description' => 		array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isCleanHtml'),
			'meta_title' => 		array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 128),
			'meta_description' => 	array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 255),
			'meta_keywords' => 		array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 255),
		),
	);

	public function __construct($id = null, $id_lang = null)
	{
		parent::__construct($id, $id_lang);
	}

	/**
	  * Return email from supplier id
	  * @param integer $id_supplier Supplier ID
	  * @return string email
	  */
	public static function getEmailById($id_supplier)
	{
		return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
			SELECT `email` FROM `'._DB_PREFIX_.'supplier` WHERE `id_supplier` = '.(int)$id_supplier);
	}
}
Link to comment
Share on other sites

×
×
  • Create New...