|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class DonationProduct extends ProductPage |
|
4
|
|
|
{ |
|
5
|
|
|
/** |
|
6
|
|
|
* @var string |
|
7
|
|
|
*/ |
|
8
|
|
|
private static $singular_name = 'Donation'; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* @var string |
|
12
|
|
|
*/ |
|
13
|
|
|
private static $plural_name = 'Donations'; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @var array |
|
17
|
|
|
*/ |
|
18
|
|
|
private static $allowed_children = []; |
|
|
|
|
|
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @return FieldList |
|
22
|
|
|
*/ |
|
23
|
|
|
public function getCMSFields() |
|
24
|
|
|
{ |
|
25
|
|
|
$fields = parent::getCMSFields(); |
|
26
|
|
|
|
|
27
|
|
|
$fields->removeByName([ |
|
28
|
|
|
'Weight', |
|
29
|
|
|
'Price', |
|
30
|
|
|
]); |
|
31
|
|
|
|
|
32
|
|
|
return $fields; |
|
33
|
|
|
} |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
class DonationProduct_Controller extends ProductPage_Controller |
|
|
|
|
|
|
37
|
|
|
{ |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @var array |
|
41
|
|
|
*/ |
|
42
|
|
|
private static $allowed_actions = [ |
|
43
|
|
|
'PurchaseForm', |
|
44
|
|
|
'updatevalue', |
|
45
|
|
|
]; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* |
|
49
|
|
|
*/ |
|
50
|
|
|
public function init() |
|
51
|
|
|
{ |
|
52
|
|
|
parent::init(); |
|
53
|
|
|
Requirements::javascript("framework/thirdparty/jquery/jquery.js"); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @return FoxyStripePurchaseForm |
|
58
|
|
|
*/ |
|
59
|
|
|
public function PurchaseForm() |
|
60
|
|
|
{ |
|
61
|
|
|
$form = parent::PurchaseForm(); |
|
62
|
|
|
|
|
63
|
|
|
$fields = $form->Fields(); |
|
64
|
|
|
|
|
65
|
|
|
$fields->replaceField(ProductPage::getGeneratedValue($this->Code, 'price', |
|
66
|
|
|
$this->Price), $currencyField = CurrencyField::create('price', 'Amount')); |
|
67
|
|
|
|
|
68
|
|
|
/*$fields->replaceField(ProductPage::getGeneratedValue($this->Code, 'code', |
|
|
|
|
|
|
69
|
|
|
$this->Code), $code = HiddenField::create(ProductPage::getGeneratedValue($this->Code, 'code', |
|
70
|
|
|
$this->Code))->setValue($this->Code)); |
|
71
|
|
|
$fields->replaceField(ProductPage::getGeneratedValue($this->Code, 'product_id', |
|
72
|
|
|
$this->ID), $id = HiddenField::create(ProductPage::getGeneratedValue($this->Code, 'product_id', |
|
73
|
|
|
$this->ID))->setValue($this->ID));*/ |
|
74
|
|
|
|
|
75
|
|
|
$id = $fields->dataFieldByName(ProductPage::getGeneratedValue($this->Code, 'product_id', |
|
76
|
|
|
$this->ID)); |
|
77
|
|
|
|
|
78
|
|
|
|
|
79
|
|
|
|
|
80
|
|
|
$code = $fields->dataFieldByName(ProductPage::getGeneratedValue($this->Code, 'code', |
|
81
|
|
|
$this->Code)); |
|
82
|
|
|
|
|
83
|
|
|
$codeName = $code->getName(); |
|
84
|
|
|
$code->setName("h:{$codeName}"); |
|
85
|
|
|
|
|
86
|
|
|
$idName = $id->getName(); |
|
87
|
|
|
$id->setName("h:{$idName}"); |
|
88
|
|
|
|
|
89
|
|
|
$fields->removeByName(array( |
|
90
|
|
|
'quantity', |
|
91
|
|
|
ProductPage::getGeneratedValue($this->Code, 'weight', $this->Weight), |
|
92
|
|
|
)); |
|
93
|
|
|
|
|
94
|
|
|
if (SiteConfig::current_site_config()->CartValidation) { |
|
95
|
|
|
Requirements::javascript("framework/thirdparty/jquery-validate/jquery.validate.js"); |
|
96
|
|
|
Requirements::javascriptTemplate("foxystripe/javascript/donationProduct.js", [ |
|
|
|
|
|
|
97
|
|
|
'Trigger' => (string)$currencyField->getAttribute('id'), |
|
98
|
|
|
'UpdateURL' => Director::absoluteURL($this->Link('updatevalue')), |
|
99
|
|
|
]); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
return $form; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* create new encrypted price value based on user input |
|
107
|
|
|
* |
|
108
|
|
|
* @param $request |
|
109
|
|
|
* |
|
110
|
|
|
* @return string|SS_HTTPResponse |
|
111
|
|
|
*/ |
|
112
|
|
|
public function updatevalue(SS_HTTPRequest $request) |
|
113
|
|
|
{ |
|
114
|
|
|
if ($request->getVar('Price') && SiteConfig::current_site_config()->CartValidation) { |
|
115
|
|
|
$vars = $request->getVars(); |
|
116
|
|
|
$signedPrice = FoxyCart_Helper::fc_hash_value($this->Code, 'price', $vars['Price'], 'name', false); |
|
117
|
|
|
$json = json_encode(['Price' => $signedPrice]); |
|
118
|
|
|
$response = new SS_HTTPResponse($json); |
|
119
|
|
|
$response->removeHeader('Content-Type'); |
|
120
|
|
|
$response->addHeader('Content-Type', 'application/json'); |
|
121
|
|
|
|
|
122
|
|
|
return $response; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
return 'false'; |
|
126
|
|
|
} |
|
127
|
|
|
} |
This check marks private properties in classes that are never used. Those properties can be removed.