|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Dynamic\ProductCatalog\Page; |
|
4
|
|
|
|
|
5
|
|
|
use Dynamic\ProductCatalog\ORM\CatalogProduct; |
|
6
|
|
|
use SilverStripe\Control\HTTPRequest; |
|
7
|
|
|
|
|
8
|
|
|
class CatalogCategoryController extends \PageController |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* @var array |
|
12
|
|
|
*/ |
|
13
|
|
|
private static $allowed_actions = array( |
|
|
|
|
|
|
14
|
|
|
'view', |
|
15
|
|
|
); |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var |
|
19
|
|
|
*/ |
|
20
|
|
|
private $product; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @param HTTPRequest|null $request |
|
24
|
|
|
* |
|
25
|
|
|
* @return mixed |
|
26
|
|
|
*/ |
|
27
|
|
|
public function getProduct(HTTPRequest $request = null) |
|
28
|
|
|
{ |
|
29
|
|
|
if (!$this->product) { |
|
30
|
|
|
$this->setProduct($this->getProductFromRequest($request)); |
|
|
|
|
|
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
return $this->product; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @param null $request |
|
|
|
|
|
|
38
|
|
|
* |
|
39
|
|
|
* @return bool|\SilverStripe\ORM\DataObject |
|
40
|
|
|
*/ |
|
41
|
|
|
public function getProductFromRequest($request = null) |
|
42
|
|
|
{ |
|
43
|
|
|
if (!$request) { |
|
|
|
|
|
|
44
|
|
|
$request = $this->getRequest(); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
$productID = $request->param('ID'); |
|
48
|
|
|
if ($productID) { |
|
49
|
|
|
$product = CatalogProduct::get()->filter('URLSegment', $productID)->first(); |
|
50
|
|
|
|
|
51
|
|
|
return $product; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
return false; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @param $product |
|
59
|
|
|
* |
|
60
|
|
|
* @return $this |
|
61
|
|
|
*/ |
|
62
|
|
|
public function setProduct($product) |
|
63
|
|
|
{ |
|
64
|
|
|
$this->product = $product; |
|
65
|
|
|
|
|
66
|
|
|
return $this; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @param HTTPRequest $request |
|
71
|
|
|
* |
|
72
|
|
|
* @return \SilverStripe\ORM\FieldType\DBHTMLText |
|
73
|
|
|
*/ |
|
74
|
|
|
public function view(HTTPRequest $request) |
|
|
|
|
|
|
75
|
|
|
{ |
|
76
|
|
|
$product = $this->getProduct(); |
|
77
|
|
|
if (!$product) { |
|
78
|
|
|
return $this->httpError(404, 'The product you\'re looking for isn\'t available.'); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
return $this->customise(array( |
|
82
|
|
|
'Title' => $product->getTitle(), |
|
83
|
|
|
'Product' => $product, |
|
84
|
|
|
'MetaTags' => $product->MetaTags(), |
|
85
|
|
|
'Breadcrumbs' => $product->Breadcrumbs(), |
|
86
|
|
|
))->renderWith(array('Dynamic\ProductCatalog\Page\Product', 'Page')); |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|