added new capabilities in iframe
This commit is contained in:
@@ -1,31 +1,22 @@
|
||||
<?php
|
||||
// in /controllers/PreorderIFrameController.php
|
||||
|
||||
class PreorderIFrameController extends mfBaseController
|
||||
{
|
||||
|
||||
private PreorderIFrameModel $preorderIFrameModel;
|
||||
|
||||
public function init()
|
||||
{
|
||||
// The model is autoloaded or included elsewhere
|
||||
// 'X-Requested-With': 'XMLHttpRequest', 'X-Frame-Options': 'SAMEORIGIN', 'X-Frame-Referrer': document.referrer
|
||||
$this->preorderIFrameModel = new PreorderIFrameModel();
|
||||
}
|
||||
|
||||
/**
|
||||
* Serves the main order form HTML.
|
||||
* This action injects the necessary configuration into the Vue app.
|
||||
*/
|
||||
public function indexAction()
|
||||
{
|
||||
$clusterId = $this->request->get('clusterId', 'NULL');
|
||||
$color = $this->request->get('color', 'blue');
|
||||
|
||||
$vue_config = [
|
||||
'baseUrl' => '/PreorderIFrame', // URL to this controller
|
||||
'clusterId' => $clusterId !== NULL ? intval($clusterId) : null,
|
||||
'color' => htmlspecialchars($color),
|
||||
'baseUrl' => '/PreorderIFrame',
|
||||
'clusterId' => $this->request->get('clusterId') ? intval($this->request->get('clusterId')) : null,
|
||||
'gemeindeId' => $this->request->get('gemeindeId') ? intval($this->request->get('gemeindeId')) : null,
|
||||
'color' => htmlspecialchars($this->request->get('color', 'blue')),
|
||||
'orderType' => htmlspecialchars($this->request->get('orderType', 'order')), // 'order' or 'interest'
|
||||
];
|
||||
|
||||
$this->layout()->set("JSGlobals", $vue_config);
|
||||
@@ -34,7 +25,8 @@ class PreorderIFrameController extends mfBaseController
|
||||
|
||||
// --- API ENDPOINTS ---
|
||||
|
||||
public function getClustersAction() {
|
||||
public function getClustersAction()
|
||||
{
|
||||
self::returnJson(['clusters' => $this->preorderIFrameModel->getClusters($_SERVER['HTTP_X_FRAME_REFERRER'])]);
|
||||
}
|
||||
|
||||
@@ -44,8 +36,6 @@ class PreorderIFrameController extends mfBaseController
|
||||
if (!$clusterId) self::sendError("Cluster ID is required.");
|
||||
|
||||
$allClusters = $this->preorderIFrameModel->getClusters($_SERVER['HTTP_X_FRAME_REFERRER']);
|
||||
if (!$allClusters) self::sendError("No cluster found for the given ID.");
|
||||
|
||||
$clusterInfo = null;
|
||||
foreach ($allClusters as $cluster) {
|
||||
if ($cluster['id'] == $clusterId) {
|
||||
@@ -54,49 +44,59 @@ class PreorderIFrameController extends mfBaseController
|
||||
}
|
||||
}
|
||||
|
||||
$preorderCampaign = new Preordercampaign($clusterInfo['campaign_id']);
|
||||
if (!$clusterInfo) self::sendError("No cluster found for the given ID or origin.");
|
||||
|
||||
$preorderCampaign = new Preordercampaign($clusterInfo['campaign_id']);
|
||||
self::returnJson(['iframe_consents' => json_decode($preorderCampaign->iframe_consents ?? '[]')]);
|
||||
}
|
||||
|
||||
public function findCityAction()
|
||||
{
|
||||
$allowedClusters = $this->preorderIFrameModel->getClusters($_SERVER['HTTP_X_FRAME_REFERRER']);
|
||||
|
||||
$zip = $this->request->get('zip');
|
||||
$clusterId = $this->request->get('cluster_id');
|
||||
$cities = $this->preorderIFrameModel->findCities($zip, $clusterId);
|
||||
self::returnJson(['cities' => $cities]);
|
||||
$params = [
|
||||
'zip' => $this->request->get('zip'),
|
||||
'clusterId' => $this->request->get('cluster_id'),
|
||||
'gemeindeId' => $this->request->get('gemeinde_id'),
|
||||
];
|
||||
self::returnJson(['cities' => $this->preorderIFrameModel->findCities($params)]);
|
||||
}
|
||||
|
||||
public function findStreetAction()
|
||||
{
|
||||
// $this->checkOriginAndGetCampaign(); // Security check
|
||||
$zip = $this->request->get('zip');
|
||||
$city = $this->request->get('city');
|
||||
$clusterId = $this->request->get('cluster_id');
|
||||
$streets = $this->preorderIFrameModel->findStreets($zip, $city, $clusterId);
|
||||
self::returnJson(['streets' => $streets]);
|
||||
$params = [
|
||||
'zip' => $this->request->get('zip'),
|
||||
'city' => $this->request->get('city'),
|
||||
'clusterId' => $this->request->get('cluster_id'),
|
||||
'gemeindeId' => $this->request->get('gemeinde_id'),
|
||||
];
|
||||
self::returnJson(['streets' => $this->preorderIFrameModel->findStreets($params)]);
|
||||
}
|
||||
|
||||
public function findAddressAction()
|
||||
{
|
||||
$addresses = $this->preorderIFrameModel->findAddresses($_GET);
|
||||
self::returnJson(['addresses' => $addresses]);
|
||||
self::returnJson(['addresses' => $this->preorderIFrameModel->findAddresses($_GET)]);
|
||||
}
|
||||
|
||||
public function submitOrderAction()
|
||||
{
|
||||
$requestBody = file_get_contents('php://input');
|
||||
$preorderData = json_decode($requestBody, true);
|
||||
|
||||
$preorderData = json_decode(file_get_contents('php://input'), true);
|
||||
if (json_last_error() !== JSON_ERROR_NONE) self::sendError("Invalid JSON data.");
|
||||
|
||||
$tt_network = NetworkModel::getFirst(['adb_network_id' => $preorderData['additionalData']['clusterId']]);
|
||||
if (!$tt_network) self::sendError("No network found for the given cluster ID.");
|
||||
// Determine network/campaign from clusterId or gemeindeId
|
||||
$networkId = null;
|
||||
if (!empty($preorderData['additionalData']['clusterId'])) {
|
||||
$tt_network = NetworkModel::getFirst(['adb_network_id' => $preorderData['additionalData']['clusterId']]);
|
||||
if ($tt_network) $networkId = $tt_network->id;
|
||||
} elseif (!empty($preorderData['additionalData']['gemeindeId'])) {
|
||||
$gn = GemeindeNetzgebietModel::getFirst(['gemeinde_id' => $preorderData['additionalData']['gemeindeId']]);
|
||||
if ($gn) {
|
||||
$tt_network = NetworkModel::getFirst(['adb_netzgebiet_id' => $gn->netzgebiet_id]);
|
||||
if ($tt_network) $networkId = $tt_network->id;
|
||||
}
|
||||
}
|
||||
|
||||
$campaign = PreordercampaignModel::getFirst(['network_id' => $tt_network->id]);
|
||||
if (!$campaign) self::sendError("No campaign found for the given cluster ID.");
|
||||
if (!$networkId) self::sendError("No network/campaign found for the given area.");
|
||||
$campaign = PreordercampaignModel::getFirst(['network_id' => $networkId]);
|
||||
if (!$campaign) self::sendError("No campaign found for the given area.");
|
||||
|
||||
$h = new ADBHausnummer($preorderData['address']['hausnummer_id']);
|
||||
if (!$h->id) self::sendError("Invalid house number ID provided.");
|
||||
@@ -109,7 +109,6 @@ class PreorderIFrameController extends mfBaseController
|
||||
$data['adb_hausnummer_id'] = $preorderData['address']['hausnummer_id'];
|
||||
$data['adb_wohneinheit_id'] = $preorderData['address']['wohneinheit_id'];
|
||||
|
||||
|
||||
$new_status = null;
|
||||
if ($data['adb_wohneinheit_id'] && $w->id) {
|
||||
$status_code = max($w->status->code, $w->hausnummer->status->code);
|
||||
@@ -119,7 +118,7 @@ class PreorderIFrameController extends mfBaseController
|
||||
}
|
||||
$data["status_id"] = $new_status ? $new_status->id : 1;
|
||||
|
||||
$data['type'] = $preorderData['connectionType'] === 'vorsorge' ? 'provision' : 'order';
|
||||
$data['type'] = $preorderData['preorderType'] ?? 'order'; // 'order', 'interest', 'provision'
|
||||
$data['connection_type'] = $preorderData['customerType'] === 'business' ? 'business' : 'single-dwelling';
|
||||
|
||||
$data['accept_agb'] = $preorderData['acceptAgb'] ? 1 : 0;
|
||||
@@ -137,17 +136,12 @@ class PreorderIFrameController extends mfBaseController
|
||||
$data['city'] = (trim($preorderData['customer']['city'])) ?: null;
|
||||
$data['phone'] = (trim($preorderData['customer']['phone'])) ?: null;
|
||||
$data['email'] = (trim($preorderData['customer']['email'])) ?: null;
|
||||
|
||||
$data['edit_by'] = 1;
|
||||
$data['create_by'] = 1;
|
||||
|
||||
$preorder = PreorderModel::create($data);
|
||||
$preorder->createUcode();
|
||||
$new_id = $preorder->save();
|
||||
|
||||
if (!$new_id) {
|
||||
self::sendError("Failed to create preorder record.");
|
||||
}
|
||||
if (!$preorder->save()) self::sendError("Failed to create preorder record.");
|
||||
|
||||
self::returnJson(['orderCode' => $preorder->ucode, 'status' => 'success']);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user