These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | |||
4 | class EcommerceNewsletterCampaignMonitorSignupDecoratorFormFixes extends Extension |
||
5 | { |
||
6 | private static $fields_to_hide = array( |
||
7 | "FirstName", |
||
8 | "Surname", |
||
9 | "SubscribeChoice" |
||
10 | ); |
||
11 | /** |
||
12 | * |
||
13 | * @var CampaignMonitorAPIConnector |
||
14 | */ |
||
15 | private static $_api = null; |
||
16 | |||
17 | /** |
||
18 | * |
||
19 | * @return CampaignMonitorAPIConnector |
||
20 | */ |
||
21 | public function getAPI() |
||
22 | { |
||
23 | if (!self::$_api) { |
||
24 | self::$_api = CampaignMonitorAPIConnector::create(); |
||
25 | self::$_api->init(); |
||
26 | } |
||
27 | return self::$_api; |
||
28 | } |
||
29 | |||
30 | public function updateFields(FieldList $fields) |
||
31 | { |
||
32 | if ($this->hasCampaignMonitorPage()) { |
||
33 | $page = $this->CampaignMonitorPage(); |
||
34 | if ($page->ReadyToReceiveSubscribtions()) { |
||
35 | // Create fields |
||
36 | $member = Member::currentUser(); |
||
37 | $api = $this->getAPI(); |
||
38 | $currentValues = $api->getSubscriber($page->ListID, $member); |
||
39 | if (!$currentValues) { |
||
40 | $emailField = null; |
||
41 | $emailRequired = true; |
||
42 | } |
||
43 | if (!$member) { |
||
44 | $member = new Member(); |
||
45 | } |
||
46 | $signupField = $member->getCampaignMonitorSignupField($page->ListID, "SubscribeChoice"); |
||
47 | $fieldsToHide = Config::inst()->get("EcommerceNewsletterCampaignMonitorSignupDecoratorFormFixes", "fields_to_hide"); |
||
48 | foreach ($fieldsToHide as $field) { |
||
49 | Requirements::customCSS("#CMCustomField".$field." {display: none!important;}"); |
||
50 | } |
||
51 | $config = EcommerceDBConfig::current_ecommerce_db_config(); |
||
52 | if ($config->CampaignMonitorSignupHeader) { |
||
53 | $fields->push(new HeaderField("CampaignMonitorNewsletterSignupHeader", $config->CampaignMonitorSignupHeader, 3)); |
||
54 | } |
||
55 | if ($config->CampaignMonitorSignupIntro) { |
||
56 | $fields->push(new LiteralField("CampaignMonitorNewsletterSignupContent", "<p class=\"campaignMonitorNewsletterSignupContent\">".$config->CampaignMonitorSignupIntro."</p>")); |
||
57 | } |
||
58 | $label = $config->CampaignMonitorSignupLabel; |
||
59 | if (!$label) { |
||
60 | $label = _t("EcommerceNewsletterCampaignMonitorSignupDecoratorFormFixes.JOIN", "Join"); |
||
61 | } |
||
62 | $fields->push(new CheckboxField("CampaignMonitorNewsletterSubscribeCheckBox", $config->CampaignMonitorSignupLabel)); |
||
63 | $fields->push($signupField); |
||
64 | Requirements::customCSS(" |
||
65 | #SubscribeChoice {display: none;} |
||
66 | .CMFieldsCustomFieldsHolder {display: none;} |
||
67 | "); |
||
68 | Requirements::customScript("jQuery(\"#CampaignMonitorNewsletterSubscribeCheckBox\").on(\"change\", function(){jQuery(\".CMFieldsCustomFieldsHolder\").slideToggle();});"); |
||
69 | } |
||
70 | } |
||
71 | } |
||
72 | |||
73 | |||
74 | /** |
||
75 | * adds the user to the list ... |
||
76 | * @param Array $data |
||
77 | * @param Form $form |
||
78 | * @param Order $order |
||
79 | * @param Member $member |
||
80 | */ |
||
81 | public function saveAddressExtension($data, $form, $order = null, $member = null) |
||
0 ignored issues
–
show
|
|||
82 | { |
||
83 | if (isset($data["CampaignMonitorNewsletterSubscribeCheckBox"]) && $data["CampaignMonitorNewsletterSubscribeCheckBox"]) { |
||
84 | if ($this->hasCampaignMonitorPage()) { |
||
85 | $page = $this->CampaignMonitorPage(); |
||
86 | if ($page->ReadyToReceiveSubscribtions()) { |
||
87 | |||
88 | //true until proven otherwise. |
||
89 | $newlyCreatedMember = false; |
||
90 | $api = $this->getAPI(); |
||
91 | $isSubscribe = isset($data["SubscribeChoice"]) && $data["SubscribeChoice"] == "Subscribe"; |
||
92 | $member = Member::currentUser(); |
||
93 | if (!$member) { |
||
94 | $memberAlreadyLoggedIn = false; |
||
95 | $existingMember = Member::get()->filter(array("Email" => Convert::raw2sql($data["Email"])))->First(); |
||
96 | //if($isSubscribe && $existingMember){ |
||
97 | //$form->addErrorMessage('Email', _t("CAMPAIGNMONITORSIGNUPPAGE.EMAIL_EXISTS", "This email is already in use. Please log in for this email or try another email address."), 'warning'); |
||
98 | //$this->redirectBack(); |
||
99 | //return; |
||
100 | //} |
||
101 | $member = $existingMember; |
||
102 | if (!$member) { |
||
103 | $newlyCreatedMember = true; |
||
104 | $member = new Member(); |
||
105 | } |
||
106 | } |
||
107 | |||
108 | //logged in: if the member already as someone else then you can't sign up. |
||
109 | else { |
||
110 | $memberAlreadyLoggedIn = true; |
||
111 | //$existingMember = Member::get() |
||
112 | // ->filter(array("Email" => Convert::raw2sql($data["CampaignMonitorEmail"]))) |
||
113 | // ->exclude(array("ID" => $member->ID)) |
||
114 | // ->First(); |
||
115 | //if($isSubscribe && $existingMember) { |
||
116 | //$form->addErrorMessage('CampaignMonitorEmail', _t("CAMPAIGNMONITORSIGNUPPAGE.EMAIL_EXISTS", "This email is already in use by someone else. Please log in for this email or try another email address."), 'warning'); |
||
117 | //$this->redirectBack(); |
||
118 | //return; |
||
119 | //} |
||
120 | } |
||
121 | |||
122 | //if this is a new member then we save the member |
||
123 | if ($isSubscribe) { |
||
124 | if ($newlyCreatedMember) { |
||
125 | $form->saveInto($member); |
||
126 | $member->Email = Convert::raw2sql($data["CampaignMonitorEmail"]); |
||
127 | $member->SetPassword = true; |
||
128 | $member->Password = Member::create_new_password(); |
||
129 | $member->write(); |
||
130 | } |
||
131 | } |
||
132 | $outcome = $member->processCampaignMonitorSignupField($page, $data, $form); |
||
133 | } |
||
134 | } |
||
135 | } |
||
136 | } |
||
137 | |||
138 | /** |
||
139 | * returns ID of Mailing List that people are subscribing to. |
||
140 | * @return CampaignMonitorPage |
||
141 | */ |
||
142 | protected function hasCampaignMonitorPage() |
||
143 | { |
||
144 | $config = EcommerceDBConfig::current_ecommerce_db_config(); |
||
145 | return $config->CampaignMonitorSignupPageID ? true : false; |
||
146 | } |
||
147 | |||
148 | /** |
||
149 | * returns ID of Mailing List that people are subscribing to. |
||
150 | * @return CampaignMonitorPage |
||
151 | */ |
||
152 | protected function campaignMonitorPage() |
||
153 | { |
||
154 | $config = EcommerceDBConfig::current_ecommerce_db_config(); |
||
155 | return $config->CampaignMonitorSignupPage(); |
||
156 | } |
||
157 | } |
||
158 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.