darryldecode / laravelshoppingcart

Shopping Cart Implementation for Laravel Framework
1.33k stars 436 forks source link

How to use newly created cart instance? #50

Closed rashmi1403 closed 8 years ago

rashmi1403 commented 8 years ago

Hi,

I needed to create a new cart instance and retain the same one throughout the session. So I created a new service provider and added the code in the register() method. Now how do I use this cart name/ instance while adding or updating my cart contents?

Thank You!

darryldecode commented 8 years ago

You can do it like so:

$WishlistCart = app('wishlist');

$WishlistCart->add(455, 'Sample Item', 100.99, 2, array());
rashmi1403 commented 8 years ago

I got this error when I tried using it like you mentioned.

Call to undefined method Darryldecode\Cart\Facades\CartFacade::add()

darryldecode commented 8 years ago

Your are using the wrong Cart class. Use \Cart::add() directly. See this link if you want some information about facade system: https://laravel.com/docs/5.1/facades

rashmi1403 commented 8 years ago

I am sorry, I am new to laravel and not getting this. Do you mean that I should update aliases in app.php with 'add' => 'Darryldecode\Cart::add()', and then use $WishlistCart->add(455, 'Sample Item', 100.99, 2, array()); with "use add;" at the beginning? I tried this and still get the same error.

And when I do use \Cart::add(); at the beginning, I get syntax error, unexpected '::' (T_PAAMAYIM_NEKUDOTAYIM), expecting ',' or ';'

rashmi1403 commented 8 years ago

Just using 'Cart' => 'Darryldecode\Cart\Cart', instead of 'Cart' => 'Darryldecode\Cart\Facades\CartFacade' in Aliases in app.php solves the issue.

mohasin-dev commented 5 years ago

Call to undefined method Darryldecode\Cart\Cart::associate()