Files
SpiceManagementSystem/app/Models/Product.php
T
Malek TellissiandClaude Sonnet 4.6 3ebd9845b0
Deploy / deploy (push) Successful in 14s
Add Shopify publish/sync per product variant
Each size row in the product form now shows a Shopify status badge
(green ✓ Shopify / gray Lokal). For saved variants, an action button
appears: 'Zu Shopify' for local-only variants (creates via Shopify
API and stores the returned variant ID), 'Shopify sync' for linked
variants (pushes price/SKU/GTIN to Shopify).

Also fixes:
- gtin missing from ProductSize::$fillable (was silently not saved)
- shopify_product_id added to products table and stored on import
- sizes afterStateHydrated now loads ProductSize directly instead of
  via the belongsToMany pivot (gets product_size_id, shopify_variant_id)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-09-12 17:20:26 +02:00

43 lines
974 B
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Product extends Model
{
protected $fillable = ['title', 'description', 'images', 'package_content', 'recipes_id', 'shopify_product_id'];
protected $casts = [
'images' => 'array',
];
public function recipe()
{
return $this->belongsTo(Recipe::class, 'recipes_id');
}
public function recipeVersions()
{
return $this->hasMany(Recipe::class)->orderByDesc('version');
}
public function sizes()
{
return $this->belongsToMany(Packing::class, 'products_sizes')
->withPivot('price', 'description', 'sku', 'gtin')
->withTimestamps();
}
public function inventories()
{
return $this->hasMany(ProductInventory::class);
}
public function batches()
{
return $this->hasMany(Batch::class);
}
}