public function setUp() { parent::setUp(); ProductCategory::config()->must_have_price = false; $this->products = $this->objFromFixture('ProductCategory', 'products'); $this->products->publish('Stage', 'Live'); $this->clothing = $this->objFromFixture('ProductCategory', 'clothing'); $this->clothing->publish('Stage', 'Live'); $this->electronics = $this->objFromFixture('ProductCategory', 'electronics'); $this->electronics->publish('Stage', 'Live'); $this->socks = $this->objFromFixture('Product', 'socks'); $this->socks->publish('Stage', 'Live'); $this->tshirt = $this->objFromFixture('Product', 'tshirt'); $this->tshirt->publish('Stage', 'Live'); $this->hdtv = $this->objFromFixture('Product', 'hdtv'); $this->hdtv->publish('Stage', 'Live'); $this->beachball = $this->objFromFixture('Product', 'beachball'); $this->beachball->publish('Stage', 'Live'); $this->mp3player = $this->objFromFixture('Product', 'mp3player'); $this->mp3player->publish('Stage', 'Live'); Versioned::reading_stage('Live'); }
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 = new ProductCategory(); $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'); } } }