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

[eluser]haseydesign[/eluser]
Hey Rei,

I can give you a generic example of how you can get the price from the database, but this is using an example database schema that will not necessarily fit your requirements, so you will have to adjust it to your needs.

If your not too familiar with ecommerce database schemas, spend a little time researching on Google, as different table structures can have many advantages and disadvantages to each design structure.

Remember, all you essentially need to do is create an array of the products data, and then add that data to the cart via the 'insert_items()' function.
How you get that product data is completely up to you.

Code:
// Get the id of the product option from POST data.
$product_option_id = $this->input->post('product_option_id');

// Run your SQL query to get your product data from the database.
$query = $this->db->select('product_table.product_id, product_table.product_name, product_options.option_name, product_options.price')
->from('product_table')
->join('product_options', 'product_table.product_id = product_options.product_id')
->where('product_option_id', $product_option_id)
->get();

// Check database data was returned.
if ($query->num_rows() == 1)
{
// Assign the database data to a variable.
$product_data = $query->row_array();

// Build the data array that will passed to the flexi cart 'insert_items()' function.
$cart_data = array(
  'id' => $product_data['product_id'],
  'name' => $product_data['product_name'].' - '.$product_data['option_name'],
  'quantity' => 1,
  'price' => $product_data['price']
);

// Insert the product to the cart.
$this->flexi_cart->insert_items($cart_data);
}


Messages In This Thread
flexi cart - A comprehensive shopping cart library for CodeIgniter - by El Forum - 08-20-2012, 08:47 PM



Theme © iAndrew 2016 - Forum software by © MyBB