Guest Posted January 25, 2020 Share Posted January 25, 2020 (edited) Hi to all. I need to add to the order list filtering to avoid showing orders with status 6. Mean, insert: WHERE os.`id_order_state` NOT IN (6) OR a.`current_state` NOT IN (6) I need to advise where to put this part of the SQL query to be valid even when selecting another filter. I put the code here and it doesn't work. protected $statuses_array = array(); public function __construct() { $this->bootstrap = true; $this->table = 'order'; $this->className = 'Order'; $this->lang = false; $this->addRowAction('view'); $this->addRowAction('delete'); $this->explicitSelect = true; $this->allow_export = true; $this->deleted = false; parent::__construct(); $this->_select = ' a.id_currency, a.id_order AS id_pdf, CONCAT(LEFT(c.`firstname`, 1), \'. \', c.`lastname`) AS `customer`, osl.`name` AS `osname`, IF(carrier.`name` = "0", "-", carrier.`name`) AS `carriername`, os.`color`, IF((SELECT so.id_order FROM `'._DB_PREFIX_.'orders` so WHERE os.`id_order_state` NOT IN (6) OR a.`current_state` NOT IN (6) AND so.id_customer = a.id_customer AND so.id_order < a.id_order LIMIT 1) > 0, 0, 1) as new, country_lang.name as cname, IF(a.valid, 1, 0) badge_success'; $this->_join = ' LEFT JOIN `'._DB_PREFIX_.'customer` c ON (c.`id_customer` = a.`id_customer`) INNER JOIN `'._DB_PREFIX_.'address` address ON address.id_address = a.id_address_delivery INNER JOIN `'._DB_PREFIX_.'country` country ON address.id_country = country.id_country INNER JOIN `'._DB_PREFIX_.'country_lang` country_lang ON (country.`id_country` = country_lang.`id_country` AND country_lang.`id_lang` = '.(int)$this->context->language->id.') LEFT JOIN `'._DB_PREFIX_.'carrier` carrier ON a.id_carrier = carrier.id_carrier LEFT JOIN `'._DB_PREFIX_.'order_state` os ON (os.`id_order_state` = a.`current_state`) LEFT JOIN `'._DB_PREFIX_.'order_state_lang` osl ON (os.`id_order_state` = osl.`id_order_state` AND osl.`id_lang` = '.(int)$this->context->language->id.')'; $this->_orderBy = 'id_order'; $this->_orderWay = 'DESC'; $this->_use_found_rows = true; Thank you Edited January 26, 2020 by Guest (see edit history) Link to comment Share on other sites More sharing options...
Knowband Plugins Posted January 25, 2020 Share Posted January 25, 2020 You have added the where condition at the wrong place. Where condition can be added in $this->_select. (Existing where condition is for different purpose) Revert the file & try adding the below line just after the $this->_use_found_rows = true; $this->_where.=' AND (os.`id_order_state` NOT IN (6) OR a.`current_state` NOT IN (6))'; Link to comment Share on other sites More sharing options...
Guest Posted January 25, 2020 Share Posted January 25, 2020 39 minutes ago, Knowband Plugins said: You have added the where condition at the wrong place. Where condition can be added in $this->_select. (Existing where condition is for different purpose) Revert the file & try adding the below line just after the $this->_use_found_rows = true; $this->_where.=' AND (os.`id_order_state` NOT IN (6) OR a.`current_state` NOT IN (6))'; It works perfectly. Thank you for your help. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now