WIP PreorderProduct 2025-02-17
This commit is contained in:
@@ -17,6 +17,98 @@ class PreorderProductController extends mfBaseController {
|
||||
protected function indexAction() {
|
||||
$this->layout()->setTemplate("PreorderProduct/Index");
|
||||
|
||||
//$product =
|
||||
$netowner_id = 4807; // $this->me->address_id;
|
||||
$netowner = new Address($netowner_id);
|
||||
|
||||
$products = PreorderProduct::getWithTypes($netowner_id);
|
||||
$this->layout()->set("products", $products);
|
||||
|
||||
$netoperators = [];
|
||||
foreach(PreordercampaignModel::search(["owner_id" => $netowner_id]) as $campaign) {
|
||||
foreach($campaign->active_operators as $op) {
|
||||
if(!array_key_exists($op->operator_id, $netoperators)) {
|
||||
$nop = new Address($op->operator_id);
|
||||
if($nop->id) {
|
||||
$netoperators[$nop->id] = $nop;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
foreach($campaign->passive_operators as $op) {
|
||||
if(!array_key_exists($op->operator_id, $netoperators)) {
|
||||
$nop = new Address($op->operator_id);
|
||||
if($nop->id) {
|
||||
$netoperators[$nop->id] = $nop;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->layout()->set("netoperators", $netoperators);
|
||||
$this->layout()->set("netowner", $netowner);
|
||||
}
|
||||
|
||||
protected function saveAction() {
|
||||
$r = $this->request;
|
||||
//var_dump($r->get());exit;
|
||||
|
||||
$netowner_id = 4807; // $this->me->address_id;
|
||||
|
||||
foreach($r->netoperators as $netoperator_id => $product_data) {
|
||||
$netoperator = new Address($netoperator_id);
|
||||
if(!$netoperator->id) {
|
||||
$this->layout()->setFlash("Betzbetreiber nicht gefunden", "error");
|
||||
$this->layout()->redirect("PreorderProduct");
|
||||
}
|
||||
foreach($product_data as $product_id => $price_data) {
|
||||
var_dump($price_data);
|
||||
$product = new PreorderProduct($product_id);
|
||||
if(!$product->id) {
|
||||
$this->layout()->setFlash("Produkt $product_id nicht gefunden", "error");
|
||||
$this->layout()->redirect("PreorderProduct");
|
||||
}
|
||||
|
||||
// create new PreorderProductPrice
|
||||
$price = PreorderProductPrice::create([
|
||||
"netowner_id" => $netowner_id,
|
||||
"preorderproduct_id" => $product->id,
|
||||
"netoperator_id" => $netoperator_id,
|
||||
]);
|
||||
if($price_data["price_setup"]) $price->price_setup = $price_data["price_setup"];
|
||||
|
||||
if(!$price_data["start_date"]) {
|
||||
$this->layout()->setFlash("Von-datum fehlt bei Produkt '".$product->name."' für '".$netoperator->getCompanyOrName()."'", "error");
|
||||
$this->redirect("PreorderProduct");
|
||||
} else {
|
||||
try {
|
||||
$start_date = new DateTime("@" . $this->dateToTimestamp($price_data["start_date"]));
|
||||
$start_date->setTimezone(new DateTimeZone("Europe/Vienna"));
|
||||
$price->start_date = $start_date->format("Y-m-d");
|
||||
} catch(Exception $e) {
|
||||
$this->layout()->setFlash("Fehler im Von-datum bei Produkt '".$product->name."' für '".$netoperator->getCompanyOrName()."'", "error");
|
||||
$this->redirect("PreorderProduct");
|
||||
}
|
||||
}
|
||||
if($price_data["end_date"]) {
|
||||
try {
|
||||
$end_date = new DateTime("@" . $this->dateToTimestamp($price_data["end_date"]));
|
||||
$end_date->setTimezone(new DateTimeZone("Europe/Vienna"));
|
||||
$price->end_date = $end_date->format("Y-m-d");
|
||||
} catch(Exception $e) {
|
||||
$this->layout()->setFlash("Fehler im Bis-Datum bei Produkt '".$product->name."' für '".$netoperator->getCompanyOrName()."'", "error");
|
||||
$this->redirect("PreorderProduct");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//var_dump($product, $price);
|
||||
|
||||
$price->save();
|
||||
}
|
||||
}
|
||||
|
||||
$this->layout()->setFlash("Neue Preise erflgreich gespeichert", "success");
|
||||
$this->redirect("PreorderProduct");
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user