Added IVT product export Admin function

This commit is contained in:
Frank Schubert
2023-05-05 15:08:41 +02:00
parent 93727c3bf9
commit ed4c6ad738
7 changed files with 388 additions and 0 deletions

View File

@@ -77,4 +77,33 @@ class AdminController extends mfBaseController {
$this->layout()->set("products", ProductModel::getActive());
}
protected function ivtDownloadActiveProducts() {
$ivtproducts = IvtProductModel::getAll();
$products = [];
foreach($ivtproducts as $product) {
$active_count = IvtCustomerProductModel::count(['pid' => $product->id]);
if(!$active_count) continue;
$new_product = [];
$new_product["product"] = $product;
$new_product["count"] = $active_count;
$new_product["customer"] = false;
if($active_count == 1) {
$cp = IvtCustomerProductModel::getFirst(["pid" => $product->id]);
//var_dump($cp);exit;
$customer = $cp->customer;
//var_dump($customer);exit;
$new_product["customer"] = ($customer->company) ? $customer->company : $customer->firstname." ".$customer->surname;
}
$products[$product->id] = $new_product;
}
$this->layout()->setTemplate("Admin/ivt_active_products.csv");
$this->layout()->set("products", $products);
}
}