Events

Working with Laravel, how can we forget events?

This package fires various cart related events which you can listen to for any application updates.

  1. CartCreated -> Fired when cart is created for the session for the first time and contains the full cart data in the variable $cartData.

  2. CartItemAdded -> Fired when an item is added to the cart and contains the new item Eloquent model object in the variable $entity.

  3. CartItemRemoved -> Fired when an item is removed from the cart and contains the new item Eloquent model object in the variable $entity.

  4. DiscountApplied -> Fired when discount if applied to the cart and contains the full cart data in the variable $cartData.

  5. CartCleared -> Fired when the cart is cleared.

Sample Usage

Add the event and listener entry in the EventServiceProvider class

protected $listen = [
    'Freshbitsweb\LaravelCartManager\Events\CartCreated' => [
        'App\Listeners\LogCartCreated',
    ],
];

Create respective listener:

<?php

namespace App\Listeners;

use Illuminate\Support\Facades\Log;
use Freshbitsweb\LaravelCartManager\Events\CartCreated;

class LogCartCreated
{
    /**
     * Handle the event.
     *
     * @param CartCreated $event
     * @return void
     */
    public function handle(CartCreated  $event)
    {
        Log::info('cart', [$event->cartData]);
    }
}

Commands