Closed rgopalakeans closed 9 months ago
@rgopalakeans
Try like this
$user_id = $event->shopId->toNative();
Hi @shawon922,
Thanks for your response. Will try same and let you know, if any issues.
Thanks, Gopal R
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.
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
@Kyon147 @shawon922 @rgopalakeans could you please help? thank you.
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));
}
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; /**
@return void */ protected Shop $shop;
public function __construct() { $this->onQueue('default'); }
/**
@return void */ public function handle(AppInstalledEvent $event) { $user_id = $event->shopId; $user_email = \App\Models\User::where('id', $user_id)->value('email');
} }`
Issue & log
Object of class Osiset\ShopifyApp\Objects\Values\ShopId could not be converted to string
When print with die
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