HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/shop.komma.nl/app/ShippingCosts/ShippingCostSection.php
<?php
namespace App\ShippingCosts;

//The new object oriented attributes
use App\Attributes\VatScenarioPrice;
use App\Vat\VatService;
use Komma\KMS\Core\Attributes\Attribute;
use Komma\KMS\Core\Attributes\OnOff;
use Komma\KMS\Core\Attributes\Select;
use Komma\KMS\Core\Attributes\TextField;
use Komma\KMS\Core\Attributes\Title;
use Komma\KMS\Core\Sections\Section;
use Illuminate\Database\Eloquent\Model;

class ShippingCostSection extends Section
{
    public function defineAttributesAndTabs(Model $currentModel = null): void
    {
        $vatService = new VatService();

        /** @var ShippingCostsService $shippingCostService */
        $shippingCostService = app(ShippingCostsService::class);

        //Build the general attributes and put them in the attributes array
        if($currentModel) {
            $attributes[] = (new TextField())
                ->setLabelText(__("KMS::global.updated_at"))
                ->setReadOnly(true)
                ->setReference( 'updated_at');
        }

        //Category selection
        $attributes[] = (new Title())
            ->setLabelText(__('KMS::shipping_costs.type'));

        $attributes[] = $defaultOnOff = (new OnOff())
            ->setLabelText(__('KMS::shipping_costs.default'))
            ->setExplanation(__('KMS::shipping_costs.default_explanation'))
            ->setReference( 'is_default');

        if($currentModel && $currentModel->exists) $defaultOnOff->setMessages(['MinimumDefaultShippingCostsCount' => __('KMS::shipping_costs.validation')]);

        $attributes[] = (new Select())
        ->setLabelText(__('KMS::company.country'))
        ->setItems(
            $shippingCostService->getCountryOptionsForSelect()->toArray()
        )->setReference( 'code');

        $attributes[] = (new VatScenarioPrice(__('KMS::shipping_costs.type')))
            ->setItems($vatService->getVatScenariosForSelect()->toArray())
            ->mapValueFrom(Attribute::ValueFromItself, 'price');

        $this->tabs->makeTab()->addItems($attributes);
    }
}