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