1 <?php
2
3 4 5 6 7 8
9 class CartPage extends Page{
10
11 static $icon = "cart/img/cart";
12 static $allowed_children = 'none';
13
14 static $defaults = array(
15 'AutoChild' => 0,
16 "DevEditType" => "Fixed",
17 'ShowInSiteMap' => 0,
18 'ShowInSearch' => 0,
19 'ShowInMenu' => 0,
20 'URLSegment' => 'cart',
21 );
22
23 24 25 26 27 28
29 static function find_link($action = null) {
30 if (!$page = DataObject::get_one('CartPage')) {
31 user_error('Создайте страницу корзины', E_USER_ERROR);
32 }
33 return $page->Link($action);
34 }
35
36 37 38 39
40 function requireDefaultRecords() {
41 parent::requireDefaultRecords();
42
43 if (!$page = DataObject::get_one('CartPage')) {
44 $page = new CartPage();
45 $page->Title = $this->i18n_singular_name();
46 $page->URLSegment = 'cart';
47 $page->writeToStage('Stage');
48 $page->publish('Stage', 'Live');
49
50 if (method_exists('DB', 'alteration_message'))
51 DB::alteration_message('Cart page created', 'created');
52 }
53 }
54
55 function canCreate() {
56 return (DataObject::get_one('CartPage')) ? false : true;
57 }
58
59 60 61 62 63 64 65
66 function CanCheckout($price=null) {
67 return Cart::current_order()->CanCheckout($price);
68 }
69
70 71 72 73 74 75 76
77 function MinTotalPrice($real=false) {
78 return Cart::current_order()->MinTotalPrice($real);
79 }
80
81 82 83 84 85
86 function HasItems() {
87 return Cart::has_items();
88 }
89 }
90
91 class CartPage_Controller extends Page_Controller{
92
93 static $allowed_actions = array();
94
95 96 97 98 99
100 function getCart() {
101 return Cart::current_order();
102 }
103
104 105 106 107 108
109 function ClearCartLink() {
110 return Cart_Controller::clear_link();
111 }
112 }
[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the
Silverstripe Forums to ask development related questions.
-