sting5 Posted August 16, 2015 Share Posted August 16, 2015 (edited) Hi, 1.4.8.2 here, Been struggling for almost two days with, this, still can't figure it out. I'm trying to highlight orders that have COD payment selected, in BO, so my employees can see them better and avoid mistakes. What I have figured out so far: in admin/tabs/AdminOrders.PHP I've added a function into existing code and changed the array variable to look for it: $statesArray = array(); $states = OrderState::getOrderStates((int)($cookie->id_lang)); foreach ($states AS $state) $statesArray[$state['id_order_state']] = $state['name']; //fuction to filter if COD or other function check_If_COD (){ $modules_infos = PaymentModule::getInstalledPaymentModules(); foreach ($modules_infos AS $module_infos) { $module = Module::getInstanceByName($module_infos['name']); if ($module == 'cashondelivery'){ return '<b class="COD_color">'; }else{ return '<b class="not_a_COD">';} } } $this->fieldsDisplay = array( 'id_order' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25), 'new' => array('title' => $this->l('New'), 'width' => 25, 'align' => 'center', 'type' => 'bool', 'filter_key' => 'new', 'tmpTableFilter' => true, 'icon' => array(0 => 'blank.gif', 1 => 'news-new.gif'), 'orderby' => false), 'customer' => array('title' => $this->l('Customer'), 'widthColumn' => 160, 'width' => 140, 'filter_key' => 'customer', 'tmpTableFilter' => true), 'total_paid' => array('title' => $this->l('Total'), 'width' => 70, 'align' => 'right', 'prefix' => '<b>', 'suffix' => '</b>', 'price' => true, 'currency' => true), 'payment' => array('title' => $this->l('Payment'), 'width' => 100, //COD exclusion by color 'prefix' => check_If_COD(), 'suffix' => '</b>'), 'osname' => array('title' => $this->l('Status'), 'widthColumn' => 230, 'type' => 'select', 'select' => $statesArray, 'filter_key' => 'os!id_order_state', 'filter_type' => 'int', 'width' => 200), 'date_add' => array('title' => $this->l('Date'), 'width' => 35, 'align' => 'right', 'type' => 'datetime', 'filter_key' => 'a!date_add'), 'id_pdf' => array('title' => $this->l('PDF'), 'callback' => 'printPDFIcons', 'orderby' => false, 'search' => false)); parent::__construct(); } but for some reason, it doesn't work - the system gives me this message: Notice: Object of class CashOnDelivery could not be converted to int in /home/public_html/admin/tabs/AdminOrders.php on line63 I have no idea how to fix this. Any help would be really appreciated! Edited August 16, 2015 by sting5 (see edit history) Link to comment Share on other sites More sharing options...
sting5 Posted August 17, 2015 Author Share Posted August 17, 2015 Hello? Anyone, please...? Link to comment Share on other sites More sharing options...
PhpMadman Posted August 17, 2015 Share Posted August 17, 2015 Hi. I have never coded for PS 1.4. But fow what I can understand from your code, is that. You use the modules name to load it in to $module $module is now a Object, with the module loaded in to it. Then you try to check if $module is cod string. That's why it fails. Remove the getInstanceByName line, and then simply check if $module_infos['name'] is cod Link to comment Share on other sites More sharing options...
sting5 Posted August 18, 2015 Author Share Posted August 18, 2015 (edited) Hi PhpMadman, first of all - thanks for Your suggestion Yep, the code is now clean, no error messages, but all payment modes are now highlited in BO. I suppose my function might be wrong in general... I'm not that good with PHP (very beginner level really), but might that be that: function check_If_COD (){ $modules_infos = PaymentModule::getInstalledPaymentModules(); <--gets all installed modules foreach ($modules_infos AS $module_infos) { $module = ($module_infos['name']); <-- gets names of all installed modules if ($module == 'cashondelivery'){ <-- finds that one of the installed modules is cashondelivery return '<b class="COD_color">'; <-- always uses the first return result because it always meets condition }else{ return '<b class="not_a_COD">';} } } Might that be that I need to change the core of the check_if_COD function? I mean call the database table "ps_orders", to then check value of "module" column, if it's "cashondelivery", then highlight the text. And in all other cases use second return string. I'm just not sure how to do this correctly... Thanks again! Edited August 18, 2015 by sting5 (see edit history) Link to comment Share on other sites More sharing options...
PhpMadman Posted August 18, 2015 Share Posted August 18, 2015 Yes. you are right. You need to grab the module field directly from the orders table. Something along this line. And also a where check that check id_order. SELECT IF(module = "cashondelivery", "<b class="COD_color">", "<b class="not_a_COD">") as cod FROM ps_orders Don't have time to look at it right now. Got to work. Link to comment Share on other sites More sharing options...
sting5 Posted August 18, 2015 Author Share Posted August 18, 2015 Thanks for a suggestion. You're offering this as a logical solution, not a code itself, I suppose...? I'm really weak on PHP, maybe You can tell me how the function should look, would really appreciate it! Link to comment Share on other sites More sharing options...
PhpMadman Posted August 18, 2015 Share Posted August 18, 2015 Hi. I'll try, but my previous code won't work. I need to find another way to do this. Link to comment Share on other sites More sharing options...
sting5 Posted August 19, 2015 Author Share Posted August 19, 2015 (edited) Thanks in advance, I will try to find the way to convert my logic into PHP language as well. [uPDATE]: Ok I've changed the function a bit, simplified it by using code that I've found in other AdminTabs files: function check_If_COD (){ if ($order['payment'] == 'cashondelivery'){ <-- deleted the variable setting payment name and went straight to the condition return '<b class="COD_color">'; }else{ return '<b class="not_a_COD">';} } Now I get different error Notice: Undefined variable: order in [...]/admin/tabs/AdminOrders.php on line 59 Funny part - the variable $order is mentioned in couple other php files, also in the same AdminOrders.php file and seem to work no problem, no errors in the code. But in my function, for some reason, it's considered undefined... Any idea why? Edited August 19, 2015 by sting5 (see edit history) Link to comment Share on other sites More sharing options...
PhpMadman Posted August 19, 2015 Share Posted August 19, 2015 Hi. We both been overthinking this. Delete all your code changes. This is why you should read the documentation... This code is used on my 1.6.1.0 test install, but the lines added should be the same. Find the word pay_color to find my added line. $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 so.id_order FROM `'._DB_PREFIX_.'orders` so WHERE 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(module = "bankwire","#ff0000","#ffffff") as pay_color, IF(a.valid, 1, 0) badge_success'; This part checks if the module is named bankwire, and then color it red #ff0000, if not bankwire, color it white. 'payment' => array( 'title' => $this->l('Payment'), 'color' => 'pay_color' ), Adds a colored element, just as the status column. Link to comment Share on other sites More sharing options...
sting5 Posted August 19, 2015 Author Share Posted August 19, 2015 Hi PHPMadman, great work with the code, can't stress enough how thankfull I am for Your time and effort in this, because my PHP skill is very amateur. I'm not sure if I understand which part goes where? I mean, this code should be put into AdminOrders.php file or different? Link to comment Share on other sites More sharing options...
PhpMadman Posted August 19, 2015 Share Posted August 19, 2015 (edited) Hi, Yes, all goes in to AdminOrders. I added the linenumbers, to the code. In the first part, add my IF(module line after line 43 as I have. IF((SELECT COUNT(so.id_order) FROM `'._DB_PREFIX_.'orders` so WHERE so.id_customer = a.id_customer) > 1, 0, 1) as new, IF(module = "bankwire","#ff0000","#ffffff") as pay_color, (SELECT COUNT(od.`id_order`) FROM `'._DB_PREFIX_.'order_detail` od WHERE od.`id_order` = a.`id_order` GROUP BY `id_order`) AS product_number'; Modify Line 62 (61 before) to include the 'pay_color' 'payment' => array('title' => $this->l('Payment'), 'width' => 100, 'color' => 'pay_color'), Hopefully that should do the trick. I'm not sure 1.4 supports the color attribute. *EDIT* Fixed payment code Edited August 19, 2015 by PhpMadman (see edit history) Link to comment Share on other sites More sharing options...
PhpMadman Posted August 19, 2015 Share Posted August 19, 2015 (edited) Hmm, I would say it dosent. Pff, and soultion was so simple... But anyway. Add that code, if it does nothing, it's a success, if it crashes PrestaShop, not so much... Then I can walk you through how to add the color support. Need to modify AdminTabs. Allready made a code for it, just need to test it on a PS 1.4... Edited August 19, 2015 by PhpMadman (see edit history) Link to comment Share on other sites More sharing options...
sting5 Posted August 20, 2015 Author Share Posted August 20, 2015 (edited) Well, that seemed to crash the file totally - Attaching the error message: 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 '// IF(module = "bankwire","#ff0000","#ffffff") as pay_color, (SELECT COUNT' at line 9 SELECT SQL_CALC_FOUND_ROWS a.*, 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 `ps_orders` so WHERE so.id_customer = a.id_customer) > 1, 0, 1) as new, // IF(module = "bankwire","#ff0000","#ffffff") as pay_color, (SELECT COUNT(od.`id_order`) FROM `ps_order_detail` od WHERE od.`id_order` = a.`id_order` GROUP BY `id_order`) AS product_number FROM `ps_orders` a LEFT JOIN `ps_customer` c ON (c.`id_customer` = a.`id_customer`) LEFT JOIN `ps_order_history` oh ON (oh.`id_order` = a.`id_order`) LEFT JOIN `ps_order_state` os ON (os.`id_order_state` = oh.`id_order_state`) LEFT JOIN `ps_order_state_lang` osl ON (os.`id_order_state` = osl.`id_order_state` AND osl.`id_lang` = 1) WHERE 1 AND oh.`id_order_history` = (SELECT MAX(`id_order_history`) FROM `ps_order_history` moh WHERE moh.`id_order` = a.`id_order` GROUP BY moh.`id_order`) ORDER BY `date_add` DESC LIMIT 0,50 I'm wondering if this means that this type of solution is only suitable with 1.6. platform version, but not 1.4? Edited August 20, 2015 by sting5 (see edit history) Link to comment Share on other sites More sharing options...
PhpMadman Posted August 21, 2015 Share Posted August 21, 2015 (edited) You can't have // in the command. Remove that, and see it works. I hope not. If it works for 1.4, it would be way easier then any other soultion I can think of. Edited August 21, 2015 by PhpMadman (see edit history) Link to comment Share on other sites More sharing options...
sting5 Posted August 21, 2015 Author Share Posted August 21, 2015 (edited) Success, seems to work fluently - no errors received - but there is no difference between payments right now, all seem the same. The AdminOrders.php file right now looks like this: $this->_select = ' 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, IF(module = "cashondelivery","#ff0000","#ffffff") as pay_color, <!-- ADDED THE LINE IN THE CODE --> (SELECT COUNT(od.`id_order`) FROM `'._DB_PREFIX_.'order_detail` od WHERE od.`id_order` = a.`id_order` GROUP BY `id_order`) AS product_number'; $this->_join = 'LEFT JOIN `'._DB_PREFIX_.'customer` c ON (c.`id_customer` = a.`id_customer`) LEFT JOIN `'._DB_PREFIX_.'order_history` oh ON (oh.`id_order` = a.`id_order`) LEFT JOIN `'._DB_PREFIX_.'order_state` os ON (os.`id_order_state` = oh.`id_order_state`) LEFT JOIN `'._DB_PREFIX_.'order_state_lang` osl ON (os.`id_order_state` = osl.`id_order_state` AND osl.`id_lang` = '.(int)($cookie->id_lang).')'; $this->_where = 'AND oh.`id_order_history` = (SELECT MAX(`id_order_history`) FROM `'._DB_PREFIX_.'order_history` moh WHERE moh.`id_order` = a.`id_order` GROUP BY moh.`id_order`)'; $statesArray = array(); $states = OrderState::getOrderStates((int)($cookie->id_lang)); foreach ($states AS $state) $statesArray[$state['id_order_state']] = $state['name']; $this->fieldsDisplay = array( 'id_order' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25), 'new' => array('title' => $this->l('New'), 'width' => 25, 'align' => 'center', 'type' => 'bool', 'filter_key' => 'new', 'tmpTableFilter' => true, 'icon' => array(0 => 'blank.gif', 1 => 'news-new.gif'), 'orderby' => false), 'customer' => array('title' => $this->l('Customer'), 'widthColumn' => 160, 'width' => 140, 'filter_key' => 'customer', 'tmpTableFilter' => true), 'total_paid' => array('title' => $this->l('Total'), 'width' => 70, 'align' => 'right', 'prefix' => '<b>', 'suffix' => '</b>', 'price' => true, 'currency' => true), 'payment' => array('title' => $this->l('Payment'), 'width' => 100, 'color' => 'pay_color'), // REPLACED PREVIOUS 'payment' line with Yours 'osname' => array('title' => $this->l('Status'), 'widthColumn' => 230, 'type' => 'select', 'select' => $statesArray, 'filter_key' => 'os!id_order_state', 'filter_type' => 'int', 'width' => 200), 'date_add' => array('title' => $this->l('Date'), 'width' => 35, 'align' => 'right', 'type' => 'datetime', 'filter_key' => 'a!date_add'), 'id_pdf' => array('title' => $this->l('PDF'), 'callback' => 'printPDFIcons', 'orderby' => false, 'search' => false)); parent::__construct(); } Edited August 21, 2015 by sting5 (see edit history) Link to comment Share on other sites More sharing options...
PhpMadman Posted August 21, 2015 Share Posted August 21, 2015 (edited) Excellent. Then that code works.Now we just need to add a few more lines in to another file.classes/AdminTab.phpStep 1 Replace this if (!isset($params['position']) AND (!isset($this->noLink) OR !$this->noLink)) echo ' onclick="document.location = \''.$currentIndex.'&'.$this->identifier.'='.$id.($this->view? '&view' : '&update').$this->table.'&token='.($token!=NULL ? $token : $this->token).'\'">'.(isset($params['prefix']) ? $params['prefix'] : ''); else echo '>'; With this. I just added some brackets { } if (!isset($params['position']) AND (!isset($this->noLink) OR !$this->noLink)) { echo ' onclick="document.location = \''.$currentIndex.'&'.$this->identifier.'='.$id.($this->view? '&view' : '&update').$this->table.'&token='.($token!=NULL ? $token : $this->token).'\'">'.(isset($params['prefix']) ? $params['prefix'] : ''); } else { echo '>'; } Save, and test the file. Step 2 Add the color support to our previous code It's just adding 3 lines after 1477 if (isset($params['color'])) { echo '<span class="label color_field" style="background-color:'.$tr[$params['color']].';color:'.(Tools::getBrightness($tr[$params['color']]) < 128 ? 'white' : '#383838').'">'; } Now you should have this. if (!isset($params['position']) AND (!isset($this->noLink) OR !$this->noLink)) { echo ' onclick="document.location = \''.$currentIndex.'&'.$this->identifier.'='.$id.($this->view? '&view' : '&update').$this->table.'&token='.($token!=NULL ? $token : $this->token).'\'">'.(isset($params['prefix']) ? $params['prefix'] : ''); if (isset($params['color'])) { echo '<span class="label color_field" style="background-color:'.$params['color'].';color:'.(Tools::getBrightness($params['color']) < 128 ? 'white' : '#383838').'">'; } } else { echo '>'; } Now, let's add the closing tag. Step 3 Now, your lines on rows 1539-1540 should currently look like this. echo (isset($params['suffix']) ? $params['suffix'] : ''). '</td>'; We need to add a line before the </td> line. echo (isset($params['suffix']) ? $params['suffix'] : ''). (isset($params['color']) ? '</span>' : ''). '</td>'; Now it supports color. Either edit your admin.css to include .label or .color_field, and add display: inline to it. Or you can edit the element directly and change the color line we created earlier to echo '<span class="label color_field" style="display:inline;background-color:'.$params['color'].';color:'.(Tools::getBrightness($params['color']) < 128 ? 'white' : '#383838').'">'; Hope this helps. Edited August 30, 2015 by PhpMadman (see edit history) 1 Link to comment Share on other sites More sharing options...
sting5 Posted August 21, 2015 Author Share Posted August 21, 2015 Wow, thanks, nice explanation! I will try the code when have time and give the results. Thanks again! Link to comment Share on other sites More sharing options...
sting5 Posted August 21, 2015 Author Share Posted August 21, 2015 (edited) Ok, I've integrated the code inside just like You told me to (I hope so), but nothing changed... There were no error messages, alterations should be ok... but the payments look the same, whether it's 'bankwire' or 'cashondelivery' - no difference. The HTML generated via the Chrome browser looks like this: <td class="pointer" onclick="document.location = '/admin/index.php?tab=AdminOrders&id_order=3107&vieworder&token=9c61sf86544je8bb0295094ca5q92a3b'">Cash on delivery</td> Maybe I should clear the cache or something like that...? Edited August 21, 2015 by sting5 (see edit history) Link to comment Share on other sites More sharing options...
PhpMadman Posted August 21, 2015 Share Posted August 21, 2015 Strange, it's like it's completly ignores the color line. Replace the onclick line with this. echo ' onclick="document.location = \''.$currentIndex.'&'.$this->identifier.'='.$id.($this->view? '&view' : '&update').$this->table.'&token='.($token!=NULL ? $token : $this->token).'\'">'.(isset($params['prefix']) ? $params['prefix'] : '!'); If PrestaShop reads your changes, it should add a ! before all payment names. If it dosent, it might be some cache somewhere that stopping you from see the update. Link to comment Share on other sites More sharing options...
sting5 Posted August 21, 2015 Author Share Posted August 21, 2015 (edited) Hmmm, I've added the exclamation mark but nothing changed, the browser still returns same line as before. Perhaps the engine can't understand this part? IF(module = "cashondelivery","#ff0000","#ffffff") as pay_color, Perhaps system does not understand that this is the payment module and needs some different approach, no? I've also checked the cache folder (smarty), ir generates nothing but .tpl file cache files, so definitely not the problem here... Edited August 21, 2015 by sting5 (see edit history) Link to comment Share on other sites More sharing options...
PhpMadman Posted August 21, 2015 Share Posted August 21, 2015 (edited) It might need some re-coding. But the ! we added should show up regardless. It has nothing to do with the color thing. Edited August 30, 2015 by PhpMadman (see edit history) Link to comment Share on other sites More sharing options...
PhpMadman Posted August 30, 2015 Share Posted August 30, 2015 (edited) After som testing on my server. I found the code to not be working. That is fixed now. I changed this line: echo '<span class="label color_field" style="background-color:'.$tr[$params['color']].';color:'.(Tools::getBrightness($tr[$params['color']]) < 128 ? 'white' : '#963').'">'; However in the sample you provided, you did not get any <span> at all, so there must be an override / cache / module that is blocking the code from AdminTab In a new install, my code directly added the <span>. So even without the fix above, you should have gotten the <span> element. Edited August 30, 2015 by PhpMadman (see edit history) Link to comment Share on other sites More sharing options...
sting5 Posted August 31, 2015 Author Share Posted August 31, 2015 Yes - You might be right! Silly me! I've found that override/Classes contain AdminTab.php file, so this must be it! I will try to correct the code soon and write about the results! Link to comment Share on other sites More sharing options...
sting5 Posted September 1, 2015 Author Share Posted September 1, 2015 (edited) Aaand it works! Thank You very much PHPMadman - the code is perfect, even the last correction You've suggested wasn't necessary - right now the cash on delivery payment status ir excluded perfectly - no more errors from employees (I hope)! Edited September 1, 2015 by sting5 (see edit history) Link to comment Share on other sites More sharing options...
PhpMadman Posted September 1, 2015 Share Posted September 1, 2015 The last correction is included in the step by step guide ; ) Glad it finally worked. Link to comment Share on other sites More sharing options...
sting5 Posted September 1, 2015 Author Share Posted September 1, 2015 Yes, my problem was that I forgot the AdminTabs.php file in override/classes folder, which was blocking the changes You've made. And You've made my day! Thanks again, really appreciated 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