Finished IvtProductMatch

This commit is contained in:
Frank Schubert
2023-10-03 20:02:13 +02:00
parent dd4bf56aa3
commit 7c81125afd
8 changed files with 208 additions and 71 deletions

View File

@@ -62,7 +62,7 @@ class AdminController extends mfBaseController {
// pagination defaults
$pagination = [];
$pagination['start'] = 0;
$pagination['count'] = 20;
$pagination['count'] = 80;
$pagination['maxItems'] = 0;
if(is_numeric($this->request->s)) {
@@ -72,11 +72,54 @@ class AdminController extends mfBaseController {
$pagination['maxItems'] = IvtProductModel::count($filter);
$ivtproducts = IvtProductModel::search($filter, $pagination);
$this->layout()->set("pagination", $pagination);
$this->layout()->set("ivtproducts", $ivtproducts);
$this->layout()->set("products", ProductModel::getActive());
}
protected function saveIvtImportMatchProducts() {
$r = $this->request;
//var_dump($r);exit;
if(!is_array($r->product) || !count($r->product)) {
$this->layout()->setFlash("Nichts zu Speichern.", "info");
$this->redirect("Admin", "ivtImportMatchProducts");
}
foreach($r->product as $ivt_product_id => $product_id) {
if(!$ivt_product_id || !$product_id) continue;
// find IvtProductMatch by ivt product id ...
$match = IvtProductMatchModel::getFirst(["ivt_product_id" => $ivt_product_id]);
if(!$match) {
// ... or create it
$ivt_product = new IvtProduct($ivt_product_id);
if(!$ivt_product->id) {
$this->layout()->setFlash("Ivt Product $ivt_product_id not found.", "error");
$this->redirect("Admin", "ivtImportMatchProducts");
}
$match = IvtProductMatchModel::create([
"ivt_product_id" => $ivt_product_id,
"ivt_product_name" => $ivt_product->name
]);
}
// save product_id to IvtProductMatch
$match->product_id = $product_id;
if(!$match->save()) {
$this->layout()->setFlash("Fehler beim Speichern.", "error");
}
}
$this->layout()->setFlash("Erfolgreich gespeichert.", "success");
if(is_numeric($r->s) && $r->s) {
$this->redirect("Admin", "ivtImportMatchProducts", ["s" => $r->s]);
}
$this->redirect("Admin", "ivtImportMatchProducts");
}
protected function ivtDownloadActiveProducts() {
$ivtproducts = IvtProductModel::getAll();