Welcome Guest, Not a member yet? Register   Sign In
Best way to extend the cart
#1

[eluser]cmgmyr[/eluser]
Hey everyone,
I'm trying to figure out a good way to extend the cart so that I can use different session names, but everything in the core library has "cart_contents" hard coded into it.

I have a website with 2 different sections. Customers can have access to one, the other, or both. I need 2 different carts (ie: different session names), so that one cart doesn't bleed into the other (if the customer has access to both sections). The 2 different sections have 2 totally different products, database tables, and checkout process.

So my question is: what is the best way of changing/extending the cart library so that I can dynamically change the session names?

Thanks in advance.
#2

[eluser]cmgmyr[/eluser]
*bump*
#3

[eluser]pickupman[/eluser]
How about creating another class like called Customer_cart, and do a search and replace for "cart_contents". Then you could load cart and customer_cart.
#4

[eluser]pickupman[/eluser]
It's only in five spots. You could also extend the cart class with MY_Cart.php instead of 'cart_contents' being hard coded as the session variable, you could add a new property to the class called cart_key. Then you could make the get/set routines of the class require the session variable.

Something like:
Code:
class MY_Cart extends CI_Cart{

  public $cart_key;

  public function __construct(){
    parent::__construct();
    $this->cart_key = 'cart_contents';
  }

  public function insert($items = array(), $cart_key = 'cart_contents')
  {
    $this->cart_key = $cart_key;
   //insert() method
  }

  private function _save_cart()
  {
    //More stuff here

    // If we made it this far it means that our cart has data.
    // Let's pass it to the Session class so it can be stored
    $this->CI->session->set_userdata(array($this->cart_key => $this->_cart_contents));
  }
}




Theme © iAndrew 2016 - Forum software by © MyBB