|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class DonationModifier extends AnyPriceRoundUpDonationModifier |
|
|
|
|
|
|
4
|
|
|
{ |
|
5
|
|
|
private static $has_one = array( |
|
|
|
|
|
|
6
|
|
|
'Donation' => 'DonationOption' |
|
7
|
|
|
); |
|
8
|
|
|
|
|
9
|
|
|
public function getModifierForm(Controller $optionalController = null, Validator $optionalValidator = null) |
|
10
|
|
|
{ |
|
11
|
|
|
$form = parent::getModifierForm($optionalController, $optionalValidator); |
|
12
|
|
|
$donations = DonationOption::get(); |
|
13
|
|
|
$fields = $form->Fields(); |
|
14
|
|
|
if ($donations->count()) { |
|
15
|
|
|
$field = $fields->fieldByName('AddDonation'); |
|
16
|
|
|
$title = $field->Title(); |
|
17
|
|
|
$source = $field->getSource(); |
|
18
|
|
|
$fields->removeByName('AddDonation'); |
|
19
|
|
|
unset($source[1]); |
|
20
|
|
|
$donations = $donations->map()->toArray(); |
|
21
|
|
|
$source += $donations; |
|
22
|
|
|
$fields->push(new DropdownField('DonationID', $title, $source, $this->DonationID)); |
|
|
|
|
|
|
23
|
|
|
} |
|
24
|
|
|
$form = new DonationModifier_Form($form->Controller(), 'DonationModifier', $fields, $form->Actions(), $form->getValidator()); |
|
|
|
|
|
|
25
|
|
|
//3.0TODO: Check me for consistencies. |
|
26
|
|
|
$form->addExtraClass('anyPriceRoundUpDonationModifier'); |
|
27
|
|
|
return $form; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function updateAddDonation($donationID) |
|
31
|
|
|
{ |
|
32
|
|
|
$this->AddDonation = $donationID ? true : false; |
|
|
|
|
|
|
33
|
|
|
$this->DonationID = $donationID; |
|
|
|
|
|
|
34
|
|
|
$this->write(); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
protected function LiveName() |
|
|
|
|
|
|
38
|
|
|
{ |
|
39
|
|
|
if ($this->hasDonation() && $this->DonationID) { |
|
|
|
|
|
|
40
|
|
|
return $this->Donation()->Title; |
|
|
|
|
|
|
41
|
|
|
} else { |
|
42
|
|
|
return parent::LiveName(); |
|
43
|
|
|
} |
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
class DonationModifier_Form extends OrderModifierForm |
|
|
|
|
|
|
48
|
|
|
{ |
|
49
|
|
|
public function submit(array $data, Form $form, $message = "order updated", $status = "good") |
|
|
|
|
|
|
50
|
|
|
{ |
|
51
|
|
|
$order = ShoppingCart::current_order(); |
|
52
|
|
|
if ($order) { |
|
53
|
|
|
$modifier = $order->Modifiers('DonationModifier'); |
|
54
|
|
|
if ($modifier) { |
|
55
|
|
|
$modifier = $modifier->First(); |
|
56
|
|
|
$modifier->updateAddDonation($data['DonationID']); |
|
57
|
|
|
$msg = $data['DonationID'] ? _t("AnyPriceRoundUpDonationModifier.UPDATED", "Round up donation added - THANK YOU.") : _t("AnyPriceRoundUpDonationModifier.UPDATED", "Round up donation removed."); |
|
58
|
|
View Code Duplication |
if (isset($data['OtherValue'])) { |
|
|
|
|
|
|
59
|
|
|
$modifier->updateOtherValue(floatval($data['OtherValue'])); |
|
60
|
|
|
if (floatval($data['OtherValue']) > 0) { |
|
61
|
|
|
$msg .= _t("AnyPriceRoundUpDonationModifier.UPDATED", "Added donation - THANK YOU."); |
|
62
|
|
|
} |
|
63
|
|
|
} else { |
|
64
|
|
|
$modifier->updateOtherValue(0); |
|
65
|
|
|
} |
|
66
|
|
|
$modifier->write(); |
|
67
|
|
|
return ShoppingCart::singleton()->setMessageAndReturn($msg, "good"); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
return ShoppingCart::singleton()->setMessageAndReturn(_t("AnyPriceRoundUpDonationModifier.NOTUPDATED", "Could not update the round up donation status.", "bad")); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.