MOON
Server: Apache
System: Linux server.royaltuning.hu 4.18.0-425.13.1.el8_7.x86_64 #1 SMP Tue Feb 21 04:20:52 EST 2023 x86_64
User: royaltuning (1001)
PHP: 8.2.32
Disabled: exec,passthru,shell_exec,system
Upload Files
File: /home/royaltuning/public_html/public/backoffice.royaltuning.hu/app/Models/CentralProduct.php
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class CentralProduct extends Model
{
    protected $fillable = [
        'sku',
        'name',
        'slug',
        'description',
        'short_description',
        'regular_price',
        'sale_price',
        'manage_stock',
        'stock_quantity',
        'stock_status',
        'status',

        'is_variation',
        'parent_sku',
        'central_parent_product_id',
        'woo_parent_product_id',
        'woo_variation_id',
        'type',

        'categories',
        'attributes',
        'images',
        'raw_data',
    ];

    protected $casts = [
        'manage_stock' => 'boolean',
        'is_variation' => 'boolean',
        'categories' => 'array',
        'attributes' => 'array',
        'images' => 'array',
        'raw_data' => 'array',
    ];

    public function shopProducts()
    {
        return $this->hasMany(ShopProduct::class);
    }

    public function parentProduct()
    {
        return $this->belongsTo(
            CentralProduct::class,
            'central_parent_product_id'
        );
    }

    public function variations()
    {
        return $this->hasMany(
            CentralProduct::class,
            'central_parent_product_id'
        );
    }

    public function scopeParents($query)
    {
        return $query->where('is_variation', false);
    }

    public function scopeVariations($query)
    {
        return $query->where('is_variation', true);
    }

    public function isVariableParent(): bool
    {
        return $this->type === 'variable' && !$this->is_variation;
    }

    public function productImages()
    {
        return $this->hasMany(CentralProductImage::class)
            ->orderByDesc('is_main')
            ->orderBy('position');
    }

    public function mainImage()
    {
        return $this->hasOne(CentralProductImage::class)
            ->where('is_main', true);
    }
}