Attributes can be set in products now

This commit is contained in:
Frank Schubert
2021-07-06 14:56:57 +02:00
parent 002c2565eb
commit ad4ab58332
16 changed files with 893 additions and 14 deletions

View File

@@ -5,6 +5,36 @@ class Product extends mfBaseModel {
private $producttech;
private $sla;
private $networks;
private $attributes;
public function loadAttributes() {
if(!$this->producttech_id) {
return false;
}
$this->attributes = [];
// get tech attribs
$ptattribs = ProducttechAttributeModel::search(['producttech_id' => $this->producttech_id]);
// fill atrribs with existing values of product attribs
foreach($ptattribs as $pta) {
$attrib = ProductAttributeModel::getFirst(['product_id' => $this->id, 'producttechattribute_id' => $pta->id]);
if(!$attrib) {
$attrib = new ProductAttribute();
$attrib->product_id = $this->id;
$attrib->producttechattribute_id = $pta->id;
$attrib->value = $pta->value;
$attrib->note = $pta->note;
}
$attrib->name = $pta->name;
$attrib->displayname = $pta->displayname;
$attrib->description = $pta->description;
$this->attributes[$attrib->name] = $attrib;
}
return true;
}
public function getProperty($name) {
if($this->$name == null) {
@@ -18,7 +48,10 @@ class Product extends mfBaseModel {
return $this->networks;
}
if($name == "attributes") {
$this->loadAttributes();
return $this->attributes;
}
$classname = ucfirst($name);
$idfield = $name."_id";