|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use Dynamic\FoxyStripe\Page\ProductPage; |
|
4
|
|
|
use Dynamic\FoxyStripe\Page\ProductPageController; |
|
5
|
|
|
use SilverStripe\SiteConfig\SiteConfig; |
|
6
|
|
|
use SilverStripe\View\Requirements; |
|
7
|
|
|
|
|
8
|
|
|
class DonationProductController extends ProductPageController |
|
9
|
|
|
{ |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* @var array |
|
13
|
|
|
*/ |
|
14
|
|
|
private static $allowed_actions = [ |
|
|
|
|
|
|
15
|
|
|
'PurchaseForm', |
|
16
|
|
|
'updatevalue', |
|
17
|
|
|
]; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* |
|
21
|
|
|
*/ |
|
22
|
|
|
public function init() |
|
23
|
|
|
{ |
|
24
|
|
|
parent::init(); |
|
25
|
|
|
Requirements::javascript("framework/thirdparty/jquery/jquery.js"); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @return FoxyStripePurchaseForm |
|
|
|
|
|
|
30
|
|
|
*/ |
|
31
|
|
|
public function PurchaseForm() |
|
32
|
|
|
{ |
|
33
|
|
|
$form = parent::PurchaseForm(); |
|
34
|
|
|
|
|
35
|
|
|
$fields = $form->Fields(); |
|
36
|
|
|
|
|
37
|
|
|
$fields->replaceField(ProductPage::getGeneratedValue($this->Code, 'price', |
|
|
|
|
|
|
38
|
|
|
$this->Price), $currencyField = CurrencyField::create('price', 'Amount')); |
|
|
|
|
|
|
39
|
|
|
|
|
40
|
|
|
$fields->removeByName(array( |
|
41
|
|
|
'quantity', |
|
42
|
|
|
ProductPage::getGeneratedValue($this->Code, 'weight', $this->Weight), |
|
|
|
|
|
|
43
|
|
|
)); |
|
44
|
|
|
|
|
45
|
|
|
if (SiteConfig::current_site_config()->CartValidation) { |
|
46
|
|
|
Requirements::javascript("framework/thirdparty/jquery-validate/jquery.validate.js"); |
|
47
|
|
|
Requirements::javascriptTemplate("foxystripe/javascript/donationProduct.js", [ |
|
48
|
|
|
'Trigger' => (string)$currencyField->getAttribute('id'), |
|
49
|
|
|
'UpdateURL' => Director::absoluteURL($this->Link('updatevalue')), |
|
50
|
|
|
]); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
return $form; |
|
|
|
|
|
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* create new encrypted price value based on user input |
|
58
|
|
|
* |
|
59
|
|
|
* @param $request |
|
60
|
|
|
* |
|
61
|
|
|
* @return string|\SilverStripe\Control\HTTPResponse |
|
62
|
|
|
*/ |
|
63
|
|
|
public function updatevalue(\SilverStripe\Control\HTTPRequest $request) |
|
64
|
|
|
{ |
|
65
|
|
|
if ($request->getVar('Price') && SiteConfig::current_site_config()->CartValidation) { |
|
66
|
|
|
$vars = $request->getVars(); |
|
67
|
|
|
$signedPrice = FoxyCart_Helper::fc_hash_value($this->Code, 'price', $vars['Price'], 'name', false); |
|
|
|
|
|
|
68
|
|
|
$json = json_encode(['Price' => $signedPrice]); |
|
69
|
|
|
$response = new HTTPResponse($json); |
|
|
|
|
|
|
70
|
|
|
$response->removeHeader('Content-Type'); |
|
|
|
|
|
|
71
|
|
|
$response->addHeader('Content-Type', 'application/json'); |
|
|
|
|
|
|
72
|
|
|
|
|
73
|
|
|
return $response; |
|
|
|
|
|
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
return 'false'; |
|
77
|
|
|
} |
|
78
|
|
|
} |