I am trying to list orders based on delivery country. For that purpose I have written sql query below. It works fine on database. But when i try to implement on AdminOrderController.php file, it throws syntax error which i tried to solve in many ways by changing syntax.
How can i implement this where clause WHERE country_lang.name = 'France' on php-side?
Could you help me to fix this issue?
Error Message:
Bad SQL query
You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version
for the right syntax to use near
'country_lang.name = 'France' ORDER BY a.`id_order`
DESC LIMIT 0,50' at line 22
Sql Query:
SELECT
ps_orders.id_currency,
ps_orders.id_order AS id_pdf,
CONCAT(LEFT(c.`firstname`, 1), '. ', c.`lastname`) AS `customer`,
osl.`name` AS `osname`,
os.`color`,
IF((SELECT COUNT(so.id_order) FROM `ps_orders` so WHERE so.id_customer =
ps_orders.id_customer) > 1, 0, 1) as new,
country_lang.name as cname,
IF(ps_orders.valid, 1, 0) badge_success
FROM ps_orders
LEFT JOIN `ps_customer` c ON (c.`id_customer` = ps_orders.`id_customer`)
INNER JOIN `ps_address` address ON address.id_address =
ps_orders.id_address_delivery
INNER JOIN `ps_country` country ON address.id_country = country.id_country
INNER JOIN `ps_country_lang` country_lang ON (country.`id_country` =
country_lang.`id_country` AND country_lang.`id_lang` = 3)
LEFT JOIN `ps_order_state` os ON (os.`id_order_state` = ps_orders.`current_state`)
LEFT JOIN `ps_order_state_lang` osl ON (os.`id_order_state` = osl.`id_order_state`
AND osl.`id_lang` = 3)
WHERE country_lang.name = 'France'
ORDER BY id_order DESC
Php Codes:
$this->_select = '
a.id_currency,
a.id_order AS id_pdf,
CONCAT(LEFT(c.`firstname`, 1), \'. \', c.`lastname`) AS `customer`,
osl.`name` AS `osname`,
os.`color`,
IF((SELECT COUNT(so.id_order) FROM `'._DB_PREFIX_.'orders` so WHERE so.id_customer = a.id_customer) > 1, 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_.'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->_where = '';
$this->_orderBy = 'id_order';
$this->_orderWay = 'DESC';
Solution:
$this->_where = 'AND country_lang.id_country = 8';
解:
$this->_where = 'AND country_lang.id_country = 8';
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.