File: D:/HostingSpaces/SBogers10/shop.komma.nl/app/Products/Product/ProductSection.php
<?php
namespace App\Products\Product;
//The new object oriented attributes
use App\Attributes\FixedProperties;
use App\Attributes\FreeProperties;
use App\Attributes\PropertyDataCollection;
use App\Attributes\VatScenarioPrice;
use App\Properties\Kms\PropertyService;
use App\Vat\VatService;
use Dompdf\Positioner\Fixed;
use Komma\KMS\Core\Attributes\Attribute;
use Komma\KMS\Core\Attributes\MultiSelect;
use Komma\KMS\Core\Attributes\Documents;
use Komma\KMS\Core\Attributes\Models\ImageProperty;
use Komma\KMS\Core\Attributes\OnOff;
use Komma\KMS\Core\Attributes\Seperator;
use Komma\KMS\Core\Attributes\TextArea;
use Komma\KMS\Core\Attributes\TextField;
use Komma\KMS\Core\Attributes\Title;
use Komma\KMS\Core\Attributes\Video;
use Komma\KMS\Core\Attributes\View;
use Komma\KMS\Core\ModelServiceInterface;
use App\Categories\Models\Category;
use Illuminate\Database\Eloquent\Model;
use Komma\KMS\Core\Sections\Section;
use Komma\KMS\Sites\SiteServiceInterface;
class ProductSection extends Section
{
protected PropertyService $propertyService;
private ModelServiceInterface $categoryModelService;
private VatService $vatrateService;
private SiteServiceInterface $siteService;
/**
* ProductSection constructor.
* @param string $slug
*/
function __construct(string $slug)
{
$this->vatrateService = new VatService();
$this->propertyService = \App::make(PropertyService::class);
$this->categoryModelService = app(ModelServiceInterface::class);
$this->categoryModelService->setModelClassName(Category::class);
$this->siteService = app(SiteServiceInterface::class);
parent::__construct($slug);
}
/**
* Define the attributes and tabs for this section.
*
* @param Model $currentModel
*/
public function defineAttributesAndTabs(Model $currentModel = null): void
{
$categoryOptionModels = $this->categoryModelService->getOptionsForSelect();
$siteOptionModels = $this->siteService->getOptionsForSelect();
$categoriesAttribute = null;
$this->tabs->makeTab()->addItems([
(new Title())
->setLabelText(__('KMS::categories.category')),
$categoriesAttribute = (new MultiSelect())
->setItems($categoryOptionModels->toArray())
->setLabelText(__('KMS::categories.category'))
->mapValueFrom(Attribute::ValueFromModelHasManyRelation, 'categories|id'),
(new Seperator()),
(new Title())
->setLabelText(__('KMS::sites.type')),
(new MultiSelect())
->setItems($siteOptionModels->toArray())
->setLabelText(__('KMS::sites.type'))
->mapValueFrom(Attribute::ValueFromItself, 'site_id'),
(new Seperator()),
(new Title())
->setLabelText(__('KMS::products.product')),
(new OnOff())
->setLabelText(__('KMS::global.active'))
->switchOn()
->setReference( 'active'),
// (new Numeric(__('KMS::products.stock')))
// ->setWholeMin(0)
// ->setReference( 'stock'),
(new VatScenarioPrice(__('KMS::products.price')))
->setItems($this->vatrateService->getVatScenariosForSelect()->toArray())
->mapValueFrom(Attribute::ValueFromItself, 'price'),
// (new Currency(__('KMS::products.price')))
// ->setMin(0)
// ->setStep(0.01)
// ->setValidationSet($priceValidationSet)
// ->setExplanation(__('KMS::products.currency_example'))
// ->setReference( 'price'),
(new TextField())
->setLabelText(__('KMS::products.sku'))
->setPlaceholderText(__('KMS::products.sku_placeholder'))
->setPattern('[A-Za-z0-9]{4,15}')
->setExplanation(__('KMS::products.sku_example'))
->setReference( 'stock_keeping_unit'),
(new Documents())
->setImageProperties([
(new ImageProperty())->setName('thumb')->setCropMethod(ImageProperty::ResizeOnCanvas)->setWidth(100)->setHeight(100),
(new ImageProperty())->setName('small')->setCropMethod(ImageProperty::ResizeOnCanvas)->setWidth(240)->setHeight(240),
(new ImageProperty())->setName('medium')->setCropMethod(ImageProperty::ResizeOnCanvas)->setWidth(384)->setHeight(384),
(new ImageProperty())->setName('large')->setCropMethod(ImageProperty::ResizeOnCanvas)->setWidth(500)->setHeight(500)
])
->setMaxDocuments(5)
->onlyAllowImages()
->setLabelText(__('KMS::global.images'))
->setSubFolder('products')
->mapValueFrom(Attribute::ValueFromDocuments, 'documents'),
(new PropertyDataCollection($categoriesAttribute))
->mapValueFrom(Attribute::ValueFromItself, 'pdk'),
// (new Documents())
// ->setLabelText(__('kms/global.documents'))
// ->setSubFolder('products')
// ->setMaxDocuments(3)
// ->setEnablePreviewsIfPossible(true)
// ->mapValueFrom(Attribute::ValueFromDocuments, 'product_documents'),
// (new Seperator()),
// (new Title(__('KMS::discounts.quantity').' '.__('KMS::discounts.discount'))),
// (new QuantityDiscount(__('KMS::discounts.newPriceText'), __('KMS::discounts.whenAmountIsReached')))
// ->mapValueFrom(Attribute::ValueFromItself, 'quantity_discount')
]);
$languageAttributes = [];
if($currentModel) {
$languageAttributes[] = (new TextField())
->setReadOnly(true)
->setLabelText(__('KMS::global.updated_at'))
->setReference( 'updated_at');
}
$languageAttributes[] = (new Title())
->setLabelText(__('KMS::global.information'));
$languageAttributes[] = (new TextField())
->setLabelText(__('KMS::global.title'))
->setPlaceholderText(__('KMS::global.enterTitle'))
->setRules('required')
->setReference( 'name');
$languageAttributes[] = (new TextArea())
->setLabelText(__('KMS::global.metaDescription'))
->setPlaceholderText(__('KMS::global.enterMetaDescription'))
->setReference( 'meta_description');
$languageAttributes[] = (new TextArea())
->setLabelText(__('KMS::global.description'))
->setReference( 'description');
$languageAttributes[] = (new Video())
->setReference( 'video');
$languageAttributes[] = (new Documents())
->setLabelText(__('KMS::products.documents_and_manuals'))
->setMaxDocuments(5)
->setSubFolder('product_manual')
->mapValueFrom(Attribute::ValueFromDocuments, 'product_documents');
$languageAttributes[] = (new FixedProperties())
->mapValueFrom(Attribute::ValueFromItself, 'required_properties');
$languageAttributes[] = (new FreeProperties())
->mapValueFrom(Attribute::ValueFromItself, 'free_properties');
$this->tabs->makeLanguageTabTemplate()->addItems($languageAttributes);
}
}