-
-
Save stealerr/476446efdc43e00c9ca8 to your computer and use it in GitHub Desktop.
This file contains 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
<?php | |
class CategoryPage extends Page{ | |
private static $has_one = array( | |
'MainCategoryPage' => 'MainCategoryPage' | |
); | |
public function getCMSFields() { | |
$fields = parent::getCMSFields(); | |
//$fields->removeByName(array()); | |
$mains = MainCategoryPage::get()->sort('Title DESC')->map('ID', 'Title'); | |
$fields->insertBefore(DropdownField::create('MainCategoryPageID', 'Type of product', $mains), 'Title'); | |
return $fields; | |
} | |
} | |
class CategoryPage_Controller extends Page_Controller { | |
} |
This file contains 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
<?php | |
class Page_Controller extends ContentController { | |
public function addTagFilters( $filter ){ //Example URL domain.td?healthy=1&cheap=1 | |
$request = $this->getRequest(); | |
$params = $request->getVars(); | |
if(count($request->getVars()) > 1 ){ | |
unset($params['url']); //Remove url from the request, so we only have the get variables | |
$filterable_params = array(); | |
foreach($params as $key => $val){ | |
array_push($filterable_params, $key); | |
} | |
$filter['Tags.Name'] = $filterable_params; | |
} | |
return $filter; | |
} | |
public function RelatedProducts(){ | |
$zip = Session::get('ZipSort'); | |
$filter = array('Quantity:GreaterThan' => 0); | |
if($zip){ | |
$filter['Zip'] = $zip; | |
} | |
$prods = ProductPage::get(); | |
if($this instanceof MainCategoryPage_Controller || $this->ClassName == 'CategoryPage'){ | |
$filter = $this->addTagFilters($filter); | |
$prods = $prods->filter($filter)->sort('Created DESC'); | |
} | |
return $prods; | |
} | |
} |
This file contains 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
<?php | |
class Tag extends DataObject{ | |
private static $db = array( | |
'Name' => 'Varchar', | |
); | |
private static $has_one = array( | |
'MainCategoryPage' => 'MainCategoryPage' | |
); | |
private static $summary_fields = array( | |
'Name' => 'Name', | |
'MainCategoryPage.Title' => 'MainCategory' | |
); | |
public function getCMSFields() { | |
$fields = parent::getCMSFields(); | |
//$fields->removeByName(array()); | |
$fields->addFieldsToTab('Root.Main', TextField::create('Name')); | |
$mains = MainCategoryPage::get()->sort('Title DESC')->map('ID', 'Title'); | |
$fields->addFieldsToTab('Root.Main', DropdownField::create('MainCategoryPageID', 'Type of product', $mains)); | |
return $fields; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment