Friday, July 22, 2016

How to implement shopping cart in laravel 5

How to implement shopping cart in laravel 5:

For implement shopping cart in your application we have to follow following steps:

1. In your composer.json file write the following code in require:


"gloudemans/shoppingcart": "^2.1",

then run command composer update.

2. In config/app.php write the following code.

In providers:
\Gloudemans\Shoppingcart\ShoppingcartServiceProvider::class

In aliases:
'Cart'            => \Gloudemans\Shoppingcart\Facades\Cart::class,

Now we can use cart in our applications

for add product in cart:
 Cart::add('293ad', 'Product 1', 1, 9.99);

 Here first parms is product id, 2nd is name of product, 3rd quantity and 4th is price of product

for update:
Cart::update($rowId, 2);

Here $rowId is a unique id product wise which is generate automatically.
2nd params is the quantity, which we want to increase.

for remove:
Cart::remove($rowId);

for check the cart:
Cart::content();

for destroy cart:
Cart::destroy();

for total in cart:
Cart::total();

for count in cart:
Cart::count();

Thanks

3 comments:

  1. Hej....
    What about session? Can I use session with it?

    ReplyDelete
  2. Is it better to use a shopping cart for creating an ecommerce site on Laravel? Or I can use packages that offer full ecommerce system? I have noticed that creating a complete ecommerce site using ecommerce package in Laravel (https://www.cloudways.com/blog/laravel-ecommerce-website-with-aimeos-package/ ) is much simpler than implementing a shopping cart. Which one would you suggest?

    ReplyDelete
  3. Our certified Laravel developers can create scintillating extensions and mapping of web applications that ensure quicker performance. We have the acumen of delivering small scale to large scale projects based on Laravel development. You name the service that you are looking for in laravel Development and we will be able to deliver that to you in minimal time. Contact@ExpressTechSoftwares.Com or +91-9806724185

    ReplyDelete