Jump to content

New Tab in BO


MrBaseball34

Recommended Posts

I have created a page that lets me see the orders that have a order_status of 12 but have not been updated. Now, I want to make this into a tab in the BO.

I know I can do it using this technique:
http://www.prestashop.com/forums/viewthread/60203/development/solved_custom_page_in_backoffice_ps1_dot_2_dot_5

However, I'm having trouble figuring out how to handle the button click. I'm not actually going to be "saving" any values. I want to refresh the page and start a process. Also, I couldn't get the CSS to "skin" this thing at all.
I had to use inline styles.

The code below works exactly like I want but I need it to be installed in the BO as a tab off the Tools tab. Can anyone help out?

Code will be posted in reply below.

Link to comment
Share on other sites

First half of code:

<?php
 //
 // file is named ReportErrors.prp 
 // and located in the admin/tabs dir 
 //
 include_once(dirname(__FILE__).'/../config/config.inc.php');    
 include_once(dirname(__FILE__).'/Db.php');    
 include_once(dirname(__FILE__).'/ReportGenerator.php');    
 include_once(dirname(__FILE__).'/Mail.php');    
 include_once(dirname(__FILE__).'/OrderHistory.php');    
 include_once(dirname(__FILE__).'/Tools.php');    

 function displayForm() {
   $cssURI = '../css/admin.css';
     $select = "SELECT o.id_order
                   , CONCAT( LEFT( c.`firstname` , 1 ) , ', ', c.`lastname` ) AS `customer`
                   , osl.`name`
                   , p.reference
                   , pd.physically_filename as filename
              FROM `ps_order_history` oh
              INNER JOIN `ps_orders` o 
                ON ( o.`id_order` = oh.`id_order` )
              LEFT JOIN `ps_customer` c 
                ON ( c.`id_customer` = o.`id_customer` )
              INNER JOIN `ps_order_detail` od 
                ON od.`id_order` = o.`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 (osl.`id_order_state` = oh.`id_order_state` AND osl.`id_lang` = 1)
              LEFT JOIN `ps_product` p 
                ON p.`id_product` = od.`product_id`
              INNER JOIN ps_product_download pd
                ON pd.`id_product` = p.`id_product`
              WHERE oh.`id_order` NOT IN (SELECT `id_order` 
                                          FROM `ps_order_history` 
                                          WHERE `id_order_state` <> 12)";
   $result = Db::getInstance()->ExecuteS($select);

   if($result AND (Db::getInstance()->NumRows() > 0)) {
     $html = '';       
     $html .= ''.PHP_EOL;
     $html .= '<html>'.PHP_EOL;
     $html .= '<head>'.PHP_EOL;
     $html .= '  <title>Report Errors ReGeneration Page</title>'.PHP_EOL;
     $html .= '  <link href="'.$cssURI.'" rel="stylesheet" type="text/css" />'.PHP_EOL;
     $html .= '</head>'.PHP_EOL;
     $html .= '<body>'.PHP_EOL;
     $html .= '  

'.PHP_EOL;
     $html .= '  '.PHP_EOL;
     $html .= '    '.PHP_EOL;
     $html .= '    Report Errors'.PHP_EOL;
     $html .= '    Check orders to generate report(s) and click Submit'.PHP_EOL;
     $html .= '    
'.PHP_EOL;
     $html .= '    
'.PHP_EOL;
     $html .= '    <form action="'.$_SERVER['REQUEST_URI'].'" method="post">'.PHP_EOL;
     $html .= '    '.PHP_EOL;
     $html .= '    
'.PHP_EOL;
     $html .= '    <input type="submit" name="submit" value="Submit" class="button" style="background-color:#FFF6D3; border-color:#FFF6D3 #DFD5AF #DFD5AF #FFF6D3; border-right:1px solid #DFD5AF; border-style:solid; border-width:1px; color:#268CCD; padding:3px; float: left;"/>'.PHP_EOL;
     $html .= '    '.PHP_EOL;
     $html .= '    </form>'.PHP_EOL;
     $html .= '    '.PHP_EOL;
     $html .= '  
'.PHP_EOL;
     $html .= '    
'.PHP_EOL;
     $html .= '</body>'.PHP_EOL;
     $html .= '</html>'.PHP_EOL;
     echo $html;

Link to comment
Share on other sites

Second half of code:

   } else {
     $html = '';       
     $html .= ''.PHP_EOL;
     $html .= '<html>'.PHP_EOL;
     $html .= '<head>'.PHP_EOL;
     $html .= '  <title>Report Errors ReGeneration Page</title>'.PHP_EOL;
     $html .= '  <link href="'.$cssURI.'" rel="stylesheet" type="text/css" />'.PHP_EOL;
     $html .= '</head>'.PHP_EOL;
     $html .= '<body>'.PHP_EOL;
     $html .= '  

'.PHP_EOL;
     $html .= '  '.PHP_EOL;
     $html .= '    '.PHP_EOL;
     $html .= '    Report Errors'.PHP_EOL;
     $html .= '    Check orders to generate report(s) and click Submit'.PHP_EOL;
     $html .= '    
'.PHP_EOL;
     $html .= '    
'.PHP_EOL;
     $html .= '    <form action="'.$_SERVER['REQUEST_URI'].'" method="post">'.PHP_EOL;
     $html .= '     IDCustomerStatusThere were no results'.PHP_EOL;
     $html .= '    
'.PHP_EOL;
     $html .= '    <input type="submit" name="submit" value="Submit" class="button" style="background-color:#FFF6D3; border-color:#FFF6D3 #DFD5AF #DFD5AF #FFF6D3; border-right:1px solid #DFD5AF; border-style:solid; border-width:1px; color:#268CCD; padding:3px; float: left;"/>'.PHP_EOL;
     $html .= '    
'.PHP_EOL;
     $html .= '    '.PHP_EOL;
     $html .= '    </form>'.PHP_EOL;
     $html .= '    '.PHP_EOL;
     $html .= '  
'.PHP_EOL;
     $html .= '</body>'.PHP_EOL;
     $html .= '</html>'.PHP_EOL;
     echo $html;
   } //if(!$result)
 } // function displayForm();

 if(isset($_POST['submit'])) {
   foreach ($_POST['history'] as $history) {
     $partno   = $_POST['reference'][key($_POST['history'])];
     $id_order = $_POST['id_order'][key($_POST['history'])];
     $filename = $_POST['filename'][key($_POST['history'])];
     //Tools::DebugLog(__CLASS__." (".__LINE__.")", "filename:".$filename);
     if(ReportGenerator::BuildReport($filename, $partno)) {
               $new_history = new OrderHistory();
               $new_history->id_order = intval($id_order);
       $new_history->id_order_state = _PS_OS_REGEN_;
           $new_history->addWithemail(true);
       unset($new_history);
       echo 'done';
     } else {
       mail("[email protected]","Report Regeneration Failed","Report generation failed for Order number:".$id_order);   
     } // if(ReportGenerator::BuildReport($filename, $partno))      
   } // foreach ($_POST['history'] as $history)
   displayForm();
 } else {
   displayForm();
 } // if(isset($_POST['submit']))

?>

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