Deploy Ladill Woo Manager / deploy (push) Successful in 55s
Sync catalog via plugin webhooks and REST proxy, with list/create/edit UI and updated logo from monolith assets. Co-authored-by: Cursor <cursoragent@cursor.com>
74 lines
1.7 KiB
PHP
74 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Support\Str;
|
|
|
|
class WooStore extends Model
|
|
{
|
|
public const STATUS_PENDING = 'pending';
|
|
public const STATUS_ACTIVE = 'active';
|
|
public const STATUS_DISCONNECTED = 'disconnected';
|
|
|
|
protected $fillable = [
|
|
'user_id',
|
|
'public_id',
|
|
'site_url',
|
|
'site_name',
|
|
'return_url',
|
|
'webhook_secret',
|
|
'plugin_token_hash',
|
|
'status',
|
|
'connected_at',
|
|
'last_webhook_at',
|
|
'metadata',
|
|
];
|
|
|
|
protected $casts = [
|
|
'connected_at' => 'datetime',
|
|
'last_webhook_at' => 'datetime',
|
|
'metadata' => 'array',
|
|
'webhook_secret' => 'encrypted',
|
|
];
|
|
|
|
protected static function booted(): void
|
|
{
|
|
static::creating(function (self $store) {
|
|
if (! $store->public_id) {
|
|
$store->public_id = (string) Str::uuid();
|
|
}
|
|
if (! $store->webhook_secret) {
|
|
$store->webhook_secret = Str::random(48);
|
|
}
|
|
});
|
|
}
|
|
|
|
public function user(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
public function orders(): HasMany
|
|
{
|
|
return $this->hasMany(WooOrder::class);
|
|
}
|
|
|
|
public function products(): HasMany
|
|
{
|
|
return $this->hasMany(WooProduct::class);
|
|
}
|
|
|
|
public function categories(): HasMany
|
|
{
|
|
return $this->hasMany(WooCategory::class);
|
|
}
|
|
|
|
public function webhookUrl(): string
|
|
{
|
|
return rtrim((string) config('app.url'), '/').'/webhooks/woocommerce/'.$this->public_id;
|
|
}
|
|
}
|