Accessing shop data in webhook jobs #653
-
Hello there,
However I am not sure what modification I need to do here before actually registering for webhooks. It always throwing error for $this->domain to be undefined. I know I can manually query it from DB table with $this->shopDomain, but I want this object to be like one we get when we use $shop = Auth::user() with auth.shopify middleware. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Heres an example job with some stuff stripped out, take a look at handle. <?php
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Osiset\ShopifyApp\Objects\Values\ShopDomain;
use Osiset\ShopifyApp\Contracts\Queries\Shop as ShopQuery;
class DummyJob implements ShouldQueue
{
use Dispatchable;
use InteractsWithQueue;
use Queueable;
use SerializesModels;
/**
* The shop domain.
* Initially starts as string in contstructor to allow for serialization.
* Handle method converts it to a shop domain.
*
* @var ShopDomain|string
*/
protected $domain;
/**
* Job setup.
*
* @param string $domain The shop's domain.
*
* @return self
*/
public function __construct(string $domain)
{
$this->domain = $domain;
}
/**
* Handle the job.
*
* @param ShopQuery $shopQuery The shop querier.
*
* @return void
*/
public function handle(ShopQuery $shopQuery): void
{
// Convert domain
$this->domain = ShopDomain::fromNative($this->domain);
// Get the shop and setup CCS with the shop
$shop = $shopQuery->getByDomain($this->domain);
// $shop is now the user model
// $shop->api() is available to use as well
}
} |
Beta Was this translation helpful? Give feedback.
Heres an example job with some stuff stripped out, take a look at handle.