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);
}
}