0

I am using Drupal 7.31 and the Commerce Kickstart distribution. I added an order using CSV file in commerce_payment_transaction table.

I want to check the condition below:

if (isset($_POST['submit'])) {
  $handle = fopen($_FILES['filename']['tmp_name'], "r");    

  $i = 1;
  $f_status = FALSE;
  while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
      if($i > 2){

        $o_id = $data[1]; // I am fetch order_id from csv. I wont to check which order_id is coming from csv is present on commerce_order or not?                   
        $remote_id = $data[2];
        $created = strtotime($data[7]);
        $changed = strtotime($data[11]);
        $amount = $data[8] * 100;

        $db_query = db_select('commerce_payment_transaction','cpt');
        $db_query->fields('cpt');
        $db_query->condition('cpt.order_id',$o_id,'=');
        $db_res = $db_query->execute();
        $row_count = $db_res->rowCount();

        if($row_count == 0){
            $o_load = commerce_order_load($o_id);
        }
    }
  }
}else{
   $output = "Upload new csv by browsing to file and clicking on Upload<br />\n";
   $output .= "<form enctype='multipart/form-data' method='post'>";
   $output .= "File name to import:<br />\n";
   $output .= "<input size='50' type='file' name='filename'><br />\n";
   $output .= "<input type='submit' name='submit' value='Upload CSV'></form>";
   return $output;
 }
 $i++;
}

How can I do so?

  • what is the relation between order_id exists(valid) and ` I added an order using CSV file in commerce_payment_transaction table.` ? – Yusef Mohamadi Jun 23 '16 at 12:38
  • On a sidenote, you are aware that lots of security updates have been released since Drupal 7.31, including SA-CORE-2014-005? – Neograph734 Jun 23 '16 at 13:26
  • @zhilevan I added code just check it once. – priyank Jun 23 '16 at 13:33
1

You can check this using commerce_order_load()

if(commerce_order_load($order_id)){
    //Do something
}
else{
   //Do something
}

Hope this will help you

  • this condition not working – priyank Jun 23 '16 at 13:24
  • @priyank, it should. If an order is found, commerce_order_load returns the object, if not object was found it returns FALSE. – Neograph734 Jun 23 '16 at 13:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.