Jump to content

cannot edit column in supplier_shop


MrGumby

Recommended Posts

Using PrestaShop 1.6.0.5

 

I want store information per supplier, per shop, so I decide create new column for it in `supplier_shop` table. Namely it is column `margin`.

 

To  be able to edit it from BO, I created override of AdminSupplierController and Supplier class. I can see values from DB when click edit, but when I click save, it throws error:

Unknown column 'margin' in 'field list'

UPDATE `ps_supplier` SET `id_supplier` = '2',`name` = 'name',`active` = '1',`date_add` = '2014-02-19 22:26:10',`date_upd` = '2014-04-01 22:00:18',`margin` = '50' WHERE `id_supplier` = 2

That is because it tries insert all data into `supplier` table, it did not create join with shop table counterpart, but it fetches data properly, so problem is only with insert statement.

 

My overrides are like this:

 

AdminSuppliersController.php

class AdminSuppliersController extends AdminSuppliersControllerCore
{
// modify only this method 
	public function renderForm()
	{
		...                
// modify fields_form array
		$this->fields_form = array(
		    'legend' => array(
			'title' => $this->l('Suppliers'),
			'icon' => 'icon-truck'
		    ),
		    'input' => array(
			array(
			    'type' => 'hidden',
			    'name' => 'id_address',
			),
                        ...


// add this element to fields_form
			array(
			    'type' => 'text',
			    'label' => $this->l('Margin rate'),
			    'name' => 'margin',
// experiment with add 'shop' => true did not help, but neither breaks anything
			    'shop' => true,
			    'col' => 2,
			    'hint' => $this->l('Basic margin for supplier, used to compute minimal price of items '),
                        ...

			
			)
		    ),
		    'submit' => array(
			'title' => $this->l('Save'),
		    )
		);

// call AdminController:: instead parent::
		return AdminController::renderForm();
	}

}

Supplier.php

class Supplier extends SupplierCore
{
	/** @var float supplier margin */
	public $margin;

	public function __construct($id = null, $id_lang = null)
	{
		self::$definition['fields']['margin'] = array('type' => self::TYPE_FLOAT, 'shop' => true, 'validate' => 'isFloat');
		parent::__construct($id, $id_lang);
	}

}

I searched for method that handles inserting in Supplier class, but I cannot get my head around it. If could someone lend helpful hand, It will be much appreciated.

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