public function handleRequest(SS_HTTPRequest $request, DataModel $model) { $this->pushCurrent(); $this->urlParams = $request->allParams(); $this->request = $request; $this->response = new SS_HTTPResponse(); $this->setDataModel($model); $urlsegment = $request->param('URLSegment'); $this->extend('onBeforeInit'); $this->init(); $this->extend('onAfterInit'); // First check products against URL segment if ($product = Product::get()->filter(array('URLSegment' => $urlsegment, 'Disabled' => 0))->first()) { $controller = Catalogue_Controller::create($product); } elseif ($category = ProductCategory::get()->filter('URLSegment', $urlsegment)->first()) { $controller = Catalogue_Controller::create($category); } else { // If CMS is installed if (class_exists('ModelAsController')) { $controller = ModelAsController::create(); } } $result = $controller->handleRequest($request, $model); $this->popCurrent(); return $result; }
/** * Check if this category is in the currently active section (e.g. it is * either current or one of it's children or products is currently being * viewed). * * @return bool */ public function isSection() { // First check if we are currently viewing a product $product = Catalogue_Controller::get_current_product(); if ($product->ID && $product->Categories()->exists()) { $ancestors = $product->Categories()->first()->getAncestors()->column(); $ancestors[] = $product->Categories()->first()->ID; } else { // Get a map of ancestors $ancestors = Catalogue_Controller::get_current_category()->getAncestors()->column(); if ($this->isCurrent()) { $ancestors[] = $this->ID; } } return in_array($this->ID, $ancestors) ? true : false; }