Welcome Guest, Not a member yet? Register   Sign In
$this->cart->total() - Can this be manipulated?
#1

[eluser]EdgeTube[/eluser]
Hi all,

I am trying to create a coupon code function using the shopping cart class. For some reason I cannot manipulate the $this->cart->total() as I am given an error "Can't use method return value in write context."

Any ideas on how I could apply a coupon code and somehow change the total?

Thanks!
#2

[eluser]bubbafoley[/eluser]
The cart class is very incomplete.

I would extend the Cart class to make the desired changes.

Something like this should work:
application/libraries/MY_Cart.php
Code:
<?php

class MY_Cart extends CI_Cart {

    function __construct()
    {
        parent::__construct();
    }

    function update_total($new_total)
    {
        $this->_cart_contents['cart_total'] = $new_total;
    }

}

then in your controller you can do this:

Code:
$this->cart->update_total(199.95);
#3

[eluser]EdgeTube[/eluser]
Cool, thanks.

The function above seems to work well. However, it looks like it's not correctly updating the grand total.

When I use my 'coupon' controller to update the total using the function above, and echo $this->cart->total(), the price shows up correctly.

However, when I have it redirect back to the shopping cart, it looks like the grand total did not update.

Any suggestions as to how to make a permanent change to the grand total?

Thanks!




Theme © iAndrew 2016 - Forum software by © MyBB