1 <?php
2
3 4 5 6 7 8
9 class ExtendMemberCart extends DataObjectDecorator {
10
11 function () {
12 return array(
13 'db' => array(
14 'Phone' => 'Varchar(255)',
15 'Discount' => 'Int',
16 'CartData' => 'Text',
17 ),
18 'has_many' => array(
19 'Orders' => 'Order',
20 )
21 );
22 }
23
24 function updateCMSFields(&$fields) {
25 if ($orders = $fields->dataFieldByName('Orders'))
26 $orders->setPermissions(array());
27
28 $fields->removeByName('CartData');
29 }
30
31 function updateMemberFormFields(&$fields) {
32 $fields->removeByName('Discount');
33 $fields->removeByName('CartData');
34 $fields->insertBefore($fields->datafieldByName('Phone'), 'Password');
35 }
36
37 function memberLoggedIn() {
38 if (method_exists('Cart', 'update_cart_from_cache')) {
39 Cart::update_cart_from_cache();
40 }
41 }
42
43 function updateValidator(&$obj) {
44 $obj->addRequiredField('Phone');
45 }
46
47 function getClientName() {
48 $title = $this->owner->getTitle();
49 return ($title) ? $title : $this->owner->Email;
50 }
51
52 function getPersonalDiscount() {
53 $discount = $this->owner->Discount;
54 if ($groups = $this->owner->Groups()) {
55 foreach ($groups as $g) {
56 if ($g->hasMethod('Discount') && $discount < $g->Discount()) {
57 $discount = $g->Discount();
58 }
59 }
60 }
61 if ($discount > 0) {
62 return $discount;
63 }
64 return false;
65 }
66 }
67
[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.
-