News:

Support the VirtueMart project and become a member

Main Menu

Change Order Status

Started by DaveB, March 21, 2005, 22:28:07 PM

Previous topic - Next topic

DaveB

I have written a new payment processor based on the code for the authorize.net file ps_authorize.php

It works perfectly, but my orders are set to Pending in the database.

How can I change this so that successful orders are set to "Confirmed"

Thanks
Dave

ps. I have also added a two new features to phpShop

1) Download Area Menu only displayed to logged in users
2) registration using email address instead of user name

Let me know if you are interested in these

DaveB

#1
OK, I figured this out myself with a couple of crude Hacks.

1) in ps_checkout.php, function add(). I used the following code at the bottom:-

if ($db->f("attribute_name") =="download") {
      $d['order_status']='C';
      require_once(CLASSPATH.'ps_order.php' ); //CREATE A NEW ps_order class as this has the download function
      $ps_order=new ps_order;
      $ps_order->order_status_update($d);
}


2) Also, I edited checkout.thankyou.php and added:-

/** DB Retrieve Download information if it was a download **/
 
        $dbw_2 = new ps_DB;
        $q = "SELECT * FROM #__pshop_product_download WHERE";
        $q .= " order_id = '" . $vars["order_id"] . "'";
        $dbw_2->query($q);
        $url = $mosConfig_live_site."/index.php?option=com_phpshop&page=shop.downloads";
       
        $downloadCounter=0;
        $message='<table border="0" width="75%"><tr>';
         
         while($dbw_2->next_record()) {
                   ++$downloadCounter;
                                     
                   $message.= '<tr><td>File name : '.$dbw_2->f("file_name").'</td>'.
                             '<td>Download ID : <a href="'."$url&download_id=".$dbw_2->f("download_id").'">'.
                             $dbw_2->f("download_id").'</a></td></tr>';
                             
          }
         
         $message.='</table>';
         
         if($downloadCounter>0) {
          echo("<p>".$PHPSHOP_LANG->_PHPSHOP_DOWNLOADS_SEND_MSG_1."</p>");
          echo("<p>".$PHPSHOP_LANG->_PHPSHOP_DOWNLOADS_SEND_MSG_2."</p>");
          echo("<p>".$message."</p>");
          echo("<p>".$PHPSHOP_LANG->_PHPSHOP_DOWNLOADS_SEND_MSG_3.": ".DOWNLOAD_MAX."</p>");
         
          $expire = ((DOWNLOAD_EXPIRE / 60) / 60) / 24;
          echo(str_replace("{expire}", $expire, $PHPSHOP_LANG->_PHPSHOP_DOWNLOADS_SEND_MSG_4));
         
         
         }

//DB End


After the THANK YOU MESSAGE, so that it displays the download URL straight away.


gudai


hooje

Hey Dave,

I'm having a little bit of trouble getting the first bit of code to work in ps_checkout.php I added it after the function add () like you mentioned, but it doesn't seem to be altering the order status from Pending -> Confirmed. The only reason I want it to do this (since your other bit of code works flawlessly - gives the download link right away) is so the user recieves an email with the download links without me having to manually confirm every order.

I put your first block of code after this IF statement in ps_checkout.php.


if( $this->_SHIPPING ) {
       /* sets _shipping */
       $d['order_shipping'] = $order_shipping = round( $this->calc_order_shipping( $d ), 2 );
       
       /* sets _shipping_tax
       * btw: This is WEIRD! To get an exactly rounded value we have to convert
       * the amount to a String and call "round" with the string. */
       $d['order_shipping_tax'] = $order_shipping_tax = round( strval($this->calc_order_shipping_tax($d)), 2 );
     }
     else {
        $d['order_shipping'] = $order_shipping = $order_shipping_tax = $d['order_shipping_tax'] = 0.00;
     }
     
     $timestamp = time() + ($mosConfig_offset*60*60);
     
     $order_total = $tmp_subtotal + $order_tax + $order_shipping + $order_shipping_tax;



Then your code went here...

and this is the code that followed it (that was already in ps_checkout.php - this is just to help you know where i'm putting it)..


/*
     if (PAYMENT_DISCOUNT_BEFORE != '1') {
      if($auth["show_price_including_tax"] == 1) {
        $order_total -= $payment_discount_untaxed;
        $order_total -= $coupon_discount_untaxed;
      }
      else {
        $order_total -= $payment_discount;
        $order_total -= $coupon_discount;
      }
     }


Can you beat me up, then let me know what i'm doing completely wrong!?

Again, thanks for this code - it has helped me and will! help me no end  :-*  :D

hooje

ok scrap the last post, i found another post you made where you say

1) I edited the function add() in ps_checkout.php and included the code as follows after  $this->email_receipt($order_id);

so, i did just that - put your code after $this->email_receipt($order_id);


still no luck - i get a confirmation email but no download email and the order info still says "pending" on the order.

DaveB

#5
My code is right at the end of function add(), as follows:-

  for($i = 0; $i < $cart["idx"]; $i++) {
      $r = "SELECT product_in_stock,product_sales ";
      $r .= "FROM #__pshop_product where product_id=";
      $r .= $cart[$i]["product_id"];
      $db->query($r);
      $db->next_record();

      if ($db->f("product_in_stock")) {
       $newquantity=($db->f("product_in_stock")-$cart[$i]["quantity"]);
       if ($newquantity <0) $newquantity=0;
       $q = "UPDATE #__pshop_product ";
       $q .= "SET product_in_stock=$newquantity ";
       $q .= "where product_id=";
       $q .= $cart[$i]["product_id"];
       $db->query($q);
       $db->next_record();
      }
      $newsales=($db->f("product_sales")+$cart[$i]["quantity"]);
      $q = "UPDATE #__pshop_product ";
      $q .= "SET product_sales=$newsales ";
      $q .= "WHERE product_id=";
      $q .= $cart[$i]["product_id"];
      $db->query($q);
      $db->next_record();
     }
     
     ######## BEGIN DAVES DOWNLOAD MOD ###############
     
      for($i = 0; $i < $cart["idx"]; $i++) {
        $dlnum=0;
        $dl = "SELECT attribute_name,attribute_value ";
        $dl .= "FROM #__pshop_product_attribute where product_id=";
        $dl .= $cart[$i]["product_id"];
        $db->query($dl);
        $db->next_record();
 
  $downloadConfirm="N"; //DB
 
        if ($db->f("attribute_name") =="download") {
     
         
          $downloadConfirm="Y";//DB
            /*$str = $order_id;
            $str .=$cart[$i]["product_id"];
            $str .=$dlnum;
            $str .=time();
     
            $download_id = md5($str);*/
           
            //DBstart
            $download_id=strtoupper(md5($_SESSION['auth']['username']));
          $download_id=preg_replace('/([A-Z0-9]{4})([A-Z0-9])/','${1}-${2}', $download_id);
          //DB end
         
            $q = "INSERT INTO #__pshop_product_download ";
            $q .= "(product_id, user_id, order_id, end_date, download_max, download_id, file_name)";
            $q .= " VALUES ('";
            $q .= $cart[$i]["product_id"] . "', '";
            $q .= $auth["user_id"] . "', '";
            $q .= $order_id . "', '";
            $q .= " 0" . "', '";
            $q .= DOWNLOAD_MAX . "', '";
            $q .= $download_id . "', '";
            $q .= $db->f("attribute_value") . "')";
            $db->query($q);
            $db->next_record();
       }
    }
    ################## END DOWNLOAD MOD ###########
   
    if (AFFILIATE_ENABLE == '1') {
      $ps_affiliate->register_sale($order_id);
    }
     // Export the order_id so the checkout complete page can get it
     $d["order_id"] = $order_id;
     
     // Unset the payment_method variables
     
     $d["payment_method_id"] = "";
     $d["order_payment_number"] = "";
     $d["order_payment_expire"] = "";
     $d["order_payment_name"] = "";
     $d["credit_card_code"] = "";
     $_SESSION['ccdata']['order_payment_name']  = "";
     $_SESSION['ccdata']['order_payment_number']  = "";
     $_SESSION['ccdata']['order_payment_expire_month'] = "";
     $_SESSION['ccdata']['order_payment_expire_year'] = "";
     $_SESSION['ccdata']['credit_card_code'] = "";
     $HTTP_POST_VARS["payment_method_id"] = "";
     $HTTP_POST_VARS["order_payment_number"] = "";         
     $HTTP_POST_VARS["order_payment_expire"] = "";
     $HTTP_POST_VARS["order_payment_name"] = "";
     $_SESSION['coupon_discount'] = "";
     $_SESSION['coupon_id'] = "";
     $_SESSION['coupon_redeemed'] = false;
     
     // Send the e-mail confirmation messages
     $this->email_receipt($order_id);

     //NOW the DAVE HACK TO CREATE THE DOWNLOAD EMAIL
     
     if ($downloadConfirm=='Y') {
      $d['order_status']='C';
      require_once(CLASSPATH.'ps_order.php' ); //CREATE A NEW ps_order class as this has the download function
      $ps_order=new ps_order;
      $ps_order->order_status_update($d);
     }
     
     //END OF DAVE HACK
     
     // Reset the cart
     $ps_cart->reset();     

     return True;
   }

I have also changed it a little to make the download id a little more friendly

Hope this helps
Dave

wooly

Hi DaveB

your hack looks really useful :)

I hope you get this as its been a little while since you made these posts.

I have three questions

1. will this work for future versions of phpshop from the one you created it for?
2. what about virtuemart- will it work if I replace all references as follows in your code

phpshop  >>> virtuemart
PHPSHOP >>> VIRTUEMART
pshop      >>> vm

If I have missed out some code/name changes could you please let me know which they are...sorry I'm not a php coder

and finally

3. I think I read somewhere that short cutting to the donwload url might not be secure as the url may show the order id on order confirmation...which by default happens before payment... have you skipped this bit or is your payment now happening before the order confirmation and thank you with the url?

I hope you understand what I mean...sorry if I am not explaining properly

Maybe if you could set out the order >payment process as you now have it in in your shop it would help me to understand better.

Thanks a lot for this in advance

W

ekoay

Quote from: DaveB on July 18, 2005, 22:04:01 PM
My code is right at the end of function add(), as follows:-

  for($i = 0; $i < $cart["idx"]; $i++) {
      $r = "SELECT product_in_stock,product_sales ";
      $r .= "FROM #__pshop_product where product_id=";
      $r .= $cart[$i]["product_id"];
      $db->query($r);
      $db->next_record();

      if ($db->f("product_in_stock")) {
       $newquantity=($db->f("product_in_stock")-$cart[$i]["quantity"]);
       if ($newquantity <0) $newquantity=0;
       $q = "UPDATE #__pshop_product ";
       $q .= "SET product_in_stock=$newquantity ";
       $q .= "where product_id=";
       $q .= $cart[$i]["product_id"];
       $db->query($q);
       $db->next_record();
      }
      $newsales=($db->f("product_sales")+$cart[$i]["quantity"]);
      $q = "UPDATE #__pshop_product ";
      $q .= "SET product_sales=$newsales ";
      $q .= "WHERE product_id=";
      $q .= $cart[$i]["product_id"];
      $db->query($q);
      $db->next_record();
     }
     
     ######## BEGIN DAVES DOWNLOAD MOD ###############
     
      for($i = 0; $i < $cart["idx"]; $i++) {
        $dlnum=0;
        $dl = "SELECT attribute_name,attribute_value ";
        $dl .= "FROM #__pshop_product_attribute where product_id=";
        $dl .= $cart[$i]["product_id"];
        $db->query($dl);
        $db->next_record();
 
  $downloadConfirm="N"; //DB
 
        if ($db->f("attribute_name") =="download") {
     
         
          $downloadConfirm="Y";//DB
            /*$str = $order_id;
            $str .=$cart[$i]["product_id"];
            $str .=$dlnum;
            $str .=time();
     
            $download_id = md5($str);*/
           
            //DBstart
            $download_id=strtoupper(md5($_SESSION['auth']['username']));
          $download_id=preg_replace('/([A-Z0-9]{4})([A-Z0-9])/','${1}-${2}', $download_id);
          //DB end
         
            $q = "INSERT INTO #__pshop_product_download ";
            $q .= "(product_id, user_id, order_id, end_date, download_max, download_id, file_name)";
            $q .= " VALUES ('";
            $q .= $cart[$i]["product_id"] . "', '";
            $q .= $auth["user_id"] . "', '";
            $q .= $order_id . "', '";
            $q .= " 0" . "', '";
            $q .= DOWNLOAD_MAX . "', '";
            $q .= $download_id . "', '";
            $q .= $db->f("attribute_value") . "')";
            $db->query($q);
            $db->next_record();
       }
    }
    ################## END DOWNLOAD MOD ###########
   
    if (AFFILIATE_ENABLE == '1') {
      $ps_affiliate->register_sale($order_id);
    }
     // Export the order_id so the checkout complete page can get it
     $d["order_id"] = $order_id;
     
     // Unset the payment_method variables
     
     $d["payment_method_id"] = "";
     $d["order_payment_number"] = "";
     $d["order_payment_expire"] = "";
     $d["order_payment_name"] = "";
     $d["credit_card_code"] = "";
     $_SESSION['ccdata']['order_payment_name']  = "";
     $_SESSION['ccdata']['order_payment_number']  = "";
     $_SESSION['ccdata']['order_payment_expire_month'] = "";
     $_SESSION['ccdata']['order_payment_expire_year'] = "";
     $_SESSION['ccdata']['credit_card_code'] = "";
     $HTTP_POST_VARS["payment_method_id"] = "";
     $HTTP_POST_VARS["order_payment_number"] = "";         
     $HTTP_POST_VARS["order_payment_expire"] = "";
     $HTTP_POST_VARS["order_payment_name"] = "";
     $_SESSION['coupon_discount'] = "";
     $_SESSION['coupon_id'] = "";
     $_SESSION['coupon_redeemed'] = false;
     
     // Send the e-mail confirmation messages
     $this->email_receipt($order_id);

     //NOW the DAVE HACK TO CREATE THE DOWNLOAD EMAIL
     
     if ($downloadConfirm=='Y') {
      $d['order_status']='C';
      require_once(CLASSPATH.'ps_order.php' ); //CREATE A NEW ps_order class as this has the download function
      $ps_order=new ps_order;
      $ps_order->order_status_update($d);
     }
     
     //END OF DAVE HACK
     
     // Reset the cart
     $ps_cart->reset();     

     return True;
   }

I have also changed it a little to make the download id a little more friendly

Hope this helps
Dave

There is a flaw in the new download id. its a little too friendly. I was using ur hack until I found out that, if a user is in the same session to do a multiple purchase, the download id will come out identical. This will cause the download info email not to be send out, but only PO is send out. And you cannot make purchase until the download is expired, still if the session id remain the same, you will never received the  download info email.

I hope this help.