File: D:/HostingSpaces/farmfun/reserveren.farmfun.be/app/Komma/Shop/Shipments/ShipmentSection.php
<?php
/**
* @author Komma <info@komma.pro>
* @copyright (c) 2012-2016, Komma
*/
namespace App\Komma\Shop\Shipments;
//The new object oriented attributes
use App\Komma\Globalization\RegionInfoInterface;
use App\Komma\Kms\Core\Attributes\Attribute;
use App\Komma\Kms\Core\Attributes\Link;
use App\Komma\Kms\Core\Attributes\Models\SelectOption;
use App\Komma\Kms\Core\Attributes\Select;
use App\Komma\Kms\Core\Attributes\TextArea;
use App\Komma\Kms\Core\Attributes\TextField;
use App\Komma\Kms\Core\Sections\Section;
use App\Komma\Kms\Core\Sections\Tabs\Collections\NoLanguageTabs;
use App\Komma\Routes\RouteService;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
class ShipmentSection extends Section
{
protected $slug = 'shipments';
public $showSave = 'all';
public $showDelete = [1];
public $showCreate = [1];
/** @var RegionInfoInterface */
private $regionInfo;
/** @var RouteService */
private $routeService;
/**
* ProductSection constructor.
*
* @param $slug
*/
// function __construct(Kms $kms, PageRepository $repository)
public function __construct($slug)
{
$tabs = new NoLanguageTabs();
$this->routeService = app(RouteService::class);
parent::__construct($tabs, $this->slug);
$this->regionInfo = app(RegionInfoInterface::class);
}
/**
* Generates the attributes for this section. They all must extend the App\Komma\Kms\Core\Attributes\Attribute class
* This is the place where you need to setup your sections appearance. Just make sure you build an array of attributes
* and put each attribute in a AbstractSectionTabItem with a SectionTabGroups constant to link them to a tab.
*
* @param Model $currentModel
* @return Collection A collection of SectionTabItems
* @see PageRepository::saveModel()
*/
protected function generateAttributes(Model $currentModel = null): Collection
{
//*****************************************************************************************\\
//*** Define attribute validation sets ***\\
//*****************************************************************************************\\
//*****************************************************************************************\\
//*** Determine and define status dropdown data ***\\
//*****************************************************************************************\\
$statusOptions = [];
foreach (ShipmentStatus::getAsArray() as $shipmentStatus) {
$statusOptions[] = (new SelectOption())->setContent(__('shop/shipments.status.'.$shipmentStatus))->setHtmlContent(__('shop/shipments.status.'.$shipmentStatus))->setValue($shipmentStatus);
}
//*****************************************************************************************\\
//*** Generate the attributes ***\\
//*****************************************************************************************\\
$attributes = [];
$attributes[] = (new Select())
->setItems($statusOptions)
->setLabelText(__('shop/shipments.status_name'))
->mapValueFrom(Attribute::ValueFromModel, 'status');
$attributes[] = (new Link(__('shop/orders.order'), 'order'))
->setLink(route('orders.show', ['order' => $currentModel->order]))
->setLinkText($currentModel->order->order_number.' ('.$currentModel->order->customer->first_name.' '.$currentModel->order->customer->last_name.')');
if ($currentModel->shipmentGroup) {
$attributes[] = (new Link(__('shop/shipmentgroups.shipmentGroup'), 'shipment_group'))
->setLink(route('shipmentgroups.show', ['shipmentgroups' => $currentModel->shipmentGroup]))
->setLinkText($currentModel->shipmentGroup->id.' ('.$currentModel->shipmentGroup->created_at.')');
} else {
$attributes[] = (new TextField(__('shop/shipmentgroups.shipmentGroup')))
->setValue(__('shop/shipmentgroups.no_shipmentGroup'))
->setReadOnly(true)
->mapValueFrom(Attribute::ValueFromItself, 'no_shipping_group_textfield');
}
$attributes[] = (new TextField(__('shop/shipments.tracking_code')))
->mapValueFrom(Attribute::ValueFromModel, 'tracking_code');
$attributes[] = (new TextArea())
->setLabelText(__('shop/shipments.comment'))
->mapValueFrom(Attribute::ValueFromModel, 'comment');
//Return all attributes as a collection
return collect(array_merge($attributes));
}
}