1 <?php
2 3 4 5 6 7
8 class ExtendProfilePageOrder extends Extension {
9
10 static $allowed_actions = array('orders', 'order', 'printorder', 'cancel_order');
11
12 static $orders_per_page = false;
13
14 15 16 17 18 19 20
21 function (&$menu) {
22 $menu[] = array(
23 'Link' => ProfilePage::find_link('orders'),
24 'Title' => _t('ProfilePage.MenuOrders', 'My Orders'),
25 );
26 }
27
28 29 30 31 32
33 function orders() {
34 $limit = "";
35 if ($count = self::$orders_per_page) {
36 $start = 0;
37 if (isset($_GET['start'])) {
38 $start = (int)$_GET['start'];
39 }
40 $limit = "{$start},{$count}";
41 }
42 return array(
43 'Title' => _t('ProfilePage.TitleOrders', 'Orders'),
44 'Form' => false,
45 'Orders' => DataObject::get('Order', 'MemberID = ' . Member::currentUserID(), 'ID DESC', '', $limit)
46 );
47 }
48
49 50 51 52 53 54 55
56 function order() {
57 if (!$order = Order::get_by_hash($this->owner->getRequest()->param('ID'))) $this->httpError(404, 'Page not found');
58 $data = $this->orders();
59 $data['Order'] = $order;
60 return $data;
61 }
62
63 64 65 66
67 function printorder() {
68 return $this->order();
69 }
70
71 72 73 74 75
76 function cancel_order() {
77 $rs = 0;
78 if (!$order = Order::get_by_hash($this->owner->getRequest()->param('ID'))) $this->httpError(404, 'Page not found');
79 if ($order->canCancel()) {
80 $order->Status = 'MemberCancelled';
81 $order->write();
82 $rs = 1;
83 }
84 if ($this->owner->isAjax()) {
85 return json_encode(array('rs' => $rs));
86 }
87 return $this->owner->redirectBack();
88 }
89 }
90
[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.
-