Skip to content

Instantly share code, notes, and snippets.

@muskie9
Created May 11, 2015 15:22
Show Gist options
  • Save muskie9/f12e079b39fb93dac203 to your computer and use it in GitHub Desktop.
Save muskie9/f12e079b39fb93dac203 to your computer and use it in GitHub Desktop.
public function onBeforeWrite(){
if(!$this->CategoryID){
$default = ProductCategory::get()->filter(array('Code' => 'DEFAULT'))->first();
$this->CategoryID = $default->ID;
}
//update many_many lists when multi-group is on
if(SiteConfig::current_site_config()->MultiGroup){
$holders = $this->getManyManyComponents('ProductHolders');
$product = ProductPage::get()->byID($this->ID);
if (isset($product->ParentID)) {
$origParent = $product->ParentID;
} else {
$origParent = null;
}
$currentParent = $this->ParentID;
if($origParent!=$currentParent){
if($holders->find('ID', $origParent)){
$holders->removeByID($origParent);
}
}
$holders->add($currentParent);
}
$title = ltrim($this->Title);
$title = rtrim($title);
$this->Title = $title;
parent::onBeforeWrite();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment