File: D:/HostingSpaces/blijegasten/blijegasten.be/app/Komma/Shop/ShippingCosts/ShippingCostSection.php
<?php
/**
*
*
* @author Komma <info@komma.pro>
* @copyright (c) 2012-2016, Komma
*/
namespace App\Komma\Shop\ShippingCosts;
//The new object oriented attributes
use App\Komma\Kms\Core\Attributes\Attribute;
use App\Komma\Kms\Core\Attributes\Currency;
use App\Komma\Kms\Core\Attributes\OnOff;
use App\Komma\Kms\Core\Attributes\Select;
use App\Komma\Kms\Core\Attributes\Title;
use App\Komma\Kms\Core\Sections\Section;
use App\Komma\Kms\Core\Sections\Tabs\Collections\NoLanguageTabs;
use App\Komma\Kms\Core\ValidationSet;
use App\Komma\Shop\Categories\Kms\CategoryModelService;
use App\Komma\Shop\Properties\Kms\PropertyService;
use App\Komma\Shop\ShippingCosts\Rules\MinimumDefaultShippingCostsCount;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
class ShippingCostSection extends Section
{
protected $title = "Shipping costs";
protected $subtitle = "All Shipping costs";
protected $slug = "shippingcosts";
/** @var CategoryModelService $categoryService */
protected $categoryService;
/** @var PropertyService $propertyService */
protected $propertyService;
/** @var ShippingCostsService */
protected $sectionService;
/**
* ShippingCostsection constructor.
*/
// function __construct(Kms $kms, PageRepository $repository)
function __construct()
{
$this->title = ucfirst(__("shop/shippingcosts.type"));
$tabs = new NoLanguageTabs();
parent::__construct($tabs, $this->slug);
}
/**
* Generates the attributes for this section. They all must extend the App\Komma\Kms\Core\Attributes\Attribute class
*
* @param Model $currentModel
* @return Collection A collection of SectionTabItems
*/
protected function generateAttributes(Model $currentModel = null): Collection
{
/** @var ShippingCostsService $shippingCostService */
$shippingCostService = app(ShippingCostsService::class);
//*****************************************************************************************\\
//*** Define attribute validation sets ***\\
//*****************************************************************************************\\
$nameValidationSet = (new ValidationSet())
->setRules('required')
->setMessages(['required' => __('validation.required')]);
$priceValidationSet = (new ValidationSet())
->setRules('required|min:0')
->setMessages([
'required' => __('validation.required'),
'min' => __('validation.min.numeric')
]);
$defaultvalidationSet = (new ValidationSet())
->setRules([new MinimumDefaultShippingCostsCount()])
->setMessages(['MinimumDefaultShippingCostsCount' => __('shop/shippingcosts.validation')]);
//*****************************************************************************************\\
//*** Generate the attributes ***\\
//*****************************************************************************************\\
$attributes = [];
//Category selection
$attributes[] = (new Title(__('shop/shippingcosts.type')));
/** @var OnOff $defaultOnOff */
$attributes[] = $defaultOnOff = (new OnOff())
->setLabelText(__('shop/shippingcosts.default'))
->setExplanation(__('shop/shippingcosts.default_explanation'))
->mapValueFrom(Attribute::ValueFromModel, 'is_default');
if($currentModel && $currentModel->exists) $defaultOnOff->setValidationSet($defaultvalidationSet);
$attributes[] = (new Select())
->setLabelText(__('company.country'))
->setItems(
$shippingCostService->getCountryOptionsForSelect()->toArray()
)->mapValueFrom(Attribute::ValueFromModel, 'code');
$attributes[] = (new Currency(__('shop/shippingcosts.type')))
->setMin(0)
->setStep(0.01)
->setValidationSet($priceValidationSet)
->mapValueFrom(Attribute::ValueFromModel, 'cost');
//Return all attributes as a collection
return collect(array_merge($attributes));
}
/**
* This method will stop the load entities of the kmsSiteSection
*
* @return array
*
*/
public function loadEntities(){
return [];
}
}