Welcome Guest, Not a member yet? Register   Sign In
Process the Cart
#1

[eluser]ramm[/eluser]
Hi all

I started working on a shopping cart, i can add products, delete, update the cart, and empty it, everything works fine.

Now, how should i save the order? and its contents?

I think I need to make a new table 'orders' with the user information, date, status, order total, etc, but i don't know how to save the cart data and be able to show it later (considering that if i change the price of a product later on, the old orders will still have the prices from when they were ordered)

I'd appreciate any help regarding this.

Thanks
#2

[eluser]nedimtx[/eluser]
Hi there.

If you want to save your orders you have to create a table in your database.

Check out user guide:
http://ellislab.com/codeigniter/user-gui.../cart.html

There is:

Code:
$this->cart->contents();

Just type:

Code:
$contents = $this->cart->contents();

$contents is going to return an array. Then use foreach. Check out:
http://www.php.net/manual/en/control-str...oreach.php

I think you need two tables in your database.
One with orders:

- id order
- data about a person who made order
- delivery data

And another one with ordered items. In this second you need a column connected to first table. In that column you have to insert id of record in the first table (orders).

Is everything clear to you?

N.
#3

[eluser]ramm[/eluser]
Clear as water!

Thank you!

I even had an idea, not sure how good can it be, i can put all cart contents into a view:
Code:
$data = //array with the formatted content for the view
$this->load->view('saved_order_tpl', $data, TRUE);

Using the parameter TRUE to convert the rendered view to a string, then save it into the same table together with the rest of the order information.
#4

[eluser]nedimtx[/eluser]
Np ramm.

Well you can put all cart contents into a view to show users, but in the end you have to insert in a table, because you need to process an order.




Theme © iAndrew 2016 - Forum software by © MyBB