views:

301

answers:

3

Is it possible to add price values to product options in the Codeigniter Cart Class. For example: T-shirt price is $10.00, but the XXL size is an extra $2.00.

$data = array(
           'id'      => 'abc',
           'qty'     => 1,
           'price'   => 10.00,
           'name'    => 'T-Shirt',
           'options' => array('Size' => 'XXL') // Where would you add $2.00 for XXL?
        );

$this->cart->insert($data);
+1  A: 

From looking at the cart class, it looks like the only way to do what you're asking is to incorporate the options price into the price that is passed to CodeIgniter's cart class. So you'd pass the array you provided in your example, with $data['price'] set to 12.00 (10.00 plus the 2.00 for XXL)

My understanding of CI's cart class is that it's only there to provide the basic session handling information for a shopping cart. Things like product options with their own pricing would need to be built on top of it in your own code.

Eric
A: 

Yep, you should "merge" the product with the option price and put the package with the total, new price into your cart. That's probably the only way that I can come up with if you want to be able to use CI:s prebuilt features of cart total etc.

Industrial
A: 

That's one of the reasons why we built our own cart and order management system apart from CI's original one.

The better way imho is to extend or rebuild CI's cart Class in order to inject product and options straight from db results. This way you can always track down how the price was calculated : from ericofsac's answer, why it is priced at 12 not 10 and how much the option was charged at sale's time.

You can also ease implementation of recording interfaces from your cart data to your order, but that's another point.

Benoit
Thanks! I'm having to use my understanding of CI's Cart Class to build my own session based cart system.
JonP