Question

While building an ecommerce platform I have run into design problems. I'm working with the built-in CodeIgniter's cart class. It stores all the cart information in session. Let say that cart has already been filled with products and user clicks checkout. When should I store order in database? Just after that click or after several steps of gathering information and stoing it in session? How to deal with additional features like different shipping methods? Should I add it to the basket first and get additional (gift address) to session? I dont want to store it in database because of the relation between gift address and order is needed and since I dont know what's the ID of the order. I'm puzzled :) Additionally I think its crucial to keep cart aware of shipping methods and additional bought services (by selecting gift address there is an extra fee) because the cart content is just like an reciept?

In brief, what is the best practice to process checkout?

Was it helpful?

Solution

You can add additional attributes to your cart item (like shipping options) by using the "options" value of the cart.

$data = array(
           'id'      => 'sku_123ABC',
           'qty'     => 1,
           'price'   => 39.95,
           'name'    => 'T-Shirt',
           'options' => array('shipId' => '1234abcd5678efghi')
        );

$this->cart->insert($data);

Bear in mind you don't need incremental IDs from the database; you can create unique IDs with uniqid() or com_create_guid().

Since you are asking for an opinion... You should store different shipping addresses in a separate address book table related to the user, not joined to the order. When you finally create an order as part of the checkout, you should copy all of the data (address data and relevant product data) to separate order tables because the product data and address book data can change; order data should be written once and never updated, aside from status. Once the order is saved you can delete the session data.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top