Skip to main content

Overview

Core notifications are exposed via contracts, so you can swap implementations without changing core code. Each notification has a contract in Esign\UnleashCommerce\Core\Contracts\Notifications and a default implementation in Esign\UnleashCommerce\Core\Notifications.

Replace a core notification

Create a custom notification that implements the same contract. You can extend the core notification and override the parts you need:
namespace App\Notifications;

use Esign\UnleashCommerce\Core\Contracts\Notifications\OrderConfirmationNotification as OrderConfirmationNotificationContract;
use Esign\UnleashCommerce\Core\Notifications\OrderConfirmationNotification as BaseOrderConfirmationNotification;
use Illuminate\Notifications\Messages\MailMessage;

class OrderConfirmationNotification extends BaseOrderConfirmationNotification implements OrderConfirmationNotificationContract
{
    public function toMail($notifiable)
    {
        return (new MailMessage)
            ->subject('Your order is confirmed')
            ->line('Thanks for your purchase.')
            ->action('View your order', route('orders.index'));
    }
}

Bind the notification contract

Bind the contract to your custom class in a service provider:
<?php

namespace App\Providers;

use App\Notifications\OrderConfirmationNotification;
use Esign\UnleashCommerce\Core\Contracts\Notifications\OrderConfirmationNotification as OrderConfirmationNotificationContract;
use Illuminate\Support\ServiceProvider;

class UnleashCommerceServiceProvider extends ServiceProvider
{
    public function register(): void
    {
        $this->registerNotifications();
    }

    protected function registerNotifications(): void
    {
        $this->app->bind(
            OrderConfirmationNotificationContract::class,
            OrderConfirmationNotification::class
        );
    }
}

Available notification contracts

See the full list in the Notifications Reference.