Version Notes
Now its possible to log in on Magento through a simple url not need anymore to link to the controller.
Update with the last version of Ebizmarts 1.0.21.
Download this release
Release Info
Developer | Thiago Santos |
Extension | TS_Auto_Login_MailChimp |
Version | 1.0.21 |
Comparing to | |
See all releases |
Version 1.0.21
- app/code/local/ThiagoSantos/LoginAutomatico/Helper/Data.php +28 -0
- app/code/local/ThiagoSantos/LoginAutomatico/Helper/MonkeyData.php +839 -0
- app/code/local/ThiagoSantos/LoginAutomatico/Model/Pageload/Observer.php +53 -0
- app/code/local/ThiagoSantos/LoginAutomatico/controllers/AController.php +93 -0
- app/code/local/ThiagoSantos/LoginAutomatico/etc/config.xml +58 -0
- app/etc/modules/ThiagoSantos_LoginAutomatico.xml +18 -0
- package.xml +21 -0
app/code/local/ThiagoSantos/LoginAutomatico/Helper/Data.php
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Pereira, Thiago Santos
|
4 |
+
* http://thiagosantos.com/
|
5 |
+
*
|
6 |
+
* @category ThiagoSantos
|
7 |
+
* @package ThiagoSantos_LoginAutomatico
|
8 |
+
*/
|
9 |
+
|
10 |
+
class ThiagoSantos_LoginAutomatico_Helper_Data extends Mage_Core_Helper_Abstract {
|
11 |
+
|
12 |
+
public function encrypt($customer, $urlencode = false) {
|
13 |
+
|
14 |
+
//montar hash
|
15 |
+
$id = $customer -> getId();
|
16 |
+
$email = $customer -> getEmail();
|
17 |
+
$crypt = Mage::getModel('core/encryption');
|
18 |
+
return $crypt -> encrypt($id . ';' . $email);
|
19 |
+
}
|
20 |
+
|
21 |
+
public function decrypt($d) {
|
22 |
+
|
23 |
+
$crypt = Mage::getModel('core/encryption');
|
24 |
+
return $crypt -> decrypt($d);
|
25 |
+
|
26 |
+
}
|
27 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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Pereira, Thiago Santos
|
4 |
+
* http://thiagosantos.com/
|
5 |
+
*
|
6 |
+
* @category ThiagoSantos
|
7 |
+
* @package ThiagoSantos_LoginAutomatico
|
8 |
+
*/
|
9 |
+
|
10 |
+
/**
|
11 |
+
* Mage Monkey default helper
|
12 |
+
*
|
13 |
+
* @category Ebizmarts
|
14 |
+
* @package Ebizmarts_MageMonkey
|
15 |
+
* @author Ebizmarts Team <info@ebizmarts.com>
|
16 |
+
*/
|
17 |
+
class ThiagoSantos_LoginAutomatico_Helper_MonkeyData extends Ebizmarts_MageMonkey_Helper_Data
|
18 |
+
{
|
19 |
+
|
20 |
+
/**
|
21 |
+
* Utility to check if admin is logged in
|
22 |
+
*
|
23 |
+
* @return bool
|
24 |
+
*/
|
25 |
+
public function isAdmin()
|
26 |
+
{
|
27 |
+
return Mage::getSingleton('admin/session')->isLoggedIn();
|
28 |
+
}
|
29 |
+
|
30 |
+
/**
|
31 |
+
* Check if Magento is EE
|
32 |
+
*
|
33 |
+
* @return bool
|
34 |
+
*/
|
35 |
+
public function isEnterprise()
|
36 |
+
{
|
37 |
+
return is_object(Mage::getConfig()->getNode('global/models/enterprise_enterprise'));
|
38 |
+
}
|
39 |
+
|
40 |
+
/**
|
41 |
+
* Return Webhooks security key for given store
|
42 |
+
*
|
43 |
+
* @param mixed $store Store object, or Id, or code
|
44 |
+
* @param string $listId Optional listid to retrieve store code from it
|
45 |
+
* @return string
|
46 |
+
*/
|
47 |
+
public function getWebhooksKey($store, $listId = null)
|
48 |
+
{
|
49 |
+
if( !is_null($listId) ){
|
50 |
+
$store = $this->getStoreByList($listId, TRUE);
|
51 |
+
}
|
52 |
+
|
53 |
+
$crypt = md5((string)Mage::getConfig()->getNode('global/crypt/key'));
|
54 |
+
$key = substr($crypt, 0, (strlen($crypt)/2));
|
55 |
+
|
56 |
+
return ($key . $store);
|
57 |
+
}
|
58 |
+
|
59 |
+
public function filterShowGroupings($interestGroupings)
|
60 |
+
{
|
61 |
+
if(is_array($interestGroupings)){
|
62 |
+
|
63 |
+
$customGroupings = Mage::getConfig()->getNode('default/monkey/custom_groupings')
|
64 |
+
->asArray();
|
65 |
+
|
66 |
+
foreach($interestGroupings as $key => $group){
|
67 |
+
|
68 |
+
if(TRUE === in_array($group['name'], $customGroupings)){
|
69 |
+
unset($interestGroupings[$key]);
|
70 |
+
}
|
71 |
+
|
72 |
+
}
|
73 |
+
}
|
74 |
+
|
75 |
+
return $interestGroupings;
|
76 |
+
}
|
77 |
+
|
78 |
+
/**
|
79 |
+
* Check if CustomerGroup grouping already exists on MC
|
80 |
+
*
|
81 |
+
* @param array $groupings
|
82 |
+
* @return bool
|
83 |
+
*/
|
84 |
+
public function customerGroupGroupingExists($interestGroupings)
|
85 |
+
{
|
86 |
+
$exists = FALSE;
|
87 |
+
if(is_array($interestGroupings)){
|
88 |
+
foreach($interestGroupings as $group){
|
89 |
+
if($group['name'] == $this->getCustomerGroupingName()){
|
90 |
+
$exists = TRUE;
|
91 |
+
break;
|
92 |
+
}
|
93 |
+
}
|
94 |
+
}
|
95 |
+
|
96 |
+
return $exists;
|
97 |
+
}
|
98 |
+
|
99 |
+
/**
|
100 |
+
* Return customer groping name to be used when creating a grouping to store
|
101 |
+
* Magento customer groups
|
102 |
+
*
|
103 |
+
* @return string
|
104 |
+
*/
|
105 |
+
public function getCustomerGroupingName()
|
106 |
+
{
|
107 |
+
return (string)Mage::getConfig()->getNode('default/monkey/custom_groupings/customer_grouping_name');
|
108 |
+
}
|
109 |
+
|
110 |
+
/**
|
111 |
+
* Get module User-Agent to use on API requests
|
112 |
+
*
|
113 |
+
* @return string
|
114 |
+
*/
|
115 |
+
public function getUserAgent()
|
116 |
+
{
|
117 |
+
$modules = Mage::getConfig()->getNode('modules')->children();
|
118 |
+
$modulesArray = (array)$modules;
|
119 |
+
|
120 |
+
$aux = (array_key_exists('Enterprise_Enterprise',$modulesArray))? 'EE' : 'CE' ;
|
121 |
+
$v = (string)Mage::getConfig()->getNode('modules/Ebizmarts_MageMonkey/version');
|
122 |
+
$version = strpos(Mage::getVersion(),'-')? substr(Mage::getVersion(),0,strpos(Mage::getVersion(),'-')) : Mage::getVersion();
|
123 |
+
return (string)'MageMonkey'.$v.'/Mage'.$aux.$version;
|
124 |
+
}
|
125 |
+
|
126 |
+
/**
|
127 |
+
* Return Mandrill API key
|
128 |
+
*
|
129 |
+
* @param string $store
|
130 |
+
* @return string Api Key
|
131 |
+
*/
|
132 |
+
public function getMandrillApiKey($store = null)
|
133 |
+
{
|
134 |
+
if(is_null($store)){
|
135 |
+
$key = $this->config('mandrill_apikey');
|
136 |
+
}else{
|
137 |
+
$curstore = Mage::app()->getStore();
|
138 |
+
Mage::app()->setCurrentStore($store);
|
139 |
+
$key = $this->config('mandrill_apikey', $store);
|
140 |
+
Mage::app()->setCurrentStore($curstore);
|
141 |
+
}
|
142 |
+
|
143 |
+
return $key;
|
144 |
+
}
|
145 |
+
|
146 |
+
/**
|
147 |
+
* Return MC API key for given store, if none is given
|
148 |
+
* default key is returned
|
149 |
+
*
|
150 |
+
* @param string $store
|
151 |
+
* @return string Api Key
|
152 |
+
*/
|
153 |
+
public function getApiKey($store = null)
|
154 |
+
{
|
155 |
+
if(is_null($store)){
|
156 |
+
$key = $this->config('apikey');
|
157 |
+
}else{
|
158 |
+
$curstore = Mage::app()->getStore();
|
159 |
+
Mage::app()->setCurrentStore($store);
|
160 |
+
$key = $this->config('apikey', $store);
|
161 |
+
Mage::app()->setCurrentStore($curstore);
|
162 |
+
}
|
163 |
+
|
164 |
+
return $key;
|
165 |
+
}
|
166 |
+
|
167 |
+
/**
|
168 |
+
* Logging facility
|
169 |
+
*
|
170 |
+
* @param mixed $data Message to save to file
|
171 |
+
* @param string $filename log filename, default is <Monkey.log>
|
172 |
+
* @return Mage_Core_Model_Log_Adapter
|
173 |
+
*/
|
174 |
+
public function log($data, $filename = 'Monkey.log')
|
175 |
+
{
|
176 |
+
return Mage::getModel('core/log_adapter', $filename)->log($data);
|
177 |
+
}
|
178 |
+
|
179 |
+
/**
|
180 |
+
* Get module configuration value
|
181 |
+
*
|
182 |
+
* @param string $value
|
183 |
+
* @param string $store
|
184 |
+
* @return mixed Configuration setting
|
185 |
+
*/
|
186 |
+
public function config($value, $store = null)
|
187 |
+
{
|
188 |
+
$store = is_null($store) ? Mage::app()->getStore() : $store;
|
189 |
+
|
190 |
+
$configscope = Mage::app()->getRequest()->getParam('store');
|
191 |
+
if( $configscope && ($configscope !== 'undefined') ){
|
192 |
+
$store = $configscope;
|
193 |
+
}
|
194 |
+
|
195 |
+
return Mage::getStoreConfig("monkey/general/$value", $store);
|
196 |
+
}
|
197 |
+
|
198 |
+
/**
|
199 |
+
* Check if config setting <checkout_subscribe> is enabled
|
200 |
+
*
|
201 |
+
* @return bool
|
202 |
+
*/
|
203 |
+
public function canCheckoutSubscribe()
|
204 |
+
{
|
205 |
+
return $this->config('checkout_subscribe');
|
206 |
+
}
|
207 |
+
|
208 |
+
/**
|
209 |
+
* Check if an email is subscribed on MailChimp
|
210 |
+
*
|
211 |
+
* @param string $email
|
212 |
+
* @param string $listId
|
213 |
+
* @return bool
|
214 |
+
*/
|
215 |
+
public function subscribedToList($email, $listId = null)
|
216 |
+
{
|
217 |
+
$on = FALSE;
|
218 |
+
|
219 |
+
if($email){
|
220 |
+
$member = Mage::getSingleton('monkey/api')
|
221 |
+
->listMemberInfo($listId, $email);
|
222 |
+
|
223 |
+
if(!is_string($member) && $member['success'] && ($member['data'][0]['status'] == 'subscribed' || $member['data'][0]['status'] == 'pending')){
|
224 |
+
$on = TRUE;
|
225 |
+
}
|
226 |
+
}
|
227 |
+
|
228 |
+
return $on;
|
229 |
+
}
|
230 |
+
|
231 |
+
/**
|
232 |
+
* Check if Ecommerce360 integration is enabled
|
233 |
+
*
|
234 |
+
* @return bool
|
235 |
+
*/
|
236 |
+
public function ecommerce360Active()
|
237 |
+
{
|
238 |
+
return (bool)($this->config('ecommerce360') != 0);
|
239 |
+
}
|
240 |
+
|
241 |
+
/**
|
242 |
+
* Check if Transactional Email via MC is enabled
|
243 |
+
*
|
244 |
+
* @return bool
|
245 |
+
*/
|
246 |
+
public function useTransactionalService()
|
247 |
+
{
|
248 |
+
return Mage::getStoreConfigFlag("monkey/general/transactional_emails");
|
249 |
+
}
|
250 |
+
|
251 |
+
/**
|
252 |
+
* Check if Ebizmarts_MageMonkey module is enabled
|
253 |
+
*
|
254 |
+
* @return bool
|
255 |
+
*/
|
256 |
+
public function canMonkey()
|
257 |
+
{
|
258 |
+
return (bool)((int)$this->config('active') !== 0);
|
259 |
+
}
|
260 |
+
|
261 |
+
/**
|
262 |
+
* Get default MC listId for given storeId
|
263 |
+
*
|
264 |
+
* @param string $store
|
265 |
+
* @return string $list
|
266 |
+
*/
|
267 |
+
public function getDefaultList($store)
|
268 |
+
{
|
269 |
+
$curstore = Mage::app()->getStore();
|
270 |
+
Mage::app()->setCurrentStore($store);
|
271 |
+
$list = $this->config('list', $store);
|
272 |
+
Mage::app()->setCurrentStore($curstore);
|
273 |
+
return $list;
|
274 |
+
}
|
275 |
+
|
276 |
+
/**
|
277 |
+
* Get additional Lists by storeId
|
278 |
+
*
|
279 |
+
* @param string $store
|
280 |
+
* @return string $list
|
281 |
+
*/
|
282 |
+
public function getAdditionalList($store)
|
283 |
+
{
|
284 |
+
$curstore = Mage::app()->getStore();
|
285 |
+
Mage::app()->setCurrentStore($store);
|
286 |
+
$list = $this->config('additional_lists', $store);
|
287 |
+
Mage::app()->setCurrentStore($curstore);
|
288 |
+
return $list;
|
289 |
+
}
|
290 |
+
|
291 |
+
/**
|
292 |
+
* Get which store is associated to given $mcListId
|
293 |
+
*
|
294 |
+
* @param string $mcListId
|
295 |
+
* @param bool $includeDefault Include <default> store or not on result
|
296 |
+
* @return string $store
|
297 |
+
*/
|
298 |
+
public function getStoreByList($mcListId, $includeDefault = FALSE)
|
299 |
+
{
|
300 |
+
$list = Mage::getModel('core/config_data')->getCollection()
|
301 |
+
->addValueFilter($mcListId)->getFirstItem();
|
302 |
+
|
303 |
+
$store = null;
|
304 |
+
if($list->getId()){
|
305 |
+
|
306 |
+
//$isDefault = (bool)($list->getScope() == 'default');
|
307 |
+
$isDefault = (bool)($list->getScope() == Mage::app()->getDefaultStoreView()->getCode());
|
308 |
+
if(!$isDefault && !$includeDefault){
|
309 |
+
$store = (string)Mage::app()->getStore($list->getScopeId())->getCode();
|
310 |
+
}else{
|
311 |
+
$store = $list->getScope();
|
312 |
+
}
|
313 |
+
|
314 |
+
}
|
315 |
+
|
316 |
+
return $store;
|
317 |
+
}
|
318 |
+
|
319 |
+
/**
|
320 |
+
* Check if current request is a Webhooks request
|
321 |
+
*
|
322 |
+
* @return bool
|
323 |
+
*/
|
324 |
+
public function isWebhookRequest()
|
325 |
+
{
|
326 |
+
$rq = Mage::app()->getRequest();
|
327 |
+
$monkeyRequest = (string)'monkeywebhookindex';
|
328 |
+
$thisRequest = (string)($rq->getRequestedRouteName() . $rq->getRequestedControllerName() . $rq->getRequestedActionName());
|
329 |
+
|
330 |
+
return (bool)($monkeyRequest === $thisRequest);
|
331 |
+
}
|
332 |
+
|
333 |
+
/**
|
334 |
+
* Get config setting <map_fields>
|
335 |
+
*
|
336 |
+
* @return array|FALSE
|
337 |
+
*/
|
338 |
+
public function getMergeMaps($storeId)
|
339 |
+
{
|
340 |
+
return unserialize( $this->config('map_fields', $storeId) );
|
341 |
+
}
|
342 |
+
|
343 |
+
/**
|
344 |
+
* Get progress bar HTML code
|
345 |
+
*
|
346 |
+
* @param integer $complete Processed qty so far
|
347 |
+
* @param integer $total Total qty to process
|
348 |
+
* @return string
|
349 |
+
*/
|
350 |
+
public function progressbar($complete, $total)
|
351 |
+
{
|
352 |
+
if($total == 0){
|
353 |
+
return;
|
354 |
+
}
|
355 |
+
$percentage = round(($complete * 100) / $total, 0);
|
356 |
+
|
357 |
+
$barStyle = '';
|
358 |
+
if($percentage > 0){
|
359 |
+
$barStyle = " style=\"width: $percentage%\"";
|
360 |
+
}
|
361 |
+
|
362 |
+
$html = "<div id=\"bar-progress-bar\" class=\"bar-all-rounded\">\n";
|
363 |
+
$html .= "<div id=\"bar-progress-bar-percentage\" class=\"bar-all-rounded\"$barStyle>";
|
364 |
+
$html .= "$percentage% ($complete of $total)";
|
365 |
+
//<progress value="75" max="100">3/4 complete</progress>
|
366 |
+
//if ($percentage > 5) {$html .= "$percentage% ($complete of $total)";} else {$html .= "<div class=\"bar-spacer\"> </div>";}
|
367 |
+
$html .= "</div></div>";
|
368 |
+
|
369 |
+
return $html;
|
370 |
+
}
|
371 |
+
|
372 |
+
/**
|
373 |
+
* Return Merge Fields mapped to Magento attributes
|
374 |
+
*
|
375 |
+
* @param object $customer
|
376 |
+
* @param bool $includeEmail
|
377 |
+
* @param integer $websiteId
|
378 |
+
* @return array
|
379 |
+
*/
|
380 |
+
public function getMergeVars($customer, $includeEmail = FALSE, $websiteId = NULL)
|
381 |
+
{
|
382 |
+
$merge_vars = array();
|
383 |
+
$maps = $this->getMergeMaps($customer->getStoreId());
|
384 |
+
|
385 |
+
if(!$maps){
|
386 |
+
return;
|
387 |
+
}
|
388 |
+
|
389 |
+
$request = Mage::app()->getRequest();
|
390 |
+
|
391 |
+
//Add Customer data to Subscriber if is Newsletter_Subscriber is Customer
|
392 |
+
if($customer->getCustomerId()){
|
393 |
+
$customer->addData(Mage::getModel('customer/customer')->load($customer->getCustomerId())
|
394 |
+
->toArray());
|
395 |
+
}
|
396 |
+
|
397 |
+
foreach($maps as $map){
|
398 |
+
|
399 |
+
$customAtt = $map['magento'];
|
400 |
+
$chimpTag = $map['mailchimp'];
|
401 |
+
|
402 |
+
if($chimpTag && $customAtt){
|
403 |
+
|
404 |
+
$key = strtoupper($chimpTag);
|
405 |
+
|
406 |
+
switch ($customAtt) {
|
407 |
+
case 'gender':
|
408 |
+
$val = (int)$customer->getData(strtolower($customAtt));
|
409 |
+
if($val == 1){
|
410 |
+
$merge_vars[$key] = 'Male';
|
411 |
+
}elseif($val == 2){
|
412 |
+
$merge_vars[$key] = 'Female';
|
413 |
+
}
|
414 |
+
break;
|
415 |
+
case 'dob':
|
416 |
+
$dob = (string)$customer->getData(strtolower($customAtt));
|
417 |
+
if($dob){
|
418 |
+
$merge_vars[$key] = (substr($dob, 5, 2) . '/' . substr($dob, 8, 2));
|
419 |
+
}
|
420 |
+
break;
|
421 |
+
case 'billing_address':
|
422 |
+
case 'shipping_address':
|
423 |
+
|
424 |
+
$addr = explode('_', $customAtt);
|
425 |
+
$address = $customer->{'getPrimary'.ucfirst($addr[0]).'Address'}();
|
426 |
+
if($address){
|
427 |
+
$merge_vars[$key] = array(
|
428 |
+
'addr1' => $address->getStreet(1),
|
429 |
+
'addr2' => $address->getStreet(2),
|
430 |
+
'city' => $address->getCity(),
|
431 |
+
'state' => (!$address->getRegion() ? $address->getCity() : $address->getRegion()),
|
432 |
+
'zip' => $address->getPostcode(),
|
433 |
+
'country' => $address->getCountryId()
|
434 |
+
);
|
435 |
+
}
|
436 |
+
|
437 |
+
break;
|
438 |
+
case 'date_of_purchase':
|
439 |
+
|
440 |
+
$last_order = Mage::getResourceModel('sales/order_collection')
|
441 |
+
->addFieldToFilter('customer_email', $customer->getEmail())
|
442 |
+
->addFieldToFilter('state', array('in' => Mage::getSingleton('sales/order_config')->getVisibleOnFrontStates()))
|
443 |
+
->setOrder('created_at', 'desc')
|
444 |
+
->getFirstItem();
|
445 |
+
if ( $last_order->getId() ){
|
446 |
+
$merge_vars[$key] = Mage::helper('core')->formatDate($last_order->getCreatedAt());
|
447 |
+
}
|
448 |
+
|
449 |
+
break;
|
450 |
+
case 'ee_customer_balance':
|
451 |
+
|
452 |
+
$merge_vars[$key] = '';
|
453 |
+
|
454 |
+
if($this->isEnterprise() && $customer->getId()){
|
455 |
+
|
456 |
+
$_customer = Mage::getModel('customer/customer')->load($customer->getId());
|
457 |
+
if($_customer->getId()){
|
458 |
+
if (Mage::app()->getStore()->isAdmin()) {
|
459 |
+
$websiteId = is_null($websiteId) ? Mage::app()->getStore()->getWebsiteId() : $websiteId;
|
460 |
+
}
|
461 |
+
|
462 |
+
$balance = Mage::getModel('enterprise_customerbalance/balance')
|
463 |
+
->setWebsiteId($websiteId)
|
464 |
+
->setCustomerId($_customer->getId())
|
465 |
+
->loadByCustomer();
|
466 |
+
|
467 |
+
$merge_vars[$key] = $balance->getAmount();
|
468 |
+
}
|
469 |
+
|
470 |
+
}
|
471 |
+
|
472 |
+
break;
|
473 |
+
case 'custshash':
|
474 |
+
$merge_vars[$key] = '';
|
475 |
+
$cryptdata = Mage::helper('loginautomatico') -> encrypt($customer);
|
476 |
+
$merge_vars[$key] = urlencode($cryptdata);
|
477 |
+
break;
|
478 |
+
default:
|
479 |
+
|
480 |
+
if( ($value = (string)$customer->getData(strtolower($customAtt)))
|
481 |
+
OR ($value = (string)$request->getPost(strtolower($customAtt))) ){
|
482 |
+
$merge_vars[$key] = $value;
|
483 |
+
}
|
484 |
+
|
485 |
+
break;
|
486 |
+
}
|
487 |
+
|
488 |
+
}
|
489 |
+
}
|
490 |
+
|
491 |
+
//GUEST
|
492 |
+
if( !$customer->getId() ){
|
493 |
+
$guestFirstName = $this->config('guest_name', $customer->getStoreId());
|
494 |
+
$guestLastName = $this->config('guest_lastname', $customer->getStoreId());
|
495 |
+
|
496 |
+
if($guestFirstName){
|
497 |
+
$merge_vars['FNAME'] = $guestFirstName;
|
498 |
+
}
|
499 |
+
if($guestLastName){
|
500 |
+
$merge_vars['LNAME'] = $guestLastName;
|
501 |
+
}
|
502 |
+
}
|
503 |
+
//GUEST
|
504 |
+
|
505 |
+
if($includeEmail){
|
506 |
+
$merge_vars['EMAIL'] = $customer->getEmail();
|
507 |
+
}
|
508 |
+
|
509 |
+
$groups = $customer->getListGroups();
|
510 |
+
$groupings = array();
|
511 |
+
if(is_array($groups) && count($groups)){
|
512 |
+
foreach($groups as $groupId => $grupoptions){
|
513 |
+
$groupings[] = array(
|
514 |
+
'id' => $groupId,
|
515 |
+
'groups' => (is_array($grupoptions) ? implode(', ', $grupoptions) : $grupoptions)
|
516 |
+
);
|
517 |
+
}
|
518 |
+
}
|
519 |
+
|
520 |
+
//Add customer group for logged in customers
|
521 |
+
if( $customer->getId() && $customer->getMcListId()){
|
522 |
+
|
523 |
+
$groupId = (int)Mage::getStoreConfig("monkey/groupings/list_" . $customer->getMcListId(), $customer->getStoreId());
|
524 |
+
if($groupId){
|
525 |
+
$groups = Mage::helper('customer')->getGroups()->toOptionHash();
|
526 |
+
$groupings[] = array(
|
527 |
+
'id' => $groupId,
|
528 |
+
'groups' => $groups[$customer->getGroupId()],
|
529 |
+
);
|
530 |
+
}
|
531 |
+
|
532 |
+
}
|
533 |
+
|
534 |
+
$merge_vars['GROUPINGS'] = $groupings;
|
535 |
+
|
536 |
+
//magemonkey_mergevars_after
|
537 |
+
$blank = new Varien_Object;
|
538 |
+
Mage::dispatchEvent('magemonkey_mergevars_after',
|
539 |
+
array('vars' => $merge_vars, 'customer' => $customer, 'newvars' => $blank));
|
540 |
+
if($blank->hasData()){
|
541 |
+
$merge_vars = array_merge($merge_vars, $blank->toArray());
|
542 |
+
}
|
543 |
+
//magemonkey_mergevars_after
|
544 |
+
|
545 |
+
return $merge_vars;
|
546 |
+
}
|
547 |
+
|
548 |
+
/**
|
549 |
+
* Register on Magento's registry GUEST customer data for MergeVars for on checkout subscribe
|
550 |
+
*
|
551 |
+
* @param Mage_Sales_Model_Order $order
|
552 |
+
* @return void
|
553 |
+
*/
|
554 |
+
public function registerGuestCustomer($order)
|
555 |
+
{
|
556 |
+
|
557 |
+
if( Mage::registry('mc_guest_customer') ){
|
558 |
+
return;
|
559 |
+
}
|
560 |
+
|
561 |
+
$customer = new Varien_Object;
|
562 |
+
|
563 |
+
$customer->setId('guest' . time());
|
564 |
+
$customer->setEmail($order->getBillingAddress()->getEmail());
|
565 |
+
$customer->setStoreId($order->getStoreId());
|
566 |
+
$customer->setFirstname($order->getBillingAddress()->getFirstname());
|
567 |
+
$customer->setLastname($order->getBillingAddress()->getLastname());
|
568 |
+
$customer->setPrimaryBillingAddress($order->getBillingAddress());
|
569 |
+
$customer->setPrimaryShippingAddress($order->getShippingAddress());
|
570 |
+
|
571 |
+
Mage::register('mc_guest_customer', $customer, TRUE);
|
572 |
+
|
573 |
+
}
|
574 |
+
|
575 |
+
|
576 |
+
/**
|
577 |
+
* Create a Magento's customer account for given data
|
578 |
+
*
|
579 |
+
* @param array $accountData
|
580 |
+
* @param integer $websiteId ID of website to associate customer to
|
581 |
+
* @return Mage_Customer_Model_Customer
|
582 |
+
*/
|
583 |
+
public function createCustomerAccount($accountData, $websiteId)
|
584 |
+
{
|
585 |
+
$customer = Mage::getModel('customer/customer')->setWebsiteId($websiteId);
|
586 |
+
|
587 |
+
if(!isset($accountData['firstname']) OR empty($accountData['firstname'])){
|
588 |
+
$accountData['firstname'] = $this->__('Store');
|
589 |
+
}
|
590 |
+
if(!isset($accountData['lastname']) OR empty($accountData['lastname'])){
|
591 |
+
$accountData['lastname'] = $this->__('Guest');
|
592 |
+
}
|
593 |
+
|
594 |
+
$customerForm = Mage::getModel('customer/form');
|
595 |
+
$customerForm->setFormCode('customer_account_create')
|
596 |
+
->setEntity($customer)
|
597 |
+
->initDefaultValues();
|
598 |
+
// emulate request
|
599 |
+
$request = $customerForm->prepareRequest($accountData);
|
600 |
+
$customerData = $customerForm->extractData($request);
|
601 |
+
$customerForm->restoreData($customerData);
|
602 |
+
|
603 |
+
$customerErrors = $customerForm->validateData($customerData);
|
604 |
+
|
605 |
+
if($customerErrors){
|
606 |
+
$customerForm->compactData($customerData);
|
607 |
+
|
608 |
+
$pwd = $customer->generatePassword(8);
|
609 |
+
$customer->setPassword($pwd);
|
610 |
+
$customer->setConfirmation($pwd);
|
611 |
+
|
612 |
+
|
613 |
+
/**
|
614 |
+
* Handle Address related Data
|
615 |
+
*/
|
616 |
+
$billing = $shipping = null;
|
617 |
+
if(isset($accountData['billing_address']) && !empty($accountData['billing_address'])){
|
618 |
+
$this->_McAddressToMage($accountData, 'billing', $customer);
|
619 |
+
}
|
620 |
+
if(isset($accountData['shipping_address']) && !empty($accountData['shipping_address'])){
|
621 |
+
$this->_McAddressToMage($accountData, 'shipping', $customer);
|
622 |
+
}
|
623 |
+
/**
|
624 |
+
* Handle Address related Data
|
625 |
+
*/
|
626 |
+
|
627 |
+
$customerErrors = $customer->validate();
|
628 |
+
if (is_array($customerErrors) && count($customerErrors)) {
|
629 |
+
|
630 |
+
//TODO: Do something with errors.
|
631 |
+
|
632 |
+
}else{
|
633 |
+
$customer->save();
|
634 |
+
|
635 |
+
if ( $customer->isConfirmationRequired() ){
|
636 |
+
$customer->sendNewAccountEmail('confirmation');
|
637 |
+
}
|
638 |
+
|
639 |
+
}
|
640 |
+
}
|
641 |
+
|
642 |
+
return $customer;
|
643 |
+
}
|
644 |
+
|
645 |
+
/**
|
646 |
+
* Parse MailChimp <address> MergeField type to Magento's address object
|
647 |
+
*
|
648 |
+
* @param array $data MC address data
|
649 |
+
* @param string $type billing or shipping
|
650 |
+
* @param Mage_Customer_Model_Customer $customer
|
651 |
+
* @return array Empty if noy errors, or a list of errors in an Array
|
652 |
+
*/
|
653 |
+
protected function _McAddressToMage(array $data, $type, $customer)
|
654 |
+
{
|
655 |
+
$addressData = $data["{$type}_address"];
|
656 |
+
$address = explode(str_repeat(chr(32), 2), $addressData);
|
657 |
+
list($addr1, $addr2, $city, $state, $zip, $country) = $address;
|
658 |
+
|
659 |
+
$region = Mage::getModel('directory/region')->loadByName($state, $country);
|
660 |
+
|
661 |
+
$mgAddress = array(
|
662 |
+
'firstname' => $data['firstname'],
|
663 |
+
'lastname' => $data['lastname'],
|
664 |
+
'street' => array($addr1, $addr2),
|
665 |
+
'city' => $city,
|
666 |
+
'country_id' => $country,
|
667 |
+
'region' => $state,
|
668 |
+
'region_id' => (!is_null($region->getId()) ? $region->getId() : null),
|
669 |
+
'postcode' => $zip,
|
670 |
+
'telephone' => 'not_provided',
|
671 |
+
);
|
672 |
+
|
673 |
+
/* @var $address Mage_Customer_Model_Address */
|
674 |
+
$address = Mage::getModel('customer/address');
|
675 |
+
/* @var $addressForm Mage_Customer_Model_Form */
|
676 |
+
$addressForm = Mage::getModel('customer/form');
|
677 |
+
$addressForm->setFormCode('customer_register_address')
|
678 |
+
->setEntity($address);
|
679 |
+
|
680 |
+
$addrrequest = $addressForm->prepareRequest($mgAddress);
|
681 |
+
$addressData = $addressForm->extractData($addrrequest);
|
682 |
+
$addressErrors = $addressForm->validateData($addressData);
|
683 |
+
|
684 |
+
$errors = array();
|
685 |
+
if ($addressErrors === true) {
|
686 |
+
$address->setId(null)
|
687 |
+
->setData("is_default_{$type}", TRUE);
|
688 |
+
$addressForm->compactData($addressData);
|
689 |
+
$customer->addAddress($address);
|
690 |
+
|
691 |
+
$addressErrors = $address->validate();
|
692 |
+
if (is_array($addressErrors)) {
|
693 |
+
$errors = array_merge($errors, $addressErrors);
|
694 |
+
}
|
695 |
+
} else {
|
696 |
+
$errors = array_merge($errors, $addressErrors);
|
697 |
+
}
|
698 |
+
|
699 |
+
return $errors;
|
700 |
+
}
|
701 |
+
|
702 |
+
/**
|
703 |
+
* Handle additional lists subscription on form posts like Customer Create Account
|
704 |
+
*
|
705 |
+
* @param Mage_Customer_Model_Customer $customer
|
706 |
+
*/
|
707 |
+
public function additionalListsSubscription($customer = null, $post = null)
|
708 |
+
{
|
709 |
+
$request = Mage::app()->getRequest();
|
710 |
+
|
711 |
+
if( !$request->isPost() && is_null($post) ){
|
712 |
+
return false;
|
713 |
+
}
|
714 |
+
|
715 |
+
$allowedPost = array('/customer/account/createpost/');
|
716 |
+
$requestString = $request->getRequestString();
|
717 |
+
|
718 |
+
if( in_array($requestString, $allowedPost) OR !is_null($post) ){
|
719 |
+
if(!is_null($post)){
|
720 |
+
$request = $post;
|
721 |
+
}
|
722 |
+
$this->handlePost($request, $customer->getEmail());
|
723 |
+
}
|
724 |
+
|
725 |
+
}
|
726 |
+
|
727 |
+
/**
|
728 |
+
* Handle subscription posts, (additional lists)
|
729 |
+
*
|
730 |
+
* @param Mage_Core_Controller_Request_Http $request
|
731 |
+
* @param string $guestEmail
|
732 |
+
* @return void
|
733 |
+
*/
|
734 |
+
public function handlePost($request, $guestEmail)
|
735 |
+
{
|
736 |
+
//<state> param is an html serialized field containing the default form state
|
737 |
+
//before submission, we need to parse it as a request in order to save it to $odata and process it
|
738 |
+
parse_str($request->getPost('state'), $odata);
|
739 |
+
|
740 |
+
$curlists = (TRUE === array_key_exists('list', $odata)) ? $odata['list'] : array();
|
741 |
+
$lists = $request->getPost('list', array());
|
742 |
+
|
743 |
+
$defaultList = $this->getDefaultList(Mage::app()->getStore());
|
744 |
+
|
745 |
+
$api = Mage::getSingleton('monkey/api');
|
746 |
+
$customer = Mage::helper('customer')->getCustomer();
|
747 |
+
$email = $guestEmail ? $guestEmail : $customer->getEmail();
|
748 |
+
|
749 |
+
$loggedIn = Mage::helper('customer')->isLoggedIn();
|
750 |
+
|
751 |
+
if( !empty($curlists) ){
|
752 |
+
|
753 |
+
//Handle Unsubscribe and groups update actions
|
754 |
+
foreach($curlists as $listId => $list){
|
755 |
+
|
756 |
+
if(FALSE === array_key_exists($listId, $lists)){
|
757 |
+
|
758 |
+
//Unsubscribe Email
|
759 |
+
if($defaultList == $listId){
|
760 |
+
|
761 |
+
$item = Mage::getModel('monkey/monkey')->loadByEmail($email);
|
762 |
+
if(!$item->getId()){
|
763 |
+
$item = Mage::getModel('newsletter/subscriber')
|
764 |
+
->loadByEmail($email);
|
765 |
+
}
|
766 |
+
if($item->getSubscriberEmail()){
|
767 |
+
$item->unsubscribe();
|
768 |
+
}
|
769 |
+
|
770 |
+
}else{
|
771 |
+
//Unsubscribe Email
|
772 |
+
$api->listUnsubscribe($listId, $email);
|
773 |
+
}
|
774 |
+
|
775 |
+
}else{
|
776 |
+
|
777 |
+
$groupings = $lists[$listId];
|
778 |
+
unset($groupings['subscribed']);
|
779 |
+
$customerLists = $api->listMemberInfo($listId,$email);
|
780 |
+
$customerLists = isset($customerLists['data'][0]['merges']['GROUPINGS']) ?$customerLists['data'][0]['merges']['GROUPINGS'] :array();
|
781 |
+
|
782 |
+
foreach ($customerLists as $clkey => $cl)
|
783 |
+
{
|
784 |
+
if (!isset($groupings[$cl['id']]))
|
785 |
+
{
|
786 |
+
$groupings[$cl['id']][] = '';
|
787 |
+
}
|
788 |
+
}
|
789 |
+
|
790 |
+
$customer->setMcListId($listId);
|
791 |
+
$customer->setListGroups($groupings);
|
792 |
+
$mergeVars = Mage::helper('monkey')->getMergeVars($customer);
|
793 |
+
|
794 |
+
//Handle groups update
|
795 |
+
$api->listUpdateMember($listId, $email, $mergeVars);
|
796 |
+
|
797 |
+
}
|
798 |
+
|
799 |
+
}
|
800 |
+
|
801 |
+
}
|
802 |
+
|
803 |
+
//Subscribe to new lists
|
804 |
+
if(is_array($lists) && is_array($curlists)){
|
805 |
+
$subscribe = array_diff_key($lists, $curlists);
|
806 |
+
if( !empty($subscribe) ){
|
807 |
+
|
808 |
+
foreach($subscribe as $listId => $slist){
|
809 |
+
|
810 |
+
if(!isset($slist['subscribed'])){
|
811 |
+
continue;
|
812 |
+
}
|
813 |
+
|
814 |
+
$groupings = $lists[$listId];
|
815 |
+
unset($groupings['subscribed']);
|
816 |
+
|
817 |
+
if($defaultList == $listId){
|
818 |
+
$subscriber = Mage::getModel('newsletter/subscriber');
|
819 |
+
|
820 |
+
$subscriber->setListGroups($groupings);
|
821 |
+
$subscriber->setMcListId($listId);
|
822 |
+
$subscriber->setMcStoreId(Mage::app()->getStore()->getId());
|
823 |
+
|
824 |
+
$subscriber->subscribe($email);
|
825 |
+
}else{
|
826 |
+
|
827 |
+
$customer->setListGroups($groupings);
|
828 |
+
$customer->setMcListId($listId);
|
829 |
+
$mergeVars = Mage::helper('monkey')->getMergeVars($customer);
|
830 |
+
$api->listSubscribe($listId, $email, $mergeVars, 'html', ($loggedIn ? false : true));
|
831 |
+
|
832 |
+
}
|
833 |
+
|
834 |
+
}
|
835 |
+
|
836 |
+
}
|
837 |
+
}
|
838 |
+
}
|
839 |
+
}
|
app/code/local/ThiagoSantos/LoginAutomatico/Model/Pageload/Observer.php
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class ThiagoSantos_LoginAutomatico_Model_Pageload_Observer {
|
4 |
+
|
5 |
+
public function __construct() {
|
6 |
+
// echo "thiago";
|
7 |
+
}
|
8 |
+
|
9 |
+
protected function _getSession() {
|
10 |
+
return Mage::getSingleton('customer/session');
|
11 |
+
}
|
12 |
+
|
13 |
+
protected function getRequest(){
|
14 |
+
return Mage::app()->getRequest();
|
15 |
+
}
|
16 |
+
|
17 |
+
/**
|
18 |
+
* _init manager referer information from the user
|
19 |
+
* @param Varien_Event_Observer $observer
|
20 |
+
* @return Xyz_Catalog_Model_Price_Observer
|
21 |
+
*/
|
22 |
+
public function _init($observer) {
|
23 |
+
|
24 |
+
$session = $this -> _getSession();
|
25 |
+
$id = $this -> getRequest() -> getParam('c');
|
26 |
+
$url = $this -> getRequest() -> getParam('r');
|
27 |
+
$store = $this -> getRequest() -> getParam('___store');
|
28 |
+
|
29 |
+
if (!isset($id)) {
|
30 |
+
$session -> addError('Parameter invalid or nonexistent user.');
|
31 |
+
}
|
32 |
+
|
33 |
+
//0 - id //1 - email
|
34 |
+
$csv = Mage::helper('loginautomatico') -> decrypt($id);
|
35 |
+
$_customerinfo = explode(';', $csv);
|
36 |
+
|
37 |
+
$customer = Mage::getModel('customer/customer') -> load($_customerinfo[0]);
|
38 |
+
|
39 |
+
//Verifica se o email bate com o email que foi criptografado
|
40 |
+
if (!$customer -> getId() || $customer -> getEmail() != trim($_customerinfo[1])) {
|
41 |
+
$session -> addError('Usuário inválido ou inexistente');
|
42 |
+
//$this -> _redirect('/');
|
43 |
+
}
|
44 |
+
|
45 |
+
$session = Mage::getSingleton('customer/session');
|
46 |
+
//logout - necessário!
|
47 |
+
$session -> logout();
|
48 |
+
//logando novamente
|
49 |
+
$session -> setCustomer($customer);
|
50 |
+
|
51 |
+
}
|
52 |
+
|
53 |
+
}
|
app/code/local/ThiagoSantos/LoginAutomatico/controllers/AController.php
ADDED
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Pereira, Thiago Santos
|
4 |
+
* http://thiagosantos.com/
|
5 |
+
*
|
6 |
+
* @category ThiagoSantos
|
7 |
+
* @package ThiagoSantos_LoginAutomatico
|
8 |
+
*
|
9 |
+
* Login Automatico
|
10 |
+
* Expectativa de URL:
|
11 |
+
* http://www.xxxxxx.com.br/la/a/do/?c=7iz3Sh0HXU6jxm2Y%2BBK%2BuXOfUSZylG7mZ7ngoZab1Y4%3D&___store=default&r=http://xxxx.com.br/
|
12 |
+
* @param c Equivale ao codigo criptografado pelo Helper do LoginAutomatico
|
13 |
+
* @param ___store Store id
|
14 |
+
* @param r Se necessário, url para redirecionar o usuário caso seja necessário
|
15 |
+
* @todo Parametros do Google Analytics no pelo sistema.
|
16 |
+
*
|
17 |
+
*/
|
18 |
+
|
19 |
+
class ThiagoSantos_LoginAutomatico_AController extends Mage_Core_Controller_Front_Action {
|
20 |
+
|
21 |
+
private $__getVars = array('c', //hash
|
22 |
+
'r', //redirect url
|
23 |
+
'___store'); //store id
|
24 |
+
|
25 |
+
protected function _getSession() {
|
26 |
+
return Mage::getSingleton('customer/session');
|
27 |
+
}
|
28 |
+
|
29 |
+
/**
|
30 |
+
* Delega para o accessAction
|
31 |
+
*/
|
32 |
+
public function doAction() {
|
33 |
+
|
34 |
+
$this -> accessAction();
|
35 |
+
|
36 |
+
}
|
37 |
+
|
38 |
+
public function _redirect($url,$params) {
|
39 |
+
header('location: ' . $url);
|
40 |
+
}
|
41 |
+
|
42 |
+
/**
|
43 |
+
* Converte o parametro, loga o usuário, redireciona para o /checkou/cart com o
|
44 |
+
* carrinho abandonado
|
45 |
+
*/
|
46 |
+
public function accessAction() {
|
47 |
+
|
48 |
+
//
|
49 |
+
$session = $this -> _getSession();
|
50 |
+
|
51 |
+
$id = $this -> getRequest() -> getParam('c');
|
52 |
+
$url = $this -> getRequest() -> getParam('r');
|
53 |
+
$store = $this -> getRequest() -> getParam('___store');
|
54 |
+
|
55 |
+
|
56 |
+
if (!isset($id)) {
|
57 |
+
$session -> addError('Parametro inválido ou usuário inexistente.');
|
58 |
+
$this -> _redirect('/');
|
59 |
+
}
|
60 |
+
|
61 |
+
//0 - id //1 - email
|
62 |
+
$csv = Mage::helper('loginautomatico') -> decrypt($id);
|
63 |
+
$_customerinfo = explode(';', $csv);
|
64 |
+
|
65 |
+
$customer = Mage::getModel('customer/customer') -> load($_customerinfo[0]);
|
66 |
+
|
67 |
+
//Verifica se o email bate com o email que foi criptografado
|
68 |
+
if (!$customer -> getId() || $customer -> getEmail() != trim($_customerinfo[1])) {
|
69 |
+
$session -> addError('Usuário inválido ou inexistente');
|
70 |
+
$this -> _redirect('/');
|
71 |
+
}
|
72 |
+
$session = Mage::getSingleton('customer/session');
|
73 |
+
//logout - necessário!
|
74 |
+
$session -> logout();
|
75 |
+
//logando novamente
|
76 |
+
$session -> setCustomer($customer);
|
77 |
+
|
78 |
+
//Campanhas do Google Analytics
|
79 |
+
//redirect
|
80 |
+
//?utm_source=carrinho_abandonado&utm_medium=email&utm_campaign=Carrinho%2BAbandonado
|
81 |
+
|
82 |
+
//$_params = array('_query' => array( 'utm_source' => 'mailchimp', 'utm_medium' => 'email', 'utm_campaign' => 'Login%2BAutomatico', '___store' => $store, ));
|
83 |
+
$_params = array();
|
84 |
+
if (isset($url)) {
|
85 |
+
$this -> _redirect($url, $_params);
|
86 |
+
exit();
|
87 |
+
}
|
88 |
+
|
89 |
+
$this -> _redirect("/", $_params);
|
90 |
+
exit();
|
91 |
+
}
|
92 |
+
|
93 |
+
}
|
app/code/local/ThiagoSantos/LoginAutomatico/etc/config.xml
ADDED
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<!--
|
3 |
+
/**
|
4 |
+
* Pereira, Thiago Santos
|
5 |
+
* http://thiagosantos.com/
|
6 |
+
*
|
7 |
+
* @category ThiagoSantos
|
8 |
+
* @package ThiagoSantos_LoginAutomatico
|
9 |
+
*/
|
10 |
+
-->
|
11 |
+
<config>
|
12 |
+
<modules>
|
13 |
+
<ThiagoSantos_LoginAutomatico>
|
14 |
+
<version>0.0.21</version>
|
15 |
+
</ThiagoSantos_LoginAutomatico>
|
16 |
+
</modules>
|
17 |
+
<global>
|
18 |
+
<helpers>
|
19 |
+
<loginautomatico>
|
20 |
+
<class>ThiagoSantos_LoginAutomatico_Helper</class>
|
21 |
+
</loginautomatico>
|
22 |
+
<monkey>
|
23 |
+
<rewrite>
|
24 |
+
<data>ThiagoSantos_LoginAutomatico_Helper_MonkeyData</data>
|
25 |
+
</rewrite>
|
26 |
+
</monkey>
|
27 |
+
</helpers>
|
28 |
+
<models>
|
29 |
+
<loginautomatico>
|
30 |
+
<class>ThiagoSantos_LoginAutomatico_Model</class>
|
31 |
+
</loginautomatico>
|
32 |
+
</models>
|
33 |
+
<!-- Eventos -->
|
34 |
+
<events>
|
35 |
+
<controller_action_layout_render_before>
|
36 |
+
<observers>
|
37 |
+
<thiagosantos_loginautomatico_pageload_observer>
|
38 |
+
<type>singleton</type>
|
39 |
+
<class>ThiagoSantos_LoginAutomatico_Model_Pageload_Observer</class>
|
40 |
+
<method>_init</method>
|
41 |
+
</thiagosantos_loginautomatico_pageload_observer>
|
42 |
+
</observers>
|
43 |
+
</controller_action_layout_render_before>
|
44 |
+
</events>
|
45 |
+
</global>
|
46 |
+
<frontend>
|
47 |
+
<routers>
|
48 |
+
<loginautomatico>
|
49 |
+
<use>standard</use>
|
50 |
+
<args>
|
51 |
+
<module>ThiagoSantos_LoginAutomatico</module>
|
52 |
+
<frontName>la</frontName>
|
53 |
+
</args>
|
54 |
+
</loginautomatico>
|
55 |
+
</routers>
|
56 |
+
</frontend>
|
57 |
+
|
58 |
+
</config>
|
app/etc/modules/ThiagoSantos_LoginAutomatico.xml
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<!--
|
3 |
+
/**
|
4 |
+
* Pereira, Thiago Santos
|
5 |
+
* http://thiagosantos.com/
|
6 |
+
*
|
7 |
+
* @category ThiagoSantos
|
8 |
+
* @package ThiagoSantos_LoginAutomatico
|
9 |
+
*/
|
10 |
+
-->
|
11 |
+
<config>
|
12 |
+
<modules>
|
13 |
+
<ThiagoSantos_LoginAutomatico>
|
14 |
+
<active>true</active>
|
15 |
+
<codePool>local</codePool>
|
16 |
+
</ThiagoSantos_LoginAutomatico>
|
17 |
+
</modules>
|
18 |
+
</config>
|
package.xml
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<package>
|
3 |
+
<name>TS_Auto_Login_MailChimp</name>
|
4 |
+
<version>1.0.21</version>
|
5 |
+
<stability>stable</stability>
|
6 |
+
<license>GNU General Public License</license>
|
7 |
+
<channel>community</channel>
|
8 |
+
<extends/>
|
9 |
+
<summary>Auto login for MailChimp on Magento Store</summary>
|
10 |
+
<description>With this extension you will be able to export a custom Merge Tag for MailChimp and use as a parameters to logged in your customer on you store. This extesion use Magento Crypt to crypt and decrypt the value of the Merge Tag. For those dont know about it, each Magento installation have a unique phrase used to crypt some data. So "thiagosantos" string crypted using my Magento instalation will have a diferent return string, of doing the same on your own store. This make my extension much secured and very usefull.</description>
|
11 |
+
<notes>Now its possible to log in on Magento through a simple url not need anymore to link to the controller.
|
12 |
+

|
13 |
+
Update with the last version of Ebizmarts 1.0.21.
|
14 |
+
</notes>
|
15 |
+
<authors><author><name>Thiago Santos</name><user>thiagosantos</user><email>thiagorow@gmail.com</email></author></authors>
|
16 |
+
<date>2012-09-24</date>
|
17 |
+
<time>18:45:00</time>
|
18 |
+
<contents><target name="magelocal"><dir name="ThiagoSantos"><dir name="LoginAutomatico"><dir name="Helper"><file name="Data.php" hash="16e7f6ff44e1b4b2d232bebb5ea796e7"/><file name="MonkeyData.php" hash="689e322b12f84b75c161323ba26853e1"/></dir><dir name="Model"><dir name="Pageload"><file name="Observer.php" hash="6b72ed7efccb88dc4809f75e71bd6e10"/></dir></dir><dir name="controllers"><file name="AController.php" hash="ac825fbe7d20a48094b838d8bdd45a9b"/></dir><dir name="etc"><file name="config.xml" hash="3648f71839bf96a387702dda6dae9d8a"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="ThiagoSantos_LoginAutomatico.xml" hash="0329b656ce44c8b877d5ff267fbd2406"/></dir></target></contents>
|
19 |
+
<compatible/>
|
20 |
+
<dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php><package><name>Ebizmarts_MageMonkey</name><channel>community</channel><min>1.0.15</min><max>1.0.21</max></package></required></dependencies>
|
21 |
+
</package>
|