# fluent-cart/1.6.0/app/Models/ProductDownload.php

FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler, version 1.6.0. 100 lines.

- Page: https://pluginprobe.com/plugins/fluent-cart/1.6.0/code/app/Models/ProductDownload.php
- Raw: https://pluginprobe.com/plugins/fluent-cart/1.6.0/raw/app/Models/ProductDownload.php
- Modified: 2026-01-23T12:08:50+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/fluent-cart/1.6.0/code/app/Models/ProductDownload.php#L10-L20`.

```php
<?php

namespace FluentCart\App\Models;

use FluentCart\App\Models\Concerns\CanSearch;
use FluentCart\App\Services\FileSystem\DownloadService;

/**
 *  Product Download Model - DB Model for Product Downloads
 *
 *  Database Model
 *
 *
 * @package FluentCart\App\Models
 *
 * @version 1.0.0
 */
class ProductDownload extends Model
{
    use CanSearch;

    protected $table = 'fct_product_downloads';

    protected $fillable = [
        'post_id',
        'product_variation_id',
        'download_identifier',
        'title',
        'type',
        'driver',
        'file_name',
        'file_path',
        'file_url',
        'file_size', // size in bytes
        'settings',
        'serial',
    ];


    public function setSettingsAttribute($settings)
    {
        if (is_array($settings) || is_object($settings)) {
            $settings = json_encode($settings, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
        }
        $this->attributes['settings'] = $settings;
    }

    public function getSettingsAttribute($settings)
    {
        if (is_string($settings)) {
            $decoded = json_decode($settings, true);
            return $decoded ?: $settings;
        }
        return $settings;
    }

    public function setProductVariationIdAttribute($variations)
    {
        if (is_array($variations)) {
            $value = json_encode($variations, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
        } elseif (is_numeric($variations)) {
            $value = json_encode([(int)$variations], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
        } else {
            $value = json_encode([], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
        }

        $this->attributes['product_variation_id'] = $value;
    }

    public function getProductVariationIdAttribute($value)
    {
        if (is_string($value)) {
            $decoded = json_decode($value, true);
            return $decoded ?: [];
        }
        return [];
    }

    /**
     * One2One: Dwonloadable Files belongs to one product
     *
     * @return \FluentCart\Framework\Database\Orm\Relations\BelongsTo
     */
    public function product()
    {
        return $this->belongsTo(Product::class, 'post_id', 'ID');
    }

    public function download_permissions()
    {
        return $this->hasMany(OrderDownloadPermission::class, 'download_id', 'id');
    }

    public function getSignedDownloadUrl(): string
    {
        return DownloadService::getDownloadableUrlFromDownload($this->toArray());
    }

}

```
