File: D:/HostingSpaces/SBogers10/komma.pro/app/KommaApp/Shop/Orders/Kms/OrderSection.php
<?php
/**
*
*
* @author Komma <info@komma.pro>
* @copyright (c) 2012-2016, Komma
*/
namespace App\KommaApp\Shop\Orders\Kms;
//The new object oriented attributes
use App\KommaApp\Kms\Core\Attributes\Attribute;
use App\KommaApp\Kms\Core\Attributes\Models\SelectOption;
use App\KommaApp\Kms\Core\Attributes\Select;
use App\KommaApp\Kms\Core\Attributes\TextField;
use App\KommaApp\Kms\Core\Attributes\View;
use App\KommaApp\Kms\Core\Sections\NoLanguageTabsDirector;
use App\KommaApp\Kms\Core\Sections\Section;
use App\KommaApp\Routes\RouteService;
use App\KommaApp\Kms\Core\Attributes\Title;
use App\KommaApp\Kms\Core\Kms;
use App\KommaApp\Kms\Core\Sections\SectionTabGroups;
use App\KommaApp\Kms\Core\Sections\SectionTabItem;
use App\KommaApp\Kms\Core\Sections\SectionTabsBuilder;
use App\KommaApp\Kms\Core\ValidationSet;
use App\KommaApp\Shop\Orders\Models\Order;
use App\KommaApp\Shop\Orders\Product\OrderedProduct;
use App\KommaApp\Shop\Orders\ProductComposite\OrderedProductComposite;
use App\KommaApp\Shop\Orders\ProductGroup\OrderedProductGroup;
use App\KommaApp\Shop\Products\Product\Product;
use App\KommaApp\Shop\Products\Product\ProductService;
use App\KommaApp\Shop\Products\ProductComposite\ProductComposite;
use App\KommaApp\Shop\Products\ProductComposite\ProductCompositeService;
use App\KommaApp\Shop\Products\ProductGroup\ProductGroupService;
use function foo\func;
use Illuminate\Database\Eloquent\Collection;
class OrderSection extends Section
{
protected $title = "Orders";
protected $subTitle = "All product orders";
protected $slug = "orders";
protected $hasRoutes = true;
public $showSave = 'all';
public $showDelete = [1];
public $showCreate = [1];
/**
* OrderSection constructor.
* @param Kms $kms
* @param OrderServiceInterface $sectionService
* @param RouteService $routeService
*/
// function __construct(Kms $kms, PageRepository $repository)
function __construct(OrderServiceInterface $sectionService, RouteService $routeService)
{
$this->title = ucfirst(__('shop/orders.orders'));
$this->subTitle = __('shop/orders.all_orders');
$sectionTabDirector = new NoLanguageTabsDirector(new SectionTabsBuilder()); //Can make tabs for us. also see KmsSection::__construct
parent::__construct($sectionService, $routeService, $sectionTabDirector);
}
/**
* Generates the attributes for this section. They all must extend the App\KommaApp\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.
*
* @see PageRepository::saveModel()
* @return Collection A collection of SectionTabItems
*/
protected function generateAttributes(): Collection
{
// \Log::info("PageSection::Generating attributes");
//*****************************************************************************************\\
//*** Define attribute validation sets ***\\
//*****************************************************************************************\\
//*****************************************************************************************\\
//*** Generate the attributes ***\\
//*****************************************************************************************\\
$attributes = [];
/** @var Order $order */
$order = $this->getModel();
$orderedProducts = $order->orderedProducts()->get();
$orderedProductGroups = $order->orderedProductGroups()->with('orderedProducts')->get();
$orderedProductComposites = $order->orderedProductComposites()->with('orderedGroups.orderedProducts')->get();
$viewData = [
'products' => $orderedProducts,
'product_groups' => $orderedProductGroups,
'product_composites' => $orderedProductComposites,
];
//Build the general attributes and put them in the attributes array
$attributes[] = (new Title(__('shop/orders.status_info')));
$attributes[] = (new Select())
->setItems($this->getOrderStatusItems())
->setLabelText(__('shop/orders.status_name'))
->mapValueFrom(Attribute::ValueFromModel, 'status');
$attributes[] = (new Title(__('shop/orders.customer_info')));
$attributes[] = (new TextField(__('shop/orders.order_number')))
->setReadOnly(true)
->mapValueFrom(Attribute::ValueFromModel, 'id');
$attributes[] = (new TextField(__('kms/users.email')))
->setReadOnly(true)
->mapValueFrom(Attribute::ValueFromModel, 'invoice_email');
$attributes[] = (new TextField(__('shop/orders.invoice_address')))
->setReadOnly(true)
->mapValueFrom(Attribute::ValueFromItself, 'invoice_data');
$attributes[] = (new TextField(__('shop/orders.shipping_address')))
->setReadOnly(true)
->mapValueFrom(Attribute::ValueFromItself, 'shipping_data');
$attributes[] = (new Title(__('shop/orders.order')));
$attributes[] = (new View('shop.partials.orders.overview'))
->setViewData($viewData);
//Build an array with attributes for each current site language
$languageIndexedAttributes = $this->createAttributesFromExistingAttributeForAllUsedLanguagesBySites([
]);
//****************************************************************************************************************************************\\
//*** Put the all attributes in a SectionTabItem so we can track for which tab they are. And then put SectionTabItems in a Collection ***\\
//****************************************************************************************************************************************\\
$tabItems = new Collection();
foreach($attributes as $attribute) $tabItems->push(new SectionTabItem($attribute, SectionTabGroups::General));
return $tabItems;
}
public function getOrderStatusItems()
{
$items = [];
foreach(__('shop/orders.status') as $value => $translation)
{
$items[] = (new SelectOption())
->setValue($value)
->setContent($translation)
->setHtmlContent($translation);
}
return $items;
}
/**
* This method will stop the load entities of the kmsSiteSection
*
* @return array
*
*/
public function loadEntities(){
return [];
}
}