vanilophp / framework

The truly Laravel E-commerce Framework
https://vanilo.io
MIT License
810 stars 102 forks source link

[Q] New product order notification via e-mail #38

Closed mironcat closed 5 years ago

mironcat commented 5 years ago

Is it possible to receive an email when a new product order? I didn't find anything about it in the documentation. Thank you for this interesting project!

fulopattila122 commented 5 years ago

You have to add a listener in your application's EventServiceProvider, that listens to the OrderWasCreated event. See an example here: https://github.com/vanilophp/framework/blob/master/src/Providers/EventServiceProvider.php

Please let me know if it worked or if you need more guidance.

mironcat commented 5 years ago

Thank you! I will try and write this if it worked or not

mironcat commented 5 years ago

I'm a absolutely newbie at the Laravel. I create and register the file of lisener:

\app\Listeners\OrderListener.php but now I have an error: Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_RECOVERABLE_ERROR) Argument 1 passed to App\Listeners\OrderListener::handle() must be an instance of App\Events\Vanilo\Order\Events\OrderWasCreated, instance of Vanilo\Order\Events\OrderWasCreated given

at the listener:

//  \app\Listeners\OrderListener.php

class OrderListener
{
    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     *
     * @param  OrderWasCreated  $event
     * @return void
     */
    public function handle(OrderWasCreated $event)
    {
        //
        $order = $event->getOrder();
        dd($order);
    }
}
fulopattila122 commented 5 years ago

Add

use Vanilo\Order\Events\OrderWasCreated;

to the list of use clauses in the OrderListener.php file

mironcat commented 5 years ago

Thank you! It works!