function setParent(&$obj, $val, $record)
 {
     $title = strtolower(Convert::raw2sql($val));
     if ($title) {
         if ($parentpage = DataObject::get_one('ProductGroup', "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 = new ProductGroup();
             $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');
         }
     }
 }