public function setParent(&$obj, $val, $record)
{
$title = strtolower(Convert::raw2sql($val));
if ($title) {
if ($parentpage = DataObject::get_one('ProductCategory', "LOWER(\"Title\") = '{$title}'", '"Created" DESC')) {
// find or create parent category, if provided
$obj->ParentID = $parentpage->ID;
$obj->write();
$obj->writeToStage('Stage');
$obj->publish('Stage', 'Live');
//TODO: otherwise assign it to the first prodcut group found
} elseif (self::$createnewproductgroups) {
//create parent product group
$pg = ProductCategory::create();
$pg->setTitle($title);
$pg->ParentID = self::$parentpageid ? $parentpageid : 0;
$pg->writeToStage('Stage');
$pg->publish('Stage', 'Live');
$obj->ParentID = $pg->ID;
$obj->write();
$obj->writeToStage('Stage');
$obj->publish('Stage', 'Live');
}
}
}