Implement MakerWorld collections sync every 10 minutes and Artikel Beheer staging workflow
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class MakerWorldCollection extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'makerworld_collections';
|
||||
|
||||
protected $fillable = [
|
||||
'makerworld_collection_id',
|
||||
'name',
|
||||
'slug',
|
||||
'description',
|
||||
'cover_url',
|
||||
'user_handle',
|
||||
'source_url',
|
||||
'is_active_sync',
|
||||
'sync_interval_minutes',
|
||||
'items_count',
|
||||
'last_synced_at',
|
||||
'last_sync_status',
|
||||
'last_sync_message',
|
||||
'raw_metadata',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'is_active_sync' => 'boolean',
|
||||
'sync_interval_minutes' => 'integer',
|
||||
'items_count' => 'integer',
|
||||
'last_synced_at' => 'datetime',
|
||||
'raw_metadata' => 'array',
|
||||
];
|
||||
|
||||
public function products(): HasMany
|
||||
{
|
||||
return $this->hasMany(Product::class, 'makerworld_collection_id');
|
||||
}
|
||||
|
||||
public function draftProducts(): HasMany
|
||||
{
|
||||
return $this->hasMany(Product::class, 'makerworld_collection_id')
|
||||
->where('status', 'draft');
|
||||
}
|
||||
|
||||
public function publishedProducts(): HasMany
|
||||
{
|
||||
return $this->hasMany(Product::class, 'makerworld_collection_id')
|
||||
->where('status', 'published');
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
@@ -13,6 +14,7 @@ class Product extends Model
|
||||
|
||||
protected $fillable = [
|
||||
'makerworld_id',
|
||||
'makerworld_collection_id',
|
||||
'category_id',
|
||||
'name',
|
||||
'slug',
|
||||
@@ -24,9 +26,11 @@ class Product extends Model
|
||||
'stock',
|
||||
'is_featured',
|
||||
'is_active',
|
||||
'status',
|
||||
'dimensions',
|
||||
'weight_grams',
|
||||
'print_time_hours',
|
||||
'print_info',
|
||||
'image_url',
|
||||
'makerworld_url',
|
||||
'makerworld_author',
|
||||
@@ -43,6 +47,7 @@ class Product extends Model
|
||||
'is_featured' => 'boolean',
|
||||
'is_active' => 'boolean',
|
||||
'print_time_hours' => 'float',
|
||||
'print_info' => 'array',
|
||||
'gallery_images' => 'array',
|
||||
'available_materials' => 'array',
|
||||
'available_colors' => 'array',
|
||||
@@ -53,11 +58,30 @@ class Product extends Model
|
||||
return $this->belongsTo(Category::class);
|
||||
}
|
||||
|
||||
public function makerworldCollection(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(MakerWorldCollection::class, 'makerworld_collection_id');
|
||||
}
|
||||
|
||||
public function orderItems(): HasMany
|
||||
{
|
||||
return $this->hasMany(OrderItem::class);
|
||||
}
|
||||
|
||||
public function scopePublished(Builder $query): Builder
|
||||
{
|
||||
return $query->where('is_active', true)
|
||||
->where(function ($q) {
|
||||
$q->where('status', 'published')
|
||||
->orWhereNull('status');
|
||||
});
|
||||
}
|
||||
|
||||
public function scopeDraft(Builder $query): Builder
|
||||
{
|
||||
return $query->where('status', 'draft');
|
||||
}
|
||||
|
||||
public function getFormattedPriceAttribute(): string
|
||||
{
|
||||
return '€ '.number_format((float) ($this->base_price ?? 0), 2, ',', '.');
|
||||
|
||||
Reference in New Issue
Block a user