HEX
Server: LiteSpeed
System: Linux my-kul-web2054.main-hosting.eu 5.14.0-611.13.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 11 04:57:59 EST 2025 x86_64
User: u665686179 (665686179)
PHP: 8.2.30
Disabled: system, exec, shell_exec, passthru, mysql_list_dbs, ini_alter, dl, symlink, link, chgrp, leak, popen, apache_child_terminate, virtual, mb_send_mail
Upload Files
File: /home/u665686179/domains/dealkr.com/public_html/Modules/AI/app/Services/ProductResourceService.php
<?php

namespace Modules\AI\app\Services;

use App\Models\Attribute;
use App\Models\Author;
use App\Models\Brand;
use App\Models\Category;
use App\Models\Color;
use App\Models\PublishingHouse;

class ProductResourceService
{
    protected Category $category;
    protected Brand $brand;
    protected Attribute $attribute;
    protected Color $color;
    protected Author $author;
    protected PublishingHouse $publishingHouse;

    private array $productType = ["physical", "digital"];
    private array $deliveryTypes = ["ready_product", "ready_after_sell"];

    public function __construct()
    {
        $this->category = new Category();
        $this->brand = new Brand();
        $this->attribute = new Attribute();
        $this->color = new Color();
        $this->author = new Author();
        $this->publishingHouse = new PublishingHouse();
    }

    private function getCategoryEntitiyData($position = 0)
    {
        return $this->category
            ->where(['position' => $position])
            ->get(['id', 'name'])
            ->mapWithKeys(fn($item) => [strtolower($item->name) => $item->id])
            ->toArray();
    }

    private function getBrandData()
    {
        return $this->brand->active()
            ->get(['id', 'name'])
            ->mapWithKeys(fn($item) => [strtolower($item->name) => $item->id])
            ->toArray();
    }

    public function productGeneralSetupData(): array
    {
        $data = [
            'categories' => $this->getCategoryEntitiyData(0),
            'sub_categories' => $this->getCategoryEntitiyData(1),
            'sub_sub_categories' => $this->getCategoryEntitiyData(2),
            'brands' => $this->getBrandData(),
            'units' => $this->units(),
            'product_types' => $this->productType,
            'delivery_types' => $this->deliveryTypes,

        ];
        return $data;
    }

    public function getVariationData(): array
    {
        $data = [
            'attributes' => $this->attribute
                ->get(['id', 'name'])
                ->mapWithKeys(fn($item) => [strtolower($item->name) => $item->id])
                ->toArray(),
            'color' => $this->color
                ->get(['id', 'name', 'code'])
                ->mapWithKeys(fn($item) => [
                    strtolower($item->name) => [
                        'id'   => $item->id,
                        'name' => $item->name,
                        'code' => $item->code
                    ]
                ])
                ->toArray(),

        ];
        return $data;
    }
    public function units(): array
    {
        return ['kg', 'pc', 'gms', 'ltrs'];
    }
}