Kyon147 / laravel-shopify

A full-featured Laravel package for aiding in Shopify App development
MIT License
363 stars 107 forks source link

Trying the Event Listener System, Facing Typecasting Issue #241

Closed rgopalakeans closed 9 months ago

rgopalakeans commented 10 months ago

https://github.com/Kyon147/laravel-shopify/wiki/Event-Listener-System#appinstalledeventclass

With help of above, trying to create a "AppInstalledEventListener" to sending a mail to merchart & admin after App getting installed.

/html/config/shopify-app.php

'listen' => [ \Osiset\ShopifyApp\Messaging\Events\AppInstalledEvent::class => [ \App\Listeners\SendAppInstalledEmailListener::class, ], ]

/html/app/Listeners/SendAppInstalledEmailListener.php

`<?php namespace App\Listeners;

use Illuminate\Bus\Queueable; use Illuminate\Support\Facades\Mail; use Illuminate\Contracts\Queue\ShouldQueue; use Osiset\ShopifyApp\Messaging\Events\AppInstalledEvent; use Illuminate\Support\Facades\Log;

class SendAppInstalledEmailListener implements ShouldQueue { use Queueable; /**

When print with die

screen1

Request

How to use the $shop_id to get shop user email? Please help us to use this "Event & Listener System".

Note

We tried many ways to to convert as a string ,int, json but no success.

Thanks, Gopal R

shawon922 commented 10 months ago

@rgopalakeans Try like this $user_id = $event->shopId->toNative();

rgopalakeans commented 10 months ago

Hi @shawon922,

Thanks for your response. Will try same and let you know, if any issues.

Thanks, Gopal R

Kyon147 commented 10 months ago

The event system has only just been released today in 19.2.0 the docs were added before the release (should have mentioned it in the docs).

Can you update your app and try again with the new version.

thanhnv37 commented 4 months ago

Hi all,

How do you get the shop email on the event AppInstalledEvent? The email stored in the user table is not the correct email.

I tried using the API get shop https://shopify.dev/docs/api/admin-rest/2024-04/resources/shop#get-shop

But the method Auth::user(); return null on this event. So when I call the method Auth::user()->api()->rest(); it returned error.

Thank you for your help.

Thanks, Thanh Nguyen

thanhnv37 commented 4 months ago

@Kyon147 @shawon922 @rgopalakeans could you please help? thank you.

thanhnv37 commented 4 months ago

Below is my code:

public function handle(AppInstalledEvent $event)
  {
    $shop = Auth::user();
    $data = $shop->api()->rest('GET', '/admin/shop.json')['body']['shop'];

    Mail::to($data['email'])->send(new AppInstalled($data));
  }