Welcome Guest, Not a member yet? Register   Sign In
flexi cart - A comprehensive shopping cart library for CodeIgniter
#21

[eluser]haseydesign[/eluser]
Hey again koichirose,
What I would do in the scenario you have outlined is as follows.

1. Before you call the save_order() function, insert an empty record into your custom order_store table using CI's standard SQL functions.
2. Get the insert_id for the new table row.
3. Call the save_order() function and pass the insert_id to the save_order() functions $custom_item_data parameter - this will save the id of your order_store table to each item row in the order_details table.
4. When the save_order() function has saved the data, use the order_number() function to get the unique id (The order number) of the order_summary table.
5. Update your custom order_store table with the order_number value.

This should mean that your custom order_store table now has the unique id of the order_summary table, and the multiple newly added rows in the order_details will have the unique id of your order_store table.

Here's a rough example (Not tested)

Code:
// Insert record to custom order_store table.
// Insert whatever data you need, the aim is just to insert a record and get the id of the new row.
$order_store_data = array(...);
$this->db->insert('order_store', $order_store_data);
$order_store_id = $this->db->insert_id();

// Now we need to add the insert_id to each item row within the order_details table.
// To associate the insert_id with each item, we need to loop through the items that are in the cart and create an array.
// Use the cart_items() function to return an array of all cart items that we can then loop through.
$custom_item_data = array();
foreach($this->flexi_cart_admin->cart_items() as $row_id => $item)
{
$custom_item_data[$row_id]['order_store_id'] = $order_store_id;
}

// Now use the save_order() function with the $custom_item_data array.
$this->flexi_cart_admin->save_order(false, $custom_item_data);

// Get the order number of the newly added order (i.e. The unique id of the order_summary table)
$order_number = $this->flexi_cart_admin->order_number();

// Update your custom order_store table with the unique id of the order_summary table.
$sql_update_data = array('order_summary_id' => $order_number);
$sql_where = array('order_store_id' => $insert_id);
$this->db->update('order_store', $sql_update_data, $sql_where);

Function reference:
cart_items() - http://haseydesign.com/flexi-cart/user_g...cart_items
save_order() - http://haseydesign.com/flexi-cart/user_g...save_order
order_number() - http://haseydesign.com/flexi-cart/user_g...der_number

---

Without knowing your full scenario, I will point out that it may be better/easier to just associate the order_store_id with the single row in the order_summary table, rather than for each order_details row.
Each row within the order_details table could then get the order_store it is assoicated to by using the parent order_summary table.

But hey, thats just a suggestion, it may not be suitable for what you're doing.


Messages In This Thread
flexi cart - A comprehensive shopping cart library for CodeIgniter - by El Forum - 05-29-2012, 03:37 AM



Theme © iAndrew 2016 - Forum software by © MyBB