Created
May 11, 2015 15:22
-
-
Save muskie9/f12e079b39fb93dac203 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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