GoodCom printers

Viewing 15 posts - 41 through 55 (of 55 total)
  • Author
    Posts
  • #38115
    smaj
    Participant

      Thank you Oily!

      @proof
      @justin how did you get the printer to callback to the website/customer? I have the ordini.txt working.

      #38116
      justin
      Participant

        Hi Smaj,

        Disclaimer, I’m not the best PHP programmer if you could even call me that. So there are probably mistakes and better ways to code this. I’m aware of that. However it does the job for us!

        Here’s the full ordercallback.php file, you’ll need to adjust the details in it.

        
        <?php
        date_default_timezone_set('Australia/Brisbane');
        //writed by GoodCom
        //author:coolbi
        //callback a=AC0001&o=10004&ak=Accepted&m=OK&dt=17:10&u=testuser&p=test
        include_once("getorder.php");
        $sUserAgent="";
        $useraccount="";
        $userpwd="";
        $resId="";
        $orderId="";
        $orderStatus="";
        $orderReason="";
        $orderTime="";
        $defaultResId="AC001";
        $defaultcount="testuser";
        $defaultpwd="test";
        if(isset($_SERVER["HTTP_USER-AGENT"])){
        $sUserAgent=$_SERVER["HTTP_USER-AGENT"];
        }
        if(isset($_GET['u'])){
        $useraccount=strtolower($_GET['u']);
        }
        if(isset($_GET['p'])){
        $userpwd=strtolower($_GET['p']);
        }
        if(isset($_GET['a'])){
        $resId=$_GET['a'];
        }
        if(isset($_GET['o'])){
        $orderId=$_GET['o'];
        }
        if(isset($_GET['ak'])){
        $orderStatus=$_GET['ak'];
        }
        if(isset($_GET['m'])){
        $orderReason=$_GET['m'];
        }
        if(isset($_GET['dt'])){
        $orderTime=$_GET['dt'];
        }
        if(($useraccount==$defaultcount)&&($userpwd==$defaultpwd) && ($resId==$defaultResId))
        {
        $ret=0;
        if($orderStatus=='Accepted'){
        $ret=updateOrderstatus($orderId,'Delivered');	
        // Start Locate Email Address And Send //		
        $ordid= "*" . $orderId . "*";
        $line_no = 0; 
        $fname = "orders.txt"; 
        $lines = file($fname); 
        foreach($lines as $line) { 
        $line_no++; 
        if(strstr($line, $ordid)) {
        preg_match_all("/[\._a-zA-Z0-9-]+@[\._a-zA-Z0-9-]+/i", $line, $matches);
        $orderTime = date('h:i a', strtotime($orderTime));
        // Start Send Email //
        //Mail the message        
        $to = $matches[0][0];
        $subject = "Order Accepted - Delivery Time: " . $orderTime . " Your Restaurant";
        $message = "
        <html>
        <head>
        <title>Thank you for your order!</title>
        </head>
        <body style='margin: 0px; background-color: #FFFFFF; font-size: 14px; color: #444444; font-family: Verdana, Helvetica, Arial, sans-serif;'>
        <table style='border-collapse:collapse;margin:10px 0; width:100%;'>
        <tr>
        <td>
        <center>
        <table style='border-collapse:collapse;width: 500px; margin: 0 auto; border: 1px dotted #CECECE; background: #F4F3F4;'>
        <tbody>
        <tr>
        <td>
        <table id='site' style='width:100%;padding: 30px; text-align: center; background-color: #21759B; color: #FFFFFF;'>
        <tbody>
        <tr><td style='text-align: center;font-size: 160%; font-weight: 600;'>Your Restaurant</td></tr>
        </tbody>
        </table>
        <table id='ordervars' style='width:100%;margin: 5px 0 30px 0; border-bottom: 1px dotted #cecece;'>
        <tr><td colspan='2' style='text-align: center;'>Your Order Has Been Confirmed.</td></tr>
        <tr><td style='width: 50%; white-space:nowrap; text-align: right; padding:2px;'>Order ID:</td>
        <td style='padding: 2px; word-break: break-word;'>" . $orderId . "</td></tr>
        <tr><td style='width: 50%; white-space:nowrap; text-align: right; padding:2px;'>Estimated Delivery Time:</td><td style='padding: 2px; word-break: break-word;'>" . $orderTime. "</td></tr>
        <tr><td colspan='2' style='text-align: center; padding:2px;'>Thank you for choosing Your Restaurant</td></tr>
        </table>
        </td>
        </tr>
        </tbody>
        </table>
        </center>
        </td>
        </tr>
        </table>
        </body>
        </html>
        ";
        // Always set content-type when sending HTML email
        $headers = "MIME-Version: 1.0" . "\r\n";
        $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
        // More headers
        $headers .= 'From: Your Restaurant <[email protected]>' . "\r\n";
        mail($to,$subject,$message,$headers);
        // WP MAIL
        define('WP_USE_THEMES', false);
        require_once('wp-load.php');
        wp_mail($to,$subject,$message,$headers);
        /*if( !$phpmailer->send() ) {
        $txt = $phpmailer->ErrorInfo;
        file_put_contents('orders.txt', $txt, FILE_APPEND);
        } else {
        $txt = "Message sent!";
        file_put_contents('orders.txt', $txt, FILE_APPEND);
        }*/
        // End Send Email //	
        }; 
        // Start Delete Order Line Once Accepted //	
        $ordid= "*" . $orderId . "*";
        $line_no = 0; 
        $fname = "orders.txt"; 
        $lines = file($fname); 
        foreach($lines as $line) { 
        $line_no++; 
        if(!strstr($line, $ordid)) $out .= $line; 
        } 
        $f = fopen($fname, "w"); 
        fwrite($f, $out); 
        fclose($f);
        // End Delete Order Line Once Accepted //		
        } 
        // End Locate Email Address And Send //			
        }
        else if($orderStatus=='Rejected'){
        $ret=updateOrderstatus($orderId,'Cancel:'.$orderReason);
        // Start Locate Email Address And Send //		
        $ordid= "*" . $orderId . "*";
        $line_no = 0; 
        $fname = "orders.txt"; 
        $lines = file($fname); 
        foreach($lines as $line) { 
        $line_no++; 
        if(strstr($line, $ordid)) {
        preg_match_all("/[\._a-zA-Z0-9-]+@[\._a-zA-Z0-9-]+/i", $line, $matches);
        // Start Send Email //
        //Mail the message        
        $to = $matches[0][0];
        $subject = "Order Rejected - Your Restaurant";
        $message = "
        <html>
        <head>
        <title>Order Rejected</title>
        </head>
        <body style='margin: 0px; background-color: #FFFFFF; font-size: 14px; color: #444444; font-family: Verdana, Helvetica, Arial, sans-serif;'>
        <table style='border-collapse:collapse;margin:10px 0; width:100%;'>
        <tr>
        <td>
        <center>
        <table style='border-collapse:collapse;width: 500px; margin: 0 auto; border: 1px dotted #CECECE; background: #F4F3F4;'>
        <tbody>
        <tr>
        <td>
        <table id='site' style='width:100%;padding: 30px; text-align: center; background-color: #21759B; color: #FFFFFF;'>
        <tbody>
        <tr><td style='text-align: center;font-size: 160%; font-weight: 600;'>Your Restaurant</td></tr>
        </tbody>
        </table>
        <table id='ordervars' style='width:100%;margin: 5px 0 30px 0; border-bottom: 1px dotted #cecece;'>
        <tr><td colspan='2' style='text-align: center;'>Your Order Has Been Rejected.</td></tr>
        <tr><td colspan='2' style='text-align: center; padding:2px;'>We apologise for the inconvenience unfortunately we are unable to fulfill your order" . $orderReason . "</td></tr>
        </table>
        </td>
        </tr>
        </tbody>
        </table>
        </center>
        </td>
        </tr>
        </table>
        </body>
        </html>
        ";
        // Always set content-type when sending HTML email
        $headers = "MIME-Version: 1.0" . "\r\n";
        $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
        // More headers
        $headers .= 'From: Your Restaurant <[email protected]>' . "\r\n";
        mail($to,$subject,$message,$headers);
        // WP MAIL
        define('WP_USE_THEMES', false);
        require_once('wp-load.php');
        wp_mail($to,$subject,$message,$headers);
        /*if( !$phpmailer->send() ) {
        $txt = $phpmailer->ErrorInfo;
        file_put_contents('orders.txt', $txt, FILE_APPEND);
        } else {
        $txt = "Message sent!";
        file_put_contents('orders.txt', $txt, FILE_APPEND);
        }*/
        // End Send Email //	
        }; 
        // Start Delete Order Line Once Accepted //	
        $ordid= "*" . $orderId . "*";
        $line_no = 0; 
        $fname = "orders.txt"; 
        $lines = file($fname); 
        foreach($lines as $line) { 
        $line_no++; 
        if(!strstr($line, $ordid)) $out .= $line; 
        } 
        $f = fopen($fname, "w"); 
        fwrite($f, $out); 
        fclose($f);
        // End Delete Order Line Once Accepted //		
        } 
        // End Locate Email Address And Send //				
        }
        if($ret==1){
        $ret=0;
        $ret=checkNewOrder();
        header("HTTP/1.1 206 Partial Content");
        if($ret!=0){
        header("More-orders: 1");
        }
        echo $ret;
        }
        }
        else{
        print substr("",0,1);
        }
        ?>
        
        #38119
        smaj
        Participant

          Thank you Very much for your reply.
          Im trying to this script to work but im just getting a loop.(asks for confirmation time and printer just prints the same order. )
          I have changed the time zone, “getorder.php” “./getorder.php”, orders.txt and the emails. Is there anything else im missing out?

          Regards

          #38120
          smaj
          Participant

            I can get past the loop now, but I not getting any email confirmation after accepting the order.??

            #38121
            Olly
            Admin & Mod

              just a note here re https://www.wp-pizza.com/topic/goodcom-printers/page/3/#post-38116

              in reality the _GET parameters are being sanitised in some way shape or form…..right ?
              just saying

              #38123
              smaj
              Participant

                @Oily Can we integrate the callback.php with your Confirm|Reject|Notify addon?
                ie. when user rejects an order the Confirm|Reject|Notify puts it and and refund the customer?

                #38130
                justin
                Participant

                  @smaj

                  Hi smaj, I’ve enabled the phpmailer in WordPress. It’s much more reliable!

                  I use SMTP 2 Go, which is free and quite good! Add this code and edit fields as required in your themes functions.php

                  
                  add_action( 'phpmailer_init', 'wpse8170_phpmailer_init' );
                  function wpse8170_phpmailer_init( PHPMailer $phpmailer ) {
                  $phpmailer->Host = 'mail.smtp2go.com';
                  $phpmailer->Port = '465'; // could be different
                  $phpmailer->Username = 'yourusername'; // if required
                  $phpmailer->Password = 'yourpassword'; // if required
                  $phpmailer->SMTPAuth = true; // if required
                  $phpmailer->SMTPSecure = 'ssl'; // enable if required, 'tls' is another possible value
                  $phpmailer->IsSMTP();
                  }
                  

                  Thanks 🙂

                  #38132
                  Olly
                  Admin & Mod

                    re: > Can we integrate the callback.php with your Confirm|Reject|Notify addon?
                    maybe there’s an action or filter hook i could add that could be used to intercept the whole process (but the individual programming using the appropriate API would still have to be a custom thing)
                    i’ll have a bit of a think , but no promises or indeed ETA I’m afraid at the moment

                    #38169
                    smaj
                    Participant

                      Hi @justin,
                      Im still having difficulty callingback.
                      I have the order writing to the ordercallback.php but cant get the email sent out??? i get a
                      RRRR err:HTTP/1.1 500 Internal Server Error
                      from the TT data.

                      What is the “include_once(“getorder.php”);” what is the getorder.php?

                      Thank you @Olly look forward to the addon soon.

                      #38174
                      Olly
                      Admin & Mod

                        if you get “fundamental” errors (like a 500 or something)
                        you should enable debug (https://docs.wp-pizza.com/troubleshooting/) and check your debug.log . there’s a good chance it will tell you what the issue is

                        #38176
                        justin
                        Participant

                          Hi @smaj,

                          I found the emails difficult to program, there are so many different components to sending the mail.

                          As Olly said, display errors. In your ordercallback.php file add:

                          
                          error_reporting(E_ALL);
                          ini_set('display_errors', 1);
                          

                          The getorder.php file is redundant as far as I remember, I don’t believe its actually used for anything (unless your using the database rather than the text file).

                          Try printing every variable and step related to the mail in a text file or such.

                          #38203
                          smaj
                          Participant

                            Hi,

                            I’m trying to print all the variables the actual printer sends back (order confirmation times etc). but I’m getting no output.

                            Do you know what Variables I should be looking for? the default ones are not echoing.

                            How do I see which page the printer is trying to actually connect to?

                            #38209
                            justin
                            Participant

                              If you are getting no output follow back the variables through each step of the script.

                              
                              $orderReason
                              $orderTime
                              $orderId
                              

                              The printer connects to ordercallback.php

                              #38210
                              smaj
                              Participant

                                How have you setup your functions.php, have dont it like #35518 or have you done something diffrent?

                                #38211
                                justin
                                Participant

                                  Hi @smaj,

                                  That may be the issue, the latest functions I’m using are below:

                                  
                                  add_action( 'phpmailer_init', 'wpse8170_phpmailer_init' );
                                  function wpse8170_phpmailer_init( PHPMailer $phpmailer ) {
                                  $phpmailer->Host = 'mail.smtp2go.com';
                                  $phpmailer->Port = '465'; // could be different
                                  $phpmailer->Username = '[email protected]'; // if required
                                  $phpmailer->Password = 'password'; // if required
                                  $phpmailer->SMTPAuth = true; // if required
                                  $phpmailer->SMTPSecure = 'ssl'; // enable if required, 'tls' is another possible value
                                  $phpmailer->IsSMTP();
                                  }
                                  function theme_enqueue_styles() {
                                  wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/style.css', array( 'avada-stylesheet' ) );
                                  }
                                  add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
                                  function avada_lang_setup() {
                                  $lang = get_stylesheet_directory() . '/languages';
                                  load_child_theme_textdomain( 'Avada', $lang );
                                  }
                                  add_action( 'after_setup_theme', 'avada_lang_setup' );
                                  // Save Order To TXT File //
                                  add_action( 'wppizza_on_order_execute', 'print_order', 1);
                                  function print_order($order_id, $order, $print_templates) {
                                  //declare new ORDER class and assign order details to var order
                                  $order = new WPPIZZA_ORDER();
                                  $order = $order->session_formatted();
                                  //check if delivery or pickup
                                  $pickup_delivery = ($order['ordervars']['order_type']['value_formatted'] == 'For Delivery' ? 1 : 2);
                                  //check if order has been paid
                                  $order_paid = ($order['ordervars']['payment_method']['value_formatted'] == 'Cash' ? 7 : 6);
                                  //add pickup_delivery and order_id to txt file
                                  $txt = "#Pizza*$pickup_delivery*$order_id*";
                                  //$txt .= print_r($order, true);
                                  //add each item from order into txt file, including ONE extra option
                                  foreach($order['order']['items'] as $item) {
                                  $ititle = html_entity_decode($item['title']);
                                  $ititle = addslashes($ititle);
                                  $txt .= "$item[quantity];$ititle $item[price_label]";
                                  foreach($item['extend_data']['addingredients']['multi']['1']['0'] as $key => $value) {
                                  //$txt .= print_r($value, true);
                                  $txt .= " + $value[count] $value[name]";
                                  }
                                  $txt .= ";$item[pricetotal_formatted];";
                                  }
                                  $txt .= "*{$order[summary][total][0][value_formatted]}*;{$order[customer][ccomments][value]};;{$order[customer][cname][value]};{$order['customer']['caddress']['value']};{$order[customer][ctel][value]};{$order['customer']['cemail']['value']};{$order[ordervars][order_date][value_formatted]};$order_paid;{$order[ordervars][payment_gateway][value]};;*#\r\n";
                                  file_put_contents('/root/pathto/public_html/orders.txt', $txt, FILE_APPEND);
                                  }
                                  // Save Order To TXT File //
                                  
                                Viewing 15 posts - 41 through 55 (of 55 total)
                                • The topic ‘GoodCom printers’ is closed to new replies.