Dallerdkj Posted April 24, 2014 Share Posted April 24, 2014 (edited) Hello everyone. I need some help with this SQL code, so i also can show the name of the discount used - This is important, because it's used for tracking purposes. I have this code: public function __construct() { $this->table = 'order'; $this->className = 'Order'; $this->lang = false; $this->addRowAction('view'); $this->explicitSelect = true; $this->deleted = false; $this->context = Context::getContext(); $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'; $this->_join = ' LEFT JOIN `'._DB_PREFIX_.'customer` c ON (c.`id_customer` = a.`id_customer`) 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'; $statuses_array = array(); $statuses = OrderState::getOrderStates((int)$this->context->language->id); foreach ($statuses as $status) $statuses_array[$status['id_order_state']] = $status['name']; $this->fields_list = array( 'total_discounts' => array( 'title' => $this->l('Discounts'), 'align' => 'center', 'width' => 25 ), The code above, shows the total discount the customer had. This is where the problem begins. I can't figure out, how to modify the SQL statement, so i can display discount name. I know the discount code, and id_customer is located in _cart_rules, and row "code" in my MYSQL Db. Can anyone please help me achieve this goal. Thanks guys :-) Edited April 25, 2014 by vekia (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted April 24, 2014 Share Posted April 24, 2014 add: LEFT JOIN `'._DB_PREFIX_.'order_cart_rule` ocr ON (ocr.`id_order` = a.`id_order`); modify: (add ocr.*,) $this->_select = ' ocr.*, a.id_currency, Link to comment Share on other sites More sharing options...
Dallerdkj Posted April 24, 2014 Author Share Posted April 24, 2014 (edited) Thanks Vekia! Will this enable me to show the discount name, let's say the discount name is "Joe". Will this enable me to show the discount name? I've tried to print array, and cant seem to find anything. Hmm. Im pasting my code: Thanks Edit: Im modifying it with the full code -> class AdminOrdersControllerCore extends AdminController { public $toolbar_title; public function __construct() { $this->table = 'order'; $this->className = 'Order'; $this->lang = false; $this->addRowAction('view'); $this->explicitSelect = true; $this->allow_export = true; $this->deleted = false; $this->context = Context::getContext(); $this->_select = ' ocr.*, a.id_currency, 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'; $this->_join = ' LEFT JOIN `'._DB_PREFIX_.'order_cart_rule` ocr ON (ocr.`id_order` = a.`id_order`); LEFT JOIN `'._DB_PREFIX_.'customer` c ON (c.`id_customer` = a.`id_customer`) 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'; $statuses_array = array(); $statuses = OrderState::getOrderStates((int)$this->context->language->id); foreach ($statuses as $status) $statuses_array[$status['id_order_state']] = $status['name']; print_r($this); $this->fields_list = array( 'name-of-discount' => array( 'title' => $this->l('name-of-discount'), 'align' => 'center', 'width' => 25 ), Edited April 24, 2014 by Dallerdkj (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted April 24, 2014 Share Posted April 24, 2014 oops i forgot about one thig: add also field "name" to $this->fields_list Link to comment Share on other sites More sharing options...
vekia Posted April 24, 2014 Share Posted April 24, 2014 i prepared modification: public function __construct() { $this->bootstrap = true; $this->table = 'order'; $this->className = 'Order'; $this->lang = false; $this->addRowAction('view'); $this->explicitSelect = true; $this->allow_export = true; $this->deleted = false; $this->context = Context::getContext(); $this->_select = ' ocr.`name` AS vname, 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_.'order_cart_rule` AS ocr ON ocr.`id_order` = a.`id_order` 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->_orderBy = 'id_order'; $this->_orderWay = 'DESC'; $statuses = OrderState::getOrderStates((int)$this->context->language->id); foreach ($statuses as $status) $this->statuses_array[$status['id_order_state']] = $status['name']; $this->fields_list = array( 'id_order' => array( 'title' => $this->l('ID'), 'align' => 'text-center', 'class' => 'fixed-width-xs' ), 'reference' => array( 'title' => $this->l('Reference') ), 'vname' => array( 'title' => $this->l('voucher name') ), 'new' => array( 'title' => $this->l('New client'), 'align' => 'text-center', 'type' => 'bool', 'tmpTableFilter' => true, 'orderby' => false ), 'customer' => array( 'title' => $this->l('Customer'), 'havingFilter' => true, ), ); effect: Link to comment Share on other sites More sharing options...
Dallerdkj Posted April 25, 2014 Author Share Posted April 25, 2014 Its working perfect! Thank you for your great help Vekia.What would this forum do without you - I have read alot of topics where you help us out, and i must say im a Big fan :-) One more question, im still on the 1.5.6 - Is the screenshot a stable 1.6? And can you mark this as solved? Have a great weekend! Daniel Link to comment Share on other sites More sharing options...
vekia Posted April 25, 2014 Share Posted April 25, 2014 screenshot that i attached is from prestashop 1.6 in my opinion it's stable, but if i were you, i will wait for 1.6.1 release as you wish - topic marked as solved Link to comment Share on other sites More sharing options...
Dallerdkj Posted April 25, 2014 Author Share Posted April 25, 2014 screenshot that i attached is from prestashop 1.6 in my opinion it's stable, but if i were you, i will wait for 1.6.1 release as you wish - topic marked as solved Perfect Thank you for your tip! I must say that the layout on the screenshot is beautiful. Looking forward to try it in the future Link to comment Share on other sites More sharing options...
vekia Posted April 25, 2014 Share Posted April 25, 2014 indeed, design of new prestashop 1.6 is awesome, both in back and front office. Usually versions with number x.0 (like 1.4.0.3, 1.5.0.7, 1.6.0.6 etc.) arent so stable, with latest upgrade of prestashop 1.6.x engine (1.6.0.6 version) we are one step closer to the 1.6.1 in my opinion it's a matter of several weeks but will see Link to comment Share on other sites More sharing options...
apositivo Posted April 28, 2014 Share Posted April 28, 2014 (edited) ok Edited May 21, 2014 by apositivo (see edit history) Link to comment Share on other sites More sharing options...
hammerleit Posted February 8, 2016 Share Posted February 8, 2016 is it possible to Show the voucher code instead of Voucher Name, as mentioned above? How do i have to Change codè? Link to comment Share on other sites More sharing options...
hammerleit Posted February 24, 2016 Share Posted February 24, 2016 @Vekia Code above works, but if you try to sort by voucher Name, System hangs by the way: Is it possible to show voucher CODE instead of voucher NAME? Where in admin can i see the used voucher code? is there any module that makes it Show me the used voucher code?? Link to comment Share on other sites More sharing options...
hammerleit Posted February 24, 2016 Share Posted February 24, 2016 If you try to make a search for voucher with the code used above it results in error: unknown column 'voucher' in 'where clause' and nothing can be done. Vou have to undo changes and reload page.... 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