CodeIgniter Forums

Full Version: Multiple different shopping cart instances
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]TheManT[/eluser]
Hello!

I'm developing an application and i'm using the shopping cart.
The users can buy from different stores on my application at the same time.

Because of that, i need to create/use a different cart in each store that the users are visiting.

How can i use the cart library to build multiple different carts?

I've tried to load using different object name but they all are the same values.
$this->load->library('cart', '', 'cart_1');
$this->load->library('cart', '', 'cart_2');

Thanks for your attention!
And sorry for my bad english! ^^

El Forum

[eluser]jvicab[/eluser]
try to se if this work:
$this->load->library('cart');
$cart1 = $this->cart;
$this->load->library('cart');
$cart2 = $this->cart;
Now I hope you have two different cart objects and you could use them to call the cart's methods.

El Forum

[eluser]TheManT[/eluser]
I've tried to add products in $cart1 and then show the $cart2.

But when i showed the $cart2, it shows the products i've added in $cart1...

They are getting the values at the session, so don't matter who added the products, all of them will see...

Is there a way to create a new and different session and set it to be used on my cart?

El Forum

[eluser]jvicab[/eluser]
well, let's try to create two objects of the cart class and see what happens:

$cart1 = new CI_Cart();
$cart2 = new CI_Cart();

El Forum

[eluser]TheManT[/eluser]
I've discovered something.
When i login (new session) and add items to cart1 and show cart2, the cart2 dont have any item i've added in cart1.
But if i refresh the page, the cart2 comes with the items...

So, i thing i have to load ALL the carts at the first time (when i login for example) e then just use the reference.
Even if i use new CI_Cart, in the second time it comes with values from the other cart...

I think the constructor method get the values from the session...

Am i right?

El Forum

[eluser]jvicab[/eluser]
yes, I would implement my own set of carts in your case, because seems like CI is messing up with session values when using cart library more than once. You might use the code of CI cart class and starting from there create your version making sure the session data won't conflict each others

El Forum

[eluser]Unknown[/eluser]
any simple solution ??
how about cart-array filtering ?

El Forum

[eluser]jvicab[/eluser]
I would create my own custom cart class, probably extending CO cart class. Later I will instantiate as many instances of it as different carts I need, so all of them will have the same functionality but with their own properties values