2017-09-12 74 views
0

我正嘗試從多家餐館下訂單。當我下訂單時,同樣訂單編號正在數據庫中添加訂單。我想要的是,當用戶從多家餐廳下訂單時,我想爲他們單獨訂購訂單號來自多家餐廳的訂單的不同訂購ID

這裏是我的代碼:

$order_id = $this->generateNewOrderId();  
foreach ($cart_content->rest_item_list as $item) 
    { 
     $td_data['order_id'] = $order_id; 
     $td_data['item_id'] = $item->id; 
     $i_details = $this->restaurant_menu_items_model->get_item_detail_by_id($item->id); 
     $td_data['item_name'] = $i_details->name; 
     $td_data['item_price'] = $i_details->price; 
     $td_data['item_quantity'] = $item->quantity; 
    } 

回答

1

嗯,這按理說,因爲你每生成訂單的訂單ID只有一次,外循環,一次也沒有。只需將其移動到迴路中即可:

foreach ($cart_content->rest_item_list as $item) { 
    $order_id = $this->generateNewOrderId(); 
    $td_data['order_id'] = $order_id; 
    //... etc ...