Jump to content

Bad SQL query Unknown column 'sa.active' in 'where clause'


Zigmunds

Recommended Posts

Hello dear PrestaShop friends and developers,

I have Prestashop 1.7.6.7 version and get an issue in back office on Monitoring page.

Bad SQL query
Unknown column 'sa.active' in 'where clause'

... And I don't see products without pictures anymore on Monitoring page.

I din't find any solution on Google.

Could you please provide me with help, how to resolve this issue?

Thank you very much!

Anotācija 2020-07-30 112219.jpg

Link to comment
Share on other sites

  • 1 month later...
  • 5 months later...
  • 4 months later...

Insert in classes / controller / AdminController.php at line 898 this code snippet:
if(!empty($filters['trackingproducts_without_photoFilter_active'])){ $alias = 'a'; }

This should be like this:

if (isset($value[1]) && !empty($value[1])) { if (!Validate::isDate($value[1])) { $this->errors[] = $this->trans('The \'To\' date format is invalid (YYYY-MM-DD)', array(), 'Admin.Notifications.Error'); } else { $sql_filter .= ' AND '.pSQL($key).' <= \''.pSQL(Tools::dateTo($value[1])).'\''; } } } else { $sql_filter .= ' AND '; $check_key = ($key == $this->identifier || $key == '`'.$this->identifier.'`'); $alias = ($definition && !empty($definition['fields'][$filter]['shop'])) ? 'sa' : 'a';

---> if(!empty($filters['trackingproducts_without_photoFilter_active'])){ $alias = 'a'; } <--- inserted

if ($type == 'int' || $type == 'bool') { $sql_filter .= (($check_key || $key == '`active`') ? $alias.'.' : '').pSQL($key).' = '.(int)$value.' '; } elseif ($type == 'decimal') { $sql_filter .= ($check_key ? $alias.'.' : '').pSQL($key).' = '.(float)$value.' '; } elseif ($type == 'select') { $sql_filter .= ($check_key ? $alias.'.' : '').pSQL($key).' = \''.pSQL($value).'\' '; } elseif ($type == 'price') { $value = (float)str_replace(',', '.', $value); $sql_filter .= ($check_key ? $alias.'.' : '').pSQL($key).' = '.pSQL(trim($value)).' '; } else { $sql_filter .= ($check_key ? $alias.'.' : '').pSQL($key).' LIKE \'%'.pSQL(trim($value)).'%\' '; }

I found this solution on https://github.com/PrestaShop/PrestaShop/issues/14923

I inserted it directly but it is better to put it in the override so it would not be overwritten when a update is made.

 

Link to comment
Share on other sites

Hello, In AdminMyworldProducts controller. you show product  and you try to handle  the sorting of the product. In your sorting query you use  sa.active

for filter , you an check your table name is alias with sa in the query or you have different alias. This occur some time when we copy paste the query from other place :)

 

If you paste the code of your AdminMyworldProducts code then we can check and give you a right answer

 

Thank you

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