Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/job-board.corals.io/Corals/modules/Ecommerce/Http/Requests/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/job-board.corals.io/Corals/modules/Ecommerce/Http/Requests/SKUBulkRequest.php
<?php

namespace Corals\Modules\Ecommerce\Http\Requests;

use Corals\Foundation\Http\Requests\BaseRequest;
use Corals\Modules\Ecommerce\Models\SKU;

class SKUBulkRequest extends BaseRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        $this->setModel(SKU::class, 'sku');

        return $this->isAuthorized();
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $this->setModel(SKU::class, 'sku');

        $rules = parent::rules();

        $product = request()->route('product');

        if ($this->isStore()) {
            $rules = array_merge($rules, [
                'generate_option' => 'required',
            ]);

            foreach ($product->variation_options ?? [] as $option) {
                if ($option->required) {
                    $rules = array_merge($rules, [
                        "options." . $option->id => 'required',
                    ]);
                }
            }
        }

        if ($this->isUpdate()) {
            foreach ($this->get('sku', []) ?? [] as $id => $sku) {
                $rules = array_merge($rules, [
                    "sku.$id.code" => 'required|unique:ecommerce_sku,code,' . $id
                ]);
            }

            if ($this->get('generate_option') === 'apply_unique') {
                $rules = array_merge($rules, [
                    'sku.*.status' => 'required',
                    'sku.*.regular_price' => 'required',
                    'sku.*.image' => 'mimes:jpg,jpeg,png|max:' . maxUploadFileSize(),
                    'sku.*.inventory' => 'required',
                    'sku.*.inventory_value' => 'required_if:sku.*.inventory,finite,bucket',
                ]);

                if ($product->shipping['enabled']) {
                    $rules = array_merge($rules, [
                        "sku.*.shipping.height" => 'required',
                        "sku.*.shipping.weight" => 'required',
                        "sku.*.shipping.width" => 'required',
                        "sku.*.shipping.length" => 'required',
                    ]);
                }
            } else {
                $rules = array_merge($rules, [
                    'status' => 'required',
                    'regular_price' => 'required',
                    'image' => 'mimes:jpg,jpeg,png|max:' . maxUploadFileSize(),
                    'inventory' => 'required',
                    'inventory_value' => 'required_if:inventory,finite,bucket',
                ]);
            }
        }

        return $rules;
    }

    public function attributes()
    {
        $attributes = [];
        $product = request()->route('product');

        foreach ($product->variation_options ?? [] as $option) {
            $attributes = array_merge($attributes, [
                "options.$option->id" => $option->label,
            ]);
        }

        $attributes = array_merge($attributes, [
            'sku.*.status' => __('Corals::attributes.status'),
            'status' => __('Corals::attributes.status'),

            'sku.*.regular_price' => __('Ecommerce::attributes.sku.regular_price'),
            'regular_price' => __('Ecommerce::attributes.sku.regular_price'),

            'sku.*.image' => __('Ecommerce::attributes.sku.image'),
            'image' => __('Ecommerce::attributes.sku.image'),

            'sku.*.inventory' => __('Ecommerce::attributes.sku.inventory'),
            'inventory' => __('Ecommerce::attributes.sku.inventory'),

            'sku.*.inventory_value' => __('Ecommerce::attributes.sku.inventory_value'),
            'inventory_value' => __('Ecommerce::attributes.sku.inventory_value'),

            "sku.*.shipping.height" => __('Ecommerce::attributes.sku.height'),
            "sku.*.shipping.weight" => __('Ecommerce::attributes.sku.weight'),
            "sku.*.shipping.width" => __('Ecommerce::attributes.sku.width'),
            "sku.*.shipping.length" => __('Ecommerce::attributes.sku.length'),
        ]);

        foreach ($this->get('sku', []) ?? [] as $id => $sku) {
            $attributes = array_merge($attributes, [
                "sku.$id.code" => __('Ecommerce::attributes.sku.code_sku')
            ]);
        }

        return $attributes;
    }
}

Spamworldpro Mini