Jump to content

SOLVED! - Override Backoffice Controllers - Does Not Work


prestatent

Recommended Posts

Some further information, just in case anyone can help.

 

I'm trying to add the web address for each store, but using the AdminStoresController.php override does not show the field in the form.

 

Is there a Prestashop official way of doing this, or will it turn out to be a hack. Frontoffice controllers seem to work fine.

Link to comment
Share on other sites

Thanks for all the help guys. Really appreciate it!!!!

 

For the record, due to the lack of any answers on this subject, I've changed the AdminStoresController.php CORE file. This means that should I upgrade in the future, as you all know, I'll have to apply the same changes.

 

Very poor from Prestashop in this respect. What is the point in allowing overrides for some files and not others. Utterly pointless.

 

If I'm mistaken in this, I'm ready to be corrected, but due to the lack of any answers I think I must be correct.

Link to comment
Share on other sites

class AdminStoresController extends AdminStoresControllerCore
{
	public function renderForm()
	{
		if (!($obj = $this->loadObject(true)))
			return;

		$image = _PS_STORE_IMG_DIR_.$obj->id.'.jpg';
		$image_url = ImageManager::thumbnail($image, $this->table.'_'.(int)$obj->id.'.'.$this->imageType, 350,
			$this->imageType, true, true);
		$image_size = file_exists($image) ? filesize($image) / 1000 : false;

		$this->fields_form = array(
			'legend' => array(
				'title' => $this->l('Stores'),
				'icon' => 'icon-home'
			),
			'input' => array(

                // ############################## Start of DA08092014 ########################### //
				array(
					'type' => 'select',
					'label' => $this->l('VIP Code'),
					'name' => 'id_vip',
					'required' => false,
					'default_value' => 0,
					'options' => array(
					'query' => Country::getVips(),
					'id' => 'id_vip',
					'name' => 'name',
					)
				),
                // ############################## End of DA08092014 ########################### //

				array(
					'type' => 'text',
					'label' => $this->l('Name'),
					'name' => 'name',
					'required' => false,
					'hint' => array(
						$this->l('Store name (e.g. City Center Mall Store).'),
						$this->l('Allowed characters: letters, spaces and %s')
					)
				),
				array(
					'type' => 'text',
					'label' => $this->l('Address'),
					'name' => 'address1',
					'required' => true
				),
				array(
					'type' => 'text',
					'label' => $this->l('Address (2)'),
					'name' => 'address2'
				),
				array(
					'type' => 'text',
					'label' => $this->l('Zip/postal Code'),
					'name' => 'postcode',
					'required' => true
				),
				array(
					'type' => 'text',
					'label' => $this->l('City'),
					'name' => 'city',
					'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),
						'id' => 'id_country',
						'name' => 'name',
					)
				),
				array(
					'type' => 'select',
					'label' => $this->l('State'),
					'name' => 'id_state',
					'required' => true,
					'options' => array(
						'id' => 'id_state',
						'name' => 'name',
                        'query' => null
					)
				),
				array(
					'type' => 'latitude',
					'label' => $this->l('Latitude / Longitude'),
					'name' => 'latitude',
					'required' => true,
					'maxlength' => 12,
					'hint' => $this->l('Store coordinates (e.g. 45.265469/-47.226478).')
				),
				array(
					'type' => 'text',
					'label' => $this->l('Phone'),
					'name' => 'phone'
				),
				array(
					'type' => 'text',
					'label' => $this->l('Fax'),
					'name' => 'fax'
				),
				array(
					'type' => 'text',
					'label' => $this->l('Email address'),
					'name' => 'email'
				),
				array(
					'type' => 'textarea',
					'label' => $this->l('Note'),
					'name' => 'note',
					'cols' => 42,
					'rows' => 4
				),
				array(
					'type' => 'switch',
					'label' => $this->l('Status'),
					'name' => 'active',
					'required' => false,
					'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')
						)
					),
					'hint' => $this->l('Whether or not to display this store.')
				),
				array(
					'type' => 'file',
					'label' => $this->l('Picture'),
					'name' => 'image',
					'display_image' => true,
					'image' => $image_url ? $image_url : false,
					'size' => $image_size,
					'hint' => $this->l('Storefront picture.')
				)
			),
			'hours' => array(
			),
			'submit' => array(
				'title' => $this->l('Save'),
			)
		);
		
		if (Shop::isFeatureActive())
		{
			$this->fields_form['input'][] = array(
				'type' => 'shop',
				'label' => $this->l('Shop association'),
				'name' => 'checkBoxShopAsso',
			);
		}

		$days = array();
		$days[1] = $this->l('Monday');
		$days[2] = $this->l('Tuesday');
		$days[3] = $this->l('Wednesday');
		$days[4] = $this->l('Thursday');
		$days[5] = $this->l('Friday');
		$days[6] = $this->l('Saturday');
		$days[7] = $this->l('Sunday');

		$hours = $this->getFieldValue($obj, 'hours');
		if (!empty($hours))
			$hours_unserialized = Tools::unSerialize($hours);

		$this->fields_value = array(
			'latitude' => $this->getFieldValue($obj, 'latitude') ? $this->getFieldValue($obj, 'latitude') : Configuration::get('PS_STORES_CENTER_LAT'),
			'longitude' => $this->getFieldValue($obj, 'longitude') ? $this->getFieldValue($obj, 'longitude') : Configuration::get('PS_STORES_CENTER_LONG'),
			'days' => $days,
			'hours' => isset($hours_unserialized) ? $hours_unserialized : false
		);

		return parent::renderForm();
	}
}

Hi

 

1. This code is used to add a new field to the store input form. I've already created the database field on the ps_store table

 

2. Above code placed in /override/controllers/admin

 

3. I did delete the class_index.php from cache/

 

The code works fine, but it should be contained in an override.

 

Thanks

Link to comment
Share on other sites

Thanks for looking at this.

 

As you see, there does seem to be inconsistencies with overrides. If anyone else has had this experience, or its a know flaw in Prestashop, I would interested in when it's being fixed.

 

Prestashop team, do you know about this issue?

 

Thanks

Link to comment
Share on other sites

Hello, I think I know why your override does not work. I ran in to the same problem

At the end of the renderForm, you use return parent::renderForm().

This is telling PrestaShop to ignore your code and use the core code.

Changing that line to calling "grandparent" will fix this issue. So AdminController:renderForm() at the end of the function, will use your code and then call the main functions needed to render the form.

  • Like 2
  • Thanks 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...