2016-04-23 29 views
0

我遇到了一个问题,即当发送数据失败而不是进入主页并再次发送数据时,调用函数中的相同函数。我会后我下面的代码:Codeigniter:创建一个重试按钮并调用相同的函数?

CODE:

function send_order($order,$wcustid,$customer_address_id) { // function to call 
    $this->load->model("order_product_m"); 
    $msg='';  

    $order_ref = $order[0]->order_no; 
    $payment_method='payment'; 
    $currency='currency'; 
    $currency_rate='1.00'; 

    //get shippingn method 
    $shipping=$this->order_m->getShippingMethod($order[0]->shipping_id); 
    $ship_method = 'Delivered'; 
    $ship_amount = $shipping[0]->amount; 

    $addOrderHeaderToWarehouse = $this->BLWP_CreateOrderHeader($wcustid, $customer_address_id, $order_ref, $ship_method,$ship_amount,$payment_method, $currency, $currency_rate); 

$status_ord_header = explode("=", $addOrderHeaderToWarehouse[1]); 

if(strpos($addOrderHeaderToWarehouse[1], 'OK')== true) { 

$ord = explode("=", $addOrderHeaderToWarehouse[3]); 
$warehouseOredrId=$ord[1]; 
$w_ordid=(int)$warehouseOredrId; 
$this->order_m->addWwarehouseorder($order[0]->id,$warehouseOredrId); //update order with warehouse id 
//update table orders with warehouse order id 

//SAVE WAREHOUSE ORDER ID FOR CRM ORDERS 

     $order_products=$this->order_m->getOrderProducts($order[0]->id); 

    $orderlineitem=0; 
     foreach($order_products as $order_product) { 


      //get warehouse order id from local db 
      $w_ord_id=$this->order_m->getwarehouseOrderId($order_product->order_id); 


      $prod=$this->product_m->getProductCode($order_product->product_id); 

      $product_code = $prod[0]->product_code; 
      $addorderproduct = $this->BLWP_CreateOrderLine($w_ord_id[0]->warehouse_order_id, $product_code, $order_product->quantity, $order_product->sales_price,''); 

      if(strpos($addorderproduct[1], 'OK')== true) { 
      $ordline = explode("=", $addorderproduct[3]); 
      $w_order_line_id=$ordline[1]; 
      //add order line id for each product in the table order product 
      $this->order_product_m->update_order_line_id($order_product->order_id,$order_product->product_id,$w_order_line_id); 
      $orderlineitem=1; 
      } 
      else $msg="Order line item not created"; 
     } 

     //Process order================================ 
     if($orderlineitem==1) { 
    $process_ord_response = $this->BLWP_ProcessOrder($w_ordid);  
    $process_order = explode("=", $process_ord_response[3]); 
    $w_ord_status= $process_order[1]; 
    $this->order_m->addWarehouseorderStatus($order[0]->id,$w_ord_status); //update order with warehouse id/ 
    } 
    else $msg.="<br>Order not processed"; 
    //============================================ 

    $msg.=" Order sent to warehouse"; 
} 
else 
    $msg="Order could not be sent to warehouse"; 
    //want to create the retry button here. 

return $msg; 

} 

我想拨打以下$msg= Order could not be sent to warehouse

回答

0

send_order功能。如果你想调用成员函数使用$此

function send_order($order,$wcustid,$customer_address_id) { // function to call 
    $this->load->model("order_product_m"); 
    $msg='';  

    $order_ref = $order[0]->order_no; 
    $payment_method='payment'; 
    $currency='currency'; 
    $currency_rate='1.00'; 

    //get shippingn method 
    $shipping=$this->order_m->getShippingMethod($order[0]->shipping_id); 
    $ship_method = 'Delivered'; 
    $ship_amount = $shipping[0]->amount; 

    $addOrderHeaderToWarehouse = $this->BLWP_CreateOrderHeader($wcustid, $customer_address_id, $order_ref, $ship_method,$ship_amount,$payment_method, $currency, $currency_rate); 

$status_ord_header = explode("=", $addOrderHeaderToWarehouse[1]); 

if(strpos($addOrderHeaderToWarehouse[1], 'OK')== true) { 

$ord = explode("=", $addOrderHeaderToWarehouse[3]); 
$warehouseOredrId=$ord[1]; 
$w_ordid=(int)$warehouseOredrId; 
$this->order_m->addWwarehouseorder($order[0]->id,$warehouseOredrId); //update order with warehouse id 
//update table orders with warehouse order id 

//SAVE WAREHOUSE ORDER ID FOR CRM ORDERS 

     $order_products=$this->order_m->getOrderProducts($order[0]->id); 

    $orderlineitem=0; 
     foreach($order_products as $order_product) { 


      //get warehouse order id from local db 
      $w_ord_id=$this->order_m->getwarehouseOrderId($order_product->order_id); 


      $prod=$this->product_m->getProductCode($order_product->product_id); 

      $product_code = $prod[0]->product_code; 
      $addorderproduct = $this->BLWP_CreateOrderLine($w_ord_id[0]->warehouse_order_id, $product_code, $order_product->quantity, $order_product->sales_price,''); 

      if(strpos($addorderproduct[1], 'OK')== true) { 
      $ordline = explode("=", $addorderproduct[3]); 
      $w_order_line_id=$ordline[1]; 
      //add order line id for each product in the table order product 
      $this->order_product_m->update_order_line_id($order_product->order_id,$order_product->product_id,$w_order_line_id); 
      $orderlineitem=1; 
      } 
      else $msg="Order line item not created"; 
     } 

     //Process order================================ 
     if($orderlineitem==1) { 
    $process_ord_response = $this->BLWP_ProcessOrder($w_ordid);  
    $process_order = explode("=", $process_ord_response[3]); 
    $w_ord_status= $process_order[1]; 
    $this->order_m->addWarehouseorderStatus($order[0]->id,$w_ord_status); //update order with warehouse id/ 
    } 
    else $msg.="<br>Order not processed"; 
    //============================================ 

    $msg.=" Order sent to warehouse"; 
} 
else 
{ 
    $msg="Order could not be sent to warehouse"; 
$this->send_order($order,$wcustid,$customer_address_id); 
    //want to create the retry button here. 

} 
return $msg; 

} 
+0

感谢您的回复,我会看看它。我还没有在else之后添加'{}',我想知道这是否是导致问题的原因。 –

+1

兄弟,如果你还没有添加{}这些,那么函数将继续递归调用,并且永远不会到达'return $ msg;' – mokNathal

+0

难道这是它继续去'订单没有发送到仓库'消息的原因吗? Cos继续发生。 –

相关问题