Skip to content
This repository has been archived by the owner on Nov 30, 2022. It is now read-only.

Adding event to notify App Installation on the store #1220

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

abishekrsrikaanth
Copy link

The AppInstalled event will be triggered after the installation of App on the store. This can be used to run jobs after successful installation. For example, fetching data from the store that is needed by the application.

Here is an example of how to set up a Listener and subscribe to it on the project's EventServiceProvider.

<?php

namespace App\Listeners;

use Osiset\ShopifyApp\Messaging\Events\AppInstalled;

class AppInstalledEventListener
{
    /**
     * Handle AppInstalled Event.
     *
     * @param  Osiset\ShopifyApp\Messaging\Events\AppInstalled $event
     * @return void
     */
    public function handle(AppInstalled $event)
    {
            $shop = $event->getShop();
            // Get Shop Details
            // Get Products
            // Get Collections
            // etc...
    }
}

Once your listener has been defined, you may register it within your application's EventServiceProvider:

<?php

namespace App\Providers;

use App\Listeners\AppInstalledEventListener;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
use Osiset\ShopifyApp\Messaging\Events\AppInstalled;

class EventServiceProvider extends ServiceProvider
{
    protected $listen = [
        AppInstalled::class => [
            AppInstalledEventListener::class,
        ],
    ];
}

@Kyon147, I am resending this PR again as the last PR (#1058) had additional code that was already merged in to the repo.

@Kyon147
Copy link
Collaborator

Kyon147 commented Oct 4, 2022

Hi @abishekrsrikaanth

Thanks for submitting a PR. Could you let me know how you would use this differently to the AfterAuthenticate job that already exists in the package which can be used for the same thing.

Thanks!

@nahid
Copy link
Contributor

nahid commented Oct 4, 2022

Also, need to add the AppUninstalled, PlanPurchased, and PlanChanged events.

@osiset and @Kyon147

@gnikyt
Copy link
Owner

gnikyt commented Oct 4, 2022

@nahid I think Kyron147 was asking how does it differ from AfterAuthenticate, are you saying we should deprecate AfterAuthenticate in favor of these events? If so, let us know :) and if thats the case, we would have to update documentation and make a major release for these events as it would break existing apps depending on if they use AfterAuthenticate.

@nahid
Copy link
Contributor

nahid commented Oct 5, 2022

@osiset Thanks, got it. I think the AfterAuthenticate job feature should be deprecated in the next version but legacy support is required up to a certain version. It can be configurable. If someone wants to use the legacy feature he/she didn't need to configure anything but if someone is want to use the Event Listener feature they need to configure it.

In my previous comment I meant that we need to add AppUninstalled, PlanPurchased, and PlanChanged events besides the AppInstalled event. Because sometimes App owners need to notify the shop owners of these events.

@gnikyt
Copy link
Owner

gnikyt commented Oct 5, 2022

@nahid Sounds fine to me, if you would like to add those additional events and some jotnotes on how to use the events so we can form a wiki entry for people, that would be great. We can then review and merge in for a major release.

@nahid
Copy link
Contributor

nahid commented Oct 6, 2022

Thank you @osiset, I'll make a PR with these changes ASAP.

@gnikyt
Copy link
Owner

gnikyt commented Oct 6, 2022

@nahid One thing to note for appinstalled, is that there will need to be an option to run it "inline" and not later somehow. Some people require changes to be made before the shop user sees the app (example, set some flag in the database).

@bilfeldt
Copy link
Contributor

@nahid One thing to note for appinstalled, is that there will need to be an option to run it "inline" and not later somehow. Some people require changes to be made before the shop user sees the app (example, set some flag in the database).

@osiset Given that this is not a job being dispatch but an event, then note that events are always synchronous. The listeners one might register for these events on the other hand can be either queued or synchronous. So "inline" is essentially build into the implementation using events, making it a really nice solution for any use case 👍

@nahid
Copy link
Contributor

nahid commented Oct 20, 2022

@bilfeldt exactly, if someone wants to run Listener immediately, just ignore the ShouldQueue implementation

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants