Jump to content

[SOLVED] Can't add product condition column to backoffice product list


Schtev

Recommended Posts

In the backoffice I want to add a column for product condition to the products list. I went to controllers/admin/AdminProductsController.php and added the following to the $this->field_list definition:
 

                $this->fields_list['condition'] = array(
                        'title' => $this->l('Condition'),
                        'align' => 'left'
                );

Much to my surprise, this resulted in the following error:

 

Bad SQL query
Column 'condition' in field list is ambiguous

 

I went into the MySQL command line to see what's up. I typed the following query:

SELECT condition FROM ps_product;

This resulted in an incorrect syntax error. Puzzling! Further research revealed that "condition" is a reserved word in MySQL, so modifying the query like so solved the problem:

SELECT `condition` FROM ps_product;

Is this why my PHP code fails? Or am I missing something?

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

hello

this field is ambigious because it also appears in other tables.

what to do?

in select clause you have to define different name for example p.condition as pcondition

then in field definition instead of condition use pcondition

Link to comment
Share on other sites

Yup! That did it. Thank you. :)

 

For the benefit of others, here's the solution:

 

Select statement:

$this->_select .= $alias.'.`condition` AS cond, ';

Field statement:

$this->fields_list['cond'] = array(
        'title' => $this->l('Condition'),
        'align' => 'left',
        'width' => 80
);
Link to comment
Share on other sites

  • 1 year later...

 am creating report module based on dispatched  order and pending order my question is in SQL

 1.How to add "where" clause ,2. How to find Deliver product order in presta shop table in db , 3. i was written where condition for current date and yesterday in controller its not working anybody pls suggest my queries .

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

  • 11 months 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...