Source of file ProductsPage.php
Size: 3,401 Bytes - Last Modified: 2021-12-23T10:02:45+00:00
/var/www/docs.ssmods.com/process/src/code/pages/ProductsPage.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 | <?php /** * Description of ProductsPage * * @author Magnum34 */ class ProductsPage extends Page { private static $allowed_children = array(); private static $description = "Main Page Little Shop."; private static $icon = './little-shop/images/shopping.png'; public function getCMSFields() { $fields = parent::getCMSFields(); return $fields; } } class ProductsPage_Controller extends Page_Controller { private $products; private static $allowed_actions = array( 'index', 'details' ); private static $url_handlers = array( 'search' => 'index', 'details/$URL' => 'details' ); public function getListCategories(){ $parents = ProductCategory::get()->filter(array("ParentID" => 0)); $list = array(); if($parents) { foreach ($parents as $parent) { $list[] = $parent; } } return new ArrayList($list); } public function getListKinds(){ $parents = ProductKind::get()->filter(array("ParentID" => 0)); $list = array(); if($parents) { foreach ($parents as $parent) { $list[] = $parent; } } return new ArrayList($list); } public function getListTags(){ return ProductTag::get(); } /** * Configuration Filter * **/ public function SearchArrayTo(array $requestSearch){ $list = array(); foreach($requestSearch as $key => $value){ switch($key){ case "url": break; case "category": $children = DataObject::get_one("ProductCategory","URLSegment = '$value' ")->Children()->column("URLSegment"); if(!$children){ $children = array(); } $children[] = $value; $list["Categories.URLSegment"] = $children; break; case "tag": $tag = DataObject::get_one("ProductTag","URLSegment = '$value' "); if($tag){ $list["ProductTags.URLSegment"] = $value; } break; default: break; } } $this->extend("updateSearchArrayTo",$list); return $list; } public function index(SS_HTTPRequest $request){ $searchArray = $this->SearchArrayTo($request->getVars()); if(count($searchArray) > 0){ $this->products = Product::get()->filter($searchArray); }else{ $this->products = Product::get(); } return $this; } public function details(SS_HTTPRequest $request){ $URL = $request->param('URL'); if(!$URL){ $this->httpError(404); } $product = DataObject::get_one("Product","URLSegment = '$URL' "); if($product){ $this->customise($product); }else{ $this->httpError(404); } return $this->renderWith(array('ProductPage_Details','Page')); } public function getProducts(){ } public function PaginatedList($limit = 10){ $pages = new PaginatedList($this->products, $this->getRequest()); $pages->setPageLength($limit); return $pages; } } |