fixed bug in eShop

This commit is contained in:
Luca Haid
2025-07-21 13:07:44 +02:00
parent d1ce237a97
commit a5e41fc579

View File

@@ -4,70 +4,57 @@ class WarehouseEShopController extends TTCrud {
protected string $headerTitle = 'Energie Steiermark Shop';
protected bool $createText = false;
//@formatter:off
protected array $columns = [
['key' => 'title', 'text' => 'Artikel', 'priority' => 11],
['key' => 'category', 'text' => 'Kategorie', 'table' => false],
['key' => 'price', 'text' => 'Preis', 'table' => ['filter' => false, 'sortable' => false, 'class' => 'text-right']],
['key' => 'price', 'text' => 'Preis', 'table' => false],
['key' => 'amount', 'text' => 'Menge', 'table' => ['filter' => false, 'sortable' => false, 'class' => 'p-0 width-80'], 'priority' => 9],
['key' => 'add', 'text' => 'Hinzufügen', 'table' => ['filter' => false, 'sortable' => false, 'class' => 'width-120 text-center'], 'priority' => 5000]
];
//@formatter:on
protected array $permissionCheck = ['WarehouseEShop'];
protected array $additionalJSVariables = [];
protected function afterInit() {
if ($this->user->isAdmin()) {
if (isset($_GET['shop']) && in_array($_GET['shop'], ['e', 'sbidi'])) {
if (!$this->user->isAdmin()) return;
if (!$this->user->getFlag('WarehouseSelectedShop') && !isset($_GET['shop'])) self::sendError("Bitte wählen Sie einen Shop aus.");
if (in_array($_GET['shop'], ['e', 'sbidi'])) {
$flag = new WorkerFlag($this->user->id, 'WarehouseSelectedShop');
$flag->value($_GET['shop']);
$flag->save();
$this->user->address_id = ($_GET['shop'] === 'e') ? '209' : '9633';
} elseif (!$this->user->getFlag('WarehouseSelectedShop')) self::sendError("Bitte wählen Sie einen Shop aus.");
} else {
$selectedShop = $this->user->getFlag('WarehouseSelectedShop')->value();
if ($selectedShop) $this->user->address_id = ($selectedShop === 'e') ? '209' : '9633';
return;
}
$this->user->address_id = ($this->user->getFlag('WarehouseSelectedShop')->value() === 'e') ? '209' : '9633';
}
protected function prepareCrudConfig() {
if (!$this->user->can('WarehouseAdmin')) $this->columns[2]['table'] = false;
if (!in_array(intval($this->user->address_id), [209, 9633])) self::sendError("Keine Berechtigung für diesen Shop");
$this->additionalJSVariables['userAddressId'] = $this->user->address_id ?? null;
if ($this->user->address_id == 209) $this->headerTitle = 'Energie Steiermark Shop';
elseif ($this->user->address_id == 9633) $this->headerTitle = 'SBIDI Shop';
else self::sendError("Keine Berechtigung für diesen Shop");
$this->headerTitle = $this->user->address_id == 209 ? 'Energie Steiermark Shop' : 'SBIDI Shop';
}
public function getAction() {
if (!in_array(intval($this->user->address_id), [209, 9633])) self::sendError("Keine Berechtigung für diesen Shop");
$filter = $this->postData['filters'] ?? [];
$order = $this->postData['order'] ?? ['key' => null, 'order' => 'ASC'];
$page = $this->postData['pagination']['page'] ?? 1;
$perPage = $this->postData['pagination']['per_page'] ?? 10;
$warehouseArticleFilter = $filter;
$warehousePacketFilter = $filter;
$shopType = (intval($this->user->address_id) === 209) ? 'EShop' : 'SbidiShop';
$filter["is{$shopType}"] = 1;
$filter["is{$shopType}Hide"] = 0;
if (!in_array(intval($this->user->address_id), [209, 9633])) self::sendError("Keine Berechtigung für diesen Shop");
$warehouseArticles = WarehouseArticleModel::getAll($filter, null, 0, $order);
$warehousePackets = WarehouseArticlePacketModel::getAll($filter, null, 0, $order);
$shopType = (intval($this->user->address_id) === 209) ? 'eShop' : 'sbidiShop';
$this->headerTitle = (intval($this->user->address_id) === 209) ? 'Energie Steiermark Shop' : 'SBIDI Shop';
$filteredAvailable = WarehouseArticlePacketModel::count($filter) + WarehouseArticleModel::count($filter);
$warehouseArticleFilter["is{$shopType}"] = 1;
$warehouseArticleFilter["is{$shopType}Hide"] = 0;
$warehousePacketFilter["is{$shopType}"] = 1;
$warehousePacketFilter["is{$shopType}Hide"] = 0;
$warehouseArticles = WarehouseArticleModel::getAll($warehouseArticleFilter, null, 0, $order);
$warehouseArticlesTotal = WarehouseArticleModel::count($warehouseArticleFilter);
$warehouseArticlesAvailable = WarehouseArticleModel::count($warehouseArticleFilter);
$warehousePackets = WarehouseArticlePacketModel::getAll($warehousePacketFilter, null, 0, $order);
$warehousePacketsTotal = WarehouseArticlePacketModel::count($warehousePacketFilter);
$warehousePacketsAvailable = WarehouseArticlePacketModel::count($warehousePacketFilter);
$filteredAvailable = $warehouseArticlesAvailable + $warehousePacketsAvailable;
$totalRows = $warehouseArticlesTotal + $warehousePacketsTotal;
$rows = [...$warehouseArticles, ...$warehousePackets];
usort($rows, function($a, $b) { return strcmp($a->title, $b->title); });
@@ -79,7 +66,7 @@ class WarehouseEShopController extends TTCrud {
"total_pages" => ceil($filteredAvailable / $perPage),
"per_page" => $perPage,
"filtered_available" => $filteredAvailable,
"total_rows" => $totalRows
"total_rows" => $filteredAvailable
]
]);
}