Jump to content

Add custom fields to manufacturer


Recommended Posts

Hi,

 

I need your help again.

 

This is my situation:

I need a grouped list of manufacturers with links to their websites.

In the backend there should be an additional field called 'Group' where i can define the group (one for each manufacturer). There should also be a field for website to define the manufacturers homepage to link the manufacturer's website.

 

The solution I thought about:

Add 2 custom fields to the database and add them to the backend.

But maybe there is a better way? Didn't find an existing module for this problem.

 

My Problem:

I tried to add my field with this tutorial: http://nemops.com/extending-prestashop-objects/

 

This is written at Step 2:

For now, reach the admin folder, then go to /themes/default/template/controllers/products. In this folder, you’ll see a bunch of tpl files whose names are equal to the name of the sections the product page is divided into. For simplicity, I will choose the first one, informations. Copy informations.tpl and go back to the main folder. Now access override/controllers/admin/templates/. We need to recreate the controller name folder structure inside, in our case, simply products. THe final directory structure is override/controllers/admin/templates/products/. Once you’re done, paste the information template file inside.

I just can't find the .tpl file for manufacturer. Surely I look in the manufacturers-folder not in the product-folder :D

The only thing I found is: \adminXXXX\themes\default\template\controllers\manufacturers\helpers\view\view.tpl ... But this seems to be the tpl file for the manufacturer-list not the detailed manufacturer editing-mask. At least I didn't find the correct place to insert my field.

 

Any ideas?

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

in this case you have to extend object definition here: contorllers/admin/AdminManufacturersController.php

public function renderForm()
	{
		$this->fields_form = array(
			'tinymce' => true,
			'legend' => array(
				'title' => $this->l('Manufacturers:'),
				'image' => '../img/admin/manufacturers.gif'
			),
			'input' => array(
				array(
					'type' => 'text',
					'label' => $this->l('Name:'),
					'name' => 'name',
					'size' => 40,
					'required' => true,
					'hint' => $this->l('Invalid characters:').' <>;=#{}'
				),
				array(
					'type' => 'textarea',
					'label' => $this->l('Short description:'),
					'name' => 'short_description',
					'lang' => true,
					'cols' => 60,
					'rows' => 10,
					'class' => 'rte',
					'hint' => $this->l('Invalid characters:').' <>;=#{}'
				),
				array(
					'type' => 'textarea',
					'label' => $this->l('Description:'),
					'name' => 'description',
					'lang' => true,
					'cols' => 60,
					'rows' => 10,
					'class' => 'rte',
					'hint' => $this->l('Invalid characters:').' <>;=#{}'
				),
				array(
					'type' => 'file',
					'label' => $this->l('Logo:'),
					'name' => 'logo',
					'display_image' => true,
					'desc' => $this->l('Upload a manufacturer 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 inside the field, write something, and 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')
						)
					)
				)
			)
		);

Link to comment
Share on other sites

This thing drives me crazy :angry::wacko:

At least it works almost now :)

 

My '\override\classes\Manufacturer.php'-file looks like this:

<?php
Class Manufacturer extends ManufacturerCore
{
	public $website;
	
    public function __construct($id_manufacturer = null, $id_lang = null)
    {
        self::$definition['fields']['website'] = array('type' => self::TYPE_STRING);
        parent::__construct($id_manufacturer, $id_lang);
    }
}
?>

This file seems to work because my custom field shows up in the front-office.

But i have a little question: What is '$id_manufacturer = null, $id_lang = null' standing for? It's more or less copy-pasted from the tutorial but I want to look behind the logic. In the tutorial there were even more parameters like $id_shop or $full ...

 

My '\override\controllers\admin\AdminManufacturersController.php'-file looks like this:

<?php
Class AdminManufacturersController extends AdminManufacturersControllerCore
{
	public function renderForm()
	{
		$this->fields_form = array(
			'tinymce' => true,
			'legend' => array(
				'title' => $this->l('Manufacturers:'),
				'image' => '../img/admin/manufacturers.gif'
			),
			'input' => array(
				array(
					'type' => 'text',
					'label' => $this->l('Name:'),
					'name' => 'name',
					'size' => 40,
					'required' => true,
					'hint' => $this->l('Invalid characters:').' <>;=#{}'
				),
				array(
					'type' => 'text',
					'label' => $this->l('Website:'),
					'name' => 'website',
					'size' => 128,
					'required' => false
				),
				array(
					'type' => 'textarea',
					'label' => $this->l('Short description:'),
					'name' => 'short_description',
					'lang' => true,
					'cols' => 60,
					'rows' => 10,
					'autoload_rte' => 'rte', //Enable TinyMCE editor for short description
					'hint' => $this->l('Invalid characters:').' <>;=#{}'
				),
				array(
					'type' => 'textarea',
					'label' => $this->l('Description:'),
					'name' => 'description',
					'lang' => true,
					'cols' => 60,
					'rows' => 10,
					'autoload_rte' => 'rte', //Enable TinyMCE editor for description
					'hint' => $this->l('Invalid characters:').' <>;=#{}'
				),
				array(
					'type' => 'file',
					'label' => $this->l('Logo:'),
					'name' => 'logo',
					'display_image' => true,
					'desc' => $this->l('Upload a manufacturer 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 inside the field, write something, and 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')
						)
					)
				)
			)
		);

		if (!($manufacturer = $this->loadObject(true)))
			return;

		if (Shop::isFeatureActive())
		{
			$this->fields_form['input'][] = array(
				'type' => 'shop',
				'label' => $this->l('Shop association:'),
				'name' => 'checkBoxShopAsso',
			);
		}

		$this->fields_form['submit'] = array(
			'title' => $this->l('Save   '),
			'class' => 'button'
		);

		$image = ImageManager::thumbnail(_PS_MANU_IMG_DIR_.'/'.$manufacturer->id.'.jpg', $this->table.'_'.(int)$manufacturer->id.'.'.$this->imageType, 350, $this->imageType, true);

		$this->fields_value = array(
			'image' => $image ? $image : false,
			'size' => $image ? filesize(_PS_MANU_IMG_DIR_.'/'.$manufacturer->id.'.jpg') / 1000 : false
		);

		foreach ($this->_languages as $language)
		{
			$this->fields_value['short_description_'.$language['id_lang']] = htmlentities(stripslashes($this->getFieldValue(
				$manufacturer,
				'short_description',
				$language['id_lang']
			)), ENT_COMPAT, 'UTF-8');

			$this->fields_value['description_'.$language['id_lang']] = htmlentities(stripslashes($this->getFieldValue(
				$manufacturer,
				'description',
				$language['id_lang']
			)), ENT_COMPAT, 'UTF-8');
		}

		return AdminManufacturersController::renderForm();
	}
}
?>

It seems to override the existing file but it does not work.

 

I get the following error when I trie to edit a manufacturer in the back-office: Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 65488 bytes) in C:\xampp\htdocs\XXX\classes\Translate.php on line 1809

 

Today I got this error (didn't change anything): Fatal error: Maximum execution time of 30 seconds exceeded in C:\xampp\htdocs\XXXX\classes\ImageManager.php on line 49

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

I get the following error when I trie to edit a manufacturer in the back-office: Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 65488 bytes) in C:\xampp\htdocs\XXX\classes\Translate.php on line 1809

 

not-enough free ram memory to run "translate" feature. you need to increase memory limit in php.ini file

 

 

Today I got this error (didn't change anything): Fatal error: Maximum execution time of 30 seconds exceeded inC:\xampp\htdocs\XXXX\classes\ImageManager.php on line 49

 

the same as above, but this message is related to script execution time. you can increase limit in .php.ini file too

Link to comment
Share on other sites

Changed them in the php.ini to the values written in my last post.

 

I think the code gets into an endless loop. It loads and loads until an error pops up.

 

I just added one field. Shouldn't have a big effect on memory or execution time, should it?

Link to comment
Share on other sites

  • 4 years later...

Hi,

Did you found the solution ?

I have exactly the same problem to add a field "email" in the SupplierController. My override of AdminSupplierController is OK, my override of Supplier class also...but the field don't appear in the form. Of course the column "eamil" has beed added in the supplier DB.

I tried to do this to verify the datas in my override

class AdminSuppliersController extends AdminSuppliersControllerCore
{

    
	public function renderForm()
    {
        // loads current warehouse
        if (!($obj = $this->loadObject(true))) {
            return;
        }

		print_r($obj);
		exit();

And I see the "email" in the object ! Why not in the form ?

Link to comment
Share on other sites

  • 3 weeks later...
  • 2 weeks 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...