edroneCRM - Version 1.1.14

Version Notes

edrone magento module - initial public release

Download this release

Release Info

Developer Michał Blak
Extension edroneCRM
Version 1.1.14
Comparing to
See all releases


Code changes from version 1.0.12 to 1.1.14

app/code/local/Edrone/Base/Block/Order.php CHANGED
@@ -292,7 +292,7 @@ class EdroneIns{
292
  * @param string $trace_url def https://api.edrone.me/trace
293
  * @since 1.0.0
294
  */
295
- function __construct($appid,$secret,$trace_url='https://api-test.edrone.me/trace.php'){
296
  $this->appid = $appid;
297
  $this->secret = $secret;
298
  $this->trace_url = $trace_url;
292
  * @param string $trace_url def https://api.edrone.me/trace
293
  * @since 1.0.0
294
  */
295
+ function __construct($appid,$secret,$trace_url='https://api.edrone.me/trace.php'){
296
  $this->appid = $appid;
297
  $this->secret = $secret;
298
  $this->trace_url = $trace_url;
app/code/local/Edrone/Base/Model/Observer.php CHANGED
@@ -1,22 +1,720 @@
1
  <?php
2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  class Edrone_Base_Model_Observer
4
  {
 
5
  public function addToCart()
6
  {
7
  $product = Mage::getModel('catalog/product')
8
- ->load(Mage::app()->getRequest()->getParam('product', 0));
9
 
10
  if (!$product->getId()) {
11
  return;
12
  }
13
 
14
  Mage::getModel('core/session')->setProductToShoppingCart(
15
- new Varien_Object(array(
16
- 'sku' => $product->getSku(),
17
- 'title' => $product->getName(),
18
- 'image' => (string)Mage::helper('catalog/image')->init($product, 'image')->resize(438),
19
- ))
20
  );
21
  }
22
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  <?php
2
 
3
+ //Check included serverside components
4
+ if (!defined('EDRONE_SDK_VERSION')) {
5
+ define('EDRONE_SDK_VERSION', 'PHPSDK_1.0.0');
6
+
7
+ abstract class EdroneEvent
8
+ {
9
+
10
+ protected $field = array();
11
+
12
+ abstract public function init();
13
+
14
+ public function pre_init()
15
+ {
16
+ //preInitObject
17
+ }
18
+
19
+ public function userCid($value)
20
+ {
21
+ $this->field['c_id'] = trim('phpsd_' . $value);
22
+ }
23
+
24
+ public function userEmail($value)
25
+ {
26
+ $this->field['email'] = trim($value);
27
+ }
28
+
29
+ public function userFirstName($value)
30
+ {
31
+ $this->field['first_name'] = trim($value);
32
+ }
33
+
34
+ public function userLastName($value)
35
+ {
36
+ $this->field['last_name'] = trim($value);
37
+ }
38
+
39
+ public function userSubscriberStatus($value)
40
+ {
41
+ $this->field['subscriber_status'] = trim($value);
42
+ }
43
+
44
+ public function userCountry($value)
45
+ {
46
+ $this->field['country'] = trim($value);
47
+ }
48
+
49
+ public function userCity($value)
50
+ {
51
+ $this->field['city'] = trim($value);
52
+ }
53
+
54
+ public function userPhone($value)
55
+ {
56
+ $this->field['phone'] = trim($value);
57
+ }
58
+
59
+ public function userTag($value)
60
+ {
61
+ $this->field['customer_tags'] = trim($value);
62
+ }
63
+
64
+ public function get()
65
+ {
66
+ return $this->field;
67
+ return $this;
68
+ }
69
+
70
+ }
71
+
72
+ class EdroneEventSubscribe extends EdroneEvent
73
+ {
74
+
75
+ public function init()
76
+ {
77
+ $this->field['action_type'] = 'subscribe';
78
+ $this->field['customer_tags'] = 'From PopUp';
79
+ }
80
+ /**
81
+ *
82
+ * @param type $value
83
+ * @return \EdroneEventOrder
84
+ */
85
+ public function userCid($value)
86
+ {
87
+ parent::userCid($value);
88
+ return $this;
89
+ }
90
+
91
+ /**
92
+ *
93
+ * @param type $value
94
+ * @return \EdroneEventOrder
95
+ */
96
+ public function userEmail($value)
97
+ {
98
+ parent::userEmail($value);
99
+ return $this;
100
+ }
101
+
102
+ /**
103
+ *
104
+ * @param type $value
105
+ * @return \EdroneEventOrder
106
+ */
107
+ public function userFirstName($value)
108
+ {
109
+ parent::userFirstName($value);
110
+ return $this;
111
+ }
112
+
113
+ /**
114
+ *
115
+ * @param type $value
116
+ * @return \EdroneEventOrder
117
+ */
118
+ public function userLastName($value)
119
+ {
120
+ parent::userLastName($value);
121
+ return $this;
122
+ }
123
+
124
+ /**
125
+ *
126
+ * @param type $value
127
+ * @return \EdroneEventOrder
128
+ */
129
+ public function userSubscriberStatus($value)
130
+ {
131
+ parent::userSubscriberStatus($value);
132
+ return $this;
133
+ }
134
+
135
+ /**
136
+ *
137
+ * @param type $value
138
+ * @return \EdroneEventOrder
139
+ */
140
+ public function userCountry($value)
141
+ {
142
+ parent::userCountry($value);
143
+ return $this;
144
+ }
145
+
146
+ /**
147
+ *
148
+ * @param type $value
149
+ * @return \EdroneEventOrder
150
+ */
151
+ public function userCity($value)
152
+ {
153
+ parent::userCity($value);
154
+ return $this;
155
+ }
156
+
157
+ /**
158
+ *
159
+ * @param type $value
160
+ * @return \EdroneEventOrder
161
+ */
162
+ public function userOrder($value)
163
+ {
164
+ parent::userPhone($value);
165
+ return $this;
166
+ }
167
+
168
+ /**
169
+ *
170
+ * @param type $value
171
+ * @return \EdroneEventOther
172
+ */
173
+ public function userTag($value)
174
+ {
175
+ parent::userTag($value);
176
+ return $this;
177
+ }
178
+ /**
179
+ * @return EdroneEventOther
180
+ */
181
+ public static function create()
182
+ {
183
+ return new EdroneEventSubscribe();
184
+ }
185
+ }
186
+
187
+ class EdroneEventOrder extends EdroneEvent
188
+ {
189
+
190
+ public function init()
191
+ {
192
+ $this->field['action_type'] = 'order';
193
+ }
194
+
195
+ /**
196
+ *
197
+ * @param type $value
198
+ * @return \EdroneEventOrder
199
+ */
200
+ public function userCid($value)
201
+ {
202
+ parent::userCid($value);
203
+ return $this;
204
+ }
205
+
206
+ /**
207
+ *
208
+ * @param type $value
209
+ * @return \EdroneEventOrder
210
+ */
211
+ public function userEmail($value)
212
+ {
213
+ parent::userEmail($value);
214
+ return $this;
215
+ }
216
+
217
+ /**
218
+ *
219
+ * @param type $value
220
+ * @return \EdroneEventOrder
221
+ */
222
+ public function userFirstName($value)
223
+ {
224
+ parent::userFirstName($value);
225
+ return $this;
226
+ }
227
+
228
+ /**
229
+ *
230
+ * @param type $value
231
+ * @return \EdroneEventOrder
232
+ */
233
+ public function userLastName($value)
234
+ {
235
+ parent::userLastName($value);
236
+ return $this;
237
+ }
238
+
239
+ /**
240
+ *
241
+ * @param type $value
242
+ * @return \EdroneEventOrder
243
+ */
244
+ public function userSubscriberStatus($value)
245
+ {
246
+ parent::userSubscriberStatus($value);
247
+ return $this;
248
+ }
249
+
250
+ /**
251
+ *
252
+ * @param type $value
253
+ * @return \EdroneEventOrder
254
+ */
255
+ public function userCountry($value)
256
+ {
257
+ parent::userCountry($value);
258
+ return $this;
259
+ }
260
+
261
+ /**
262
+ *
263
+ * @param type $value
264
+ * @return \EdroneEventOrder
265
+ */
266
+ public function userCity($value)
267
+ {
268
+ parent::userCity($value);
269
+ return $this;
270
+ }
271
+
272
+ /**
273
+ *
274
+ * @param type $value
275
+ * @return \EdroneEventOrder
276
+ */
277
+ public function userOrder($value)
278
+ {
279
+ parent::userPhone($value);
280
+ return $this;
281
+ }
282
+
283
+ /**
284
+ *
285
+ * @param type $value
286
+ * @return \EdroneEventOther
287
+ */
288
+ public function userTag($value)
289
+ {
290
+ parent::userTag($value);
291
+ return $this;
292
+ }
293
+
294
+ /**
295
+ *
296
+ * @param type $value
297
+ * @return \EdroneEventOrder Description
298
+ */
299
+ public function productSkus($value)
300
+ {
301
+ if (is_array($value)) {
302
+ $value = implode('|', $value);
303
+ }
304
+ $this->field['product_skus'] = $value;
305
+ return $this;
306
+ }
307
+
308
+ /**
309
+ *
310
+ * @param type $value
311
+ * @return \EdroneEventOrder
312
+ */
313
+ public function productIds($value)
314
+ {
315
+ if (is_array($value)) {
316
+ $value = implode('|', $value);
317
+ }
318
+ $this->field['product_ids'] = $value;
319
+ return $this;
320
+ }
321
+
322
+ /**
323
+ *
324
+ * @param type $value
325
+ * @return \EdroneEventOrder
326
+ */
327
+ public function productTitles($value)
328
+ {
329
+ if (is_array($value)) {
330
+ $value = implode('|', $value);
331
+ }
332
+ $this->field['product_titles'] = $value;
333
+ return $this;
334
+ }
335
+
336
+ /**
337
+ *
338
+ * @param type $value
339
+ * @return \EdroneEventOrder
340
+ */
341
+ public function productImages($value)
342
+ {
343
+ if (is_array($value)) {
344
+ $value = implode('|', $value);
345
+ }
346
+ $this->field['product_images'] = $value;
347
+ return $this;
348
+ }
349
+
350
+ /**
351
+ *
352
+ * @param type $value
353
+ * @return \EdroneEventOrder
354
+ */
355
+ public function productUrls($value)
356
+ {
357
+ if (is_array($value)) {
358
+ $value = implode('|', $value);
359
+ }
360
+ $this->field['product_urls'] = $value;
361
+ return $this;
362
+ }
363
+
364
+ /**
365
+ *
366
+ * @param type $value
367
+ * @return \EdroneEventOrder
368
+ */
369
+ public function productCounts($value)
370
+ {
371
+ if (is_array($value)) {
372
+ $value = implode('|', $value);
373
+ }
374
+ $this->field['product_counts'] = $value;
375
+ return $this;
376
+ }
377
+
378
+ /**
379
+ *
380
+ * @param type $value
381
+ * @return \EdroneEventOrder
382
+ */
383
+ public function productCategoryIds($value)
384
+ {
385
+ if (is_array($value)) {
386
+ $value = implode('|', $value);
387
+ }
388
+ $this->field['product_category_ids'] = $value;
389
+ return $this;
390
+ }
391
+
392
+ /**
393
+ *
394
+ * @param type $value
395
+ * @return \EdroneEventOrder
396
+ */
397
+ public function productCategoryNames($value)
398
+ {
399
+ if (is_array($value)) {
400
+ $value = implode('|', $value);
401
+ }
402
+ $this->field['product_category_names'] = $value;
403
+ return $this;
404
+ }
405
+
406
+ public function orderId($value)
407
+ {
408
+ $this->field['order_id'] = $value;
409
+ return $this;
410
+ }
411
+
412
+ public function orderPaymentValue($value)
413
+ {
414
+ $this->field['order_payment_value'] = $value;
415
+ return $this;
416
+ }
417
+
418
+ public function orderBasePaymentValue($value)
419
+ {
420
+ $this->field['base_payment_value'] = $value;
421
+ return $this;
422
+ }
423
+
424
+ public function orderDetails($value)
425
+ {
426
+ $this->field['order_details'] = $value;
427
+ return $this;
428
+ }
429
+
430
+ public function orderCurrency($value)
431
+ {
432
+ $this->field['order_currency'] = $value;
433
+ return $this;
434
+ }
435
+
436
+ public function orderBaseCurrency($value)
437
+ {
438
+ $this->field['base_currency'] = $value;
439
+ return $this;
440
+ }
441
+
442
+ /**
443
+ * @return EdroneEventOrder
444
+ */
445
+ public static function create()
446
+ {
447
+ return new EdroneEventOrder();
448
+ }
449
+
450
+ }
451
+
452
+ class EdroneIns
453
+ {
454
+
455
+ /** @var string AppId */
456
+ private $appid = '';
457
+
458
+ /** @var string $secret Secret */
459
+ private $secret = '';
460
+
461
+ /** @var string Trace url. def https://api.edrone.me/trace */
462
+ private $trace_url = '';
463
+
464
+ /** @var array Array of request field */
465
+ private $fiels = array();
466
+
467
+ /** @var array Prepared request array */
468
+ private $preparedpack = array();
469
+
470
+ /** @var Closure Closure method called on error */
471
+ private $errorHandle = null;
472
+
473
+ /** @var Closure Closure method called on success */
474
+ private $readyHandle = null;
475
+
476
+ /** @var Array Last request information */
477
+ private $lastRequest = null;
478
+
479
+ /**
480
+ * Construct new Edrone Request instace
481
+ * @param string $appid AppId of tracker
482
+ * @param string $secret Secret of tracer
483
+ * @param string $trace_url def https://api.edrone.me/trace
484
+ * @since 1.0.0
485
+ */
486
+ function __construct($appid, $secret, $trace_url = 'https://api.edrone.me/trace.php')
487
+ {
488
+ $this->appid = $appid;
489
+ $this->secret = $secret;
490
+ $this->trace_url = $trace_url;
491
+ }
492
+
493
+ /**
494
+ *
495
+ * Prepare event to send
496
+ *
497
+ * @param EdroneEvent $event Use object of EdroneEventAddToCart,EdroneEventOrder,EdroneEventOrder,EdroneEventOther
498
+ * @return EdroneIns
499
+ * @since 1.0.0
500
+ */
501
+ public function prepare($event)
502
+ {
503
+ if (!($event instanceof EdroneEvent )) {
504
+ throw new Exception('Event must by child EdroneEvent class ');
505
+ $this->preparedpack = array();
506
+ return;
507
+ }
508
+ $event->pre_init();
509
+ $event->init();
510
+ $this->preparedpack = array_merge($event->get(), array(
511
+ "app_id" => $this->appid,
512
+ "version" => EDRONE_SDK_VERSION,
513
+ "sender_type" => 'server',
514
+ ));
515
+ //Calc sign - beta
516
+ ksort($this->preparedpack);
517
+ $sign = '';
518
+ foreach ($this->preparedpack as $key => $value) {
519
+ $sign .= $value;
520
+ }
521
+ $this->preparedpack['sign'] = md5($this->secret . $sign);
522
+ //
523
+ return $this;
524
+ }
525
+
526
+ /**
527
+ *
528
+ * Force send prepared data
529
+ * @since 1.0.0
530
+ */
531
+ public function send()
532
+ {
533
+ $ch = curl_init();
534
+ curl_setopt($ch, CURLOPT_URL, $this->trace_url);
535
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
536
+ curl_setopt($ch, CURLOPT_POST, 1);
537
+ curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($this->preparedpack));
538
+ curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3);
539
+ curl_setopt($ch, CURLOPT_TIMEOUT, 3);
540
+ $data = curl_exec($ch);
541
+ $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
542
+ $report = curl_getinfo($ch);
543
+ curl_close($ch);
544
+ $this->lastRequest = array("code" => $httpcode, "response" => $data, "info" => $report, 'fields' => $this->preparedpack);
545
+ if (($httpcode !== 200) && ($this->errorHandle !== null)) {
546
+ call_user_func_array($this->errorHandle, array($this));
547
+ } elseif (($httpcode === 200) && ($this->readyHandle !== null)) {
548
+ call_user_func_array($this->readyHandle, array($this));
549
+ }
550
+ }
551
+
552
+ /**
553
+ * Return last request as array (debug)
554
+ * @return array
555
+ * @since 1.0.0
556
+ */
557
+ public function getLastRequest()
558
+ {
559
+ return $this->lastRequest;
560
+ }
561
+
562
+ /**
563
+ * Set Callbacks for error action and ready action
564
+ * @param \Closure $errorHandle
565
+ * @param \Closure $readyHandle
566
+ * @since 1.0.0
567
+ */
568
+ public function setCallbacks($errorHandle = null, $readyHandle = null)
569
+ {
570
+ $this->errorHandle = $errorHandle;
571
+ $this->readyHandle = $readyHandle;
572
+ }
573
+
574
+ }
575
+
576
+ }
577
+
578
  class Edrone_Base_Model_Observer
579
  {
580
+
581
  public function addToCart()
582
  {
583
  $product = Mage::getModel('catalog/product')
584
+ ->load(Mage::app()->getRequest()->getParam('product', 0));
585
 
586
  if (!$product->getId()) {
587
  return;
588
  }
589
 
590
  Mage::getModel('core/session')->setProductToShoppingCart(
591
+ new Varien_Object(array(
592
+ 'sku' => $product->getSku(),
593
+ 'title' => $product->getName(),
594
+ 'image' => (string) Mage::helper('catalog/image')->init($product, 'image')->resize(438),
595
+ ))
596
  );
597
  }
598
+
599
+ private function getOrderData($order)
600
+ {
601
+
602
+ $orderData = array();
603
+ $customerData = array();
604
+ $product_category_names = array();
605
+ $product_category_ids = array();
606
+ $product_counts = array();
607
+
608
+
609
+ foreach ($order->getAllVisibleItems() as $item) {
610
+ $skus[] = $item->getSku();
611
+ $ids[] = $item->getId();
612
+ $titles[] = $item->getName();
613
+
614
+ $_Product = Mage::getModel("catalog/product")->load($item->getProductId());
615
+ $categoryIds = $_Product->getCategoryIds(); //array of product categories
616
+ $product_counts[] = settype($item->getQtyOrdered(), 'int');
617
+ $categoryId = array_pop($categoryIds);
618
+ if (is_numeric($categoryId)) {
619
+ $category = Mage::getModel('catalog/category')->load($categoryId);
620
+ $product_category_names[] = $category->getName();
621
+ $product_category_ids[] = $categoryId;
622
+ }
623
+
624
+
625
+ $product = $item->getProduct();
626
+ if ($product)
627
+ $images[] = (string) Mage::helper('catalog/image')->init($product, 'image')->resize(438);
628
+ }
629
+ $orderData['order_id'] = $order->getIncrementId();
630
+ $orderData['sku'] = join('|', $skus);
631
+ $orderData['id'] = join('|', $ids);
632
+ $orderData['title'] = join('|', $titles);
633
+ $orderData['image'] = join('|', $images);
634
+ $orderData['order_id'] = $order->getIncrementId();
635
+ $orderData['order_payment_value'] = $order->getGrandTotal();
636
+ $orderData['base_payment_value'] = $order->getBaseGrandTotal();
637
+ $orderData['base_currency'] = $order->getBaseCurrencyCode();
638
+ $orderData['order_currency'] = $order->getOrderCurrencyCode();
639
+ $orderData['coupon'] = $order->getCouponCode();
640
+ $orderData['product_category_names'] = join('|', $product_category_names);
641
+ $orderData['product_category_ids'] = join('|', $product_category_ids);
642
+ $orderData['product_counts'] = join('|', $product_counts);
643
+
644
+ $customerData['first_name'] = $order->getBillingAddress()->getFirstname();
645
+ $customerData['last_name'] = $order->getBillingAddress()->getLastname();
646
+ $customerData['email'] = $order->getBillingAddress()->getEmail();
647
+ $customerData['country'] = $order->getBillingAddress()->getCountry();
648
+ $customerData['city'] = $order->getBillingAddress()->getCity();
649
+ $customerData['phone'] = $order->getBillingAddress()->getTelephone();
650
+
651
+ return array($orderData, $customerData);
652
+ }
653
+
654
+ private function sendDataToServer($orderData, $customerData)
655
+ {
656
+ try {
657
+ $configHelper = Mage::helper('edrone/config');
658
+ $edrone = new EdroneIns($configHelper->getAppId(), '');
659
+ $edrone->setCallbacks(function($obj) {
660
+ error_log("EDRONEPHPSDK ERROR - wrong request:" . json_encode($obj->getLastRequest()));
661
+ }, function() {
662
+
663
+ });
664
+ $edrone->prepare(
665
+ EdroneEventOrder::create()->
666
+ userFirstName(($customerData['first_name']))->
667
+ userLastName(($customerData['last_name']))->
668
+ userEmail($customerData['email'])->
669
+ productSkus($orderData['sku'])->
670
+ productTitles($orderData['title'])->
671
+ productImages($orderData['image'])->
672
+ productCategoryIds($orderData['product_category_ids'])->
673
+ productCategoryNames($orderData['product_category_names'])->
674
+ orderId($orderData['order_id'])->
675
+ orderPaymentValue($orderData['order_payment_value'])->
676
+ orderCurrency($orderData['order_currency'])->
677
+ productCounts($orderData['product_counts'])
678
+ )->send();
679
+ } catch (Exception $e) {
680
+ error_log("EDRONEPHPSDK ERROR:" . $e->getMessage() . ' more :' . json_encode($e));
681
+ }
682
+ return json_encode($edrone->getLastRequest());
683
+ }
684
+
685
+ public function export_new_order($observer)
686
+ {
687
+ $order = $observer->getEvent()->getOrder();
688
+ $orderdata = $this->getOrderData($order);
689
+ $status = $this->sendDataToServer($orderdata[0], $orderdata[1]);
690
+
691
+ return $this;
692
+ }
693
+
694
+ public function newsletterSubscriberChange($observer)
695
+ {
696
+ $subscriber = $observer->getEvent()->getSubscriber();
697
+ $sub = 0;
698
+ if ($subscriber->isSubscribed()) {
699
+ $sub = 1;
700
+ $email = $subscriber->getEmail();
701
+ try {
702
+ $configHelper = Mage::helper('edrone/config');
703
+ $edrone = new EdroneIns($configHelper->getAppId(), '');
704
+ $edrone->setCallbacks(function($obj) {
705
+ error_log("EDRONEPHPSDK ERROR - wrong request:" . json_encode($obj->getLastRequest()));
706
+ }, function() {
707
+
708
+ });
709
+ $edrone->prepare(
710
+ EdroneEventSubscribe::create()->
711
+ userEmail($email)->
712
+ userSubscriberStatus($sub)
713
+ )->send();
714
+ } catch (Exception $e) {
715
+ error_log("EDRONEPHPSDK ERROR:" . $e->getMessage() . ' more :' . json_encode($e));
716
+ }
717
+ }
718
+ }
719
+
720
+ }
app/code/local/Edrone/Base/etc/config.xml CHANGED
@@ -2,7 +2,7 @@
2
  <config>
3
  <modules>
4
  <Edrone_Base>
5
- <version>1.0.10</version>
6
  </Edrone_Base>
7
  </modules>
8
  <global>
@@ -44,6 +44,26 @@
44
  </observers>
45
  </checkout_cart_product_add_after>
46
  </events>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  <routers>
48
  <edrone_newsletter>
49
  <use>standard</use>
2
  <config>
3
  <modules>
4
  <Edrone_Base>
5
+ <version>1.1.14</version>
6
  </Edrone_Base>
7
  </modules>
8
  <global>
44
  </observers>
45
  </checkout_cart_product_add_after>
46
  </events>
47
+ <events>
48
+ <sales_order_place_after>
49
+ <observers>
50
+ <edrone_order_observer>
51
+ <class>Edrone_Base_Model_Observer</class>
52
+ <method>export_new_order</method>
53
+ </edrone_order_observer>
54
+ </observers>
55
+ </sales_order_place_after>
56
+ </events>
57
+ <events>
58
+ <newsletter_subscriber_save_before>
59
+ <observers>
60
+ <edrone_subscriber_save_observer>
61
+ <class>Edrone_Base_Model_Observer</class>
62
+ <method>newsletterSubscriberChange</method>
63
+ </edrone_subscriber_save_observer>
64
+ </observers>
65
+ </newsletter_subscriber_save_before>
66
+ </events>
67
  <routers>
68
  <edrone_newsletter>
69
  <use>standard</use>
app/design/frontend/base/default/template/edrone/cart_view.phtml ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /* @var $this Edrone_Base_Block_Cart */
3
+ $helper = $this->getConfigHelper();
4
+ $helper2 = Mage::helper('edrone');
5
+ $customerData = $this->getCustomerData();
6
+ $productData = $this->getProductData();
7
+ ?>
8
+
9
+ <?php if(!empty($productData)): ?>
10
+ <script type="text/javascript">
11
+ (function (srcjs) {
12
+ window._edrone = window._edrone || {};
13
+ _edrone.app_id = '<?php echo $helper->getAppId() ?>';
14
+ _edrone.version = '1.1.14';
15
+ _edrone.platform = 'Magento';
16
+ _edrone.platform_version = '<?php echo Mage::getVersion(); ?>';
17
+ _edrone.trace_url = '<?php echo $helper->getCollectorUrl() ?>';
18
+ _edrone.is_logged_in = '<?php echo $customerData['is_logged_in'] ?>';
19
+ _edrone.email = '<?php echo $customerData['email'] ?>';
20
+ _edrone.phone = '<?php echo $customerData['phone'] ?>';
21
+ _edrone.first_name = '<?php echo urlencode($customerData['first_name']); ?>';
22
+ _edrone.last_name = '<?php echo urlencode($customerData['last_name']); ?>';
23
+ _edrone.product_skus = '<?php echo $productData['sku'] ?>';
24
+ _edrone.product_ids = '';
25
+ _edrone.product_titles = '<?php echo urlencode($productData['title']); ?>';
26
+ _edrone.product_images = '<?php echo urlencode($productData['image']); ?>';
27
+ _edrone.product_category_ids = '<?php echo $productData['product_category_ids'] ?>';
28
+ _edrone.product_category_names = '<?php echo urlencode($productData['product_category_names']); ?>';
29
+ _edrone.order_id = '';
30
+ _edrone.order_payment_value = '';
31
+ _edrone.currency = '';
32
+ _edrone.action_type = 'add_to_cart';
33
+ _edrone.country = '<?php echo $customerData['country'] ?>';
34
+ _edrone.city = '<?php echo urlencode($customerData['city']); ?>';
35
+ _edrone.subscriber_status = '<?php echo $customerData['subscriber_status'] ?>';
36
+ _edrone.utc_time = '<?php echo $helper2->utcNow() ?>';
37
+
38
+
39
+ var doc = document.createElement('script');
40
+ doc.type = 'text/javascript';
41
+ doc.async = true;
42
+ doc.src = ('https:' == document.location.protocol ? 'https:' : 'http:') + srcjs;
43
+ var s = document.getElementsByTagName('script')[0];
44
+ s.parentNode.insertBefore(doc, s);
45
+
46
+ })("<?php echo $helper->getExternalScriptUrl() ?>");
47
+ </script>
48
+ <?php endif; ?>
app/design/frontend/base/default/template/edrone/default.phtml ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /* @var $this Edrone_Base_Block_Base */
3
+ $helper = $this->getConfigHelper();
4
+ $helper2 = Mage::helper('edrone');
5
+ $customerData = $this->getCustomerData();
6
+ ?>
7
+
8
+ <script type="text/javascript">
9
+ (function (srcjs) {
10
+ window._edrone = window._edrone || {};
11
+ _edrone.app_id = '<?php echo $helper->getAppId() ?>';
12
+ _edrone.version = '1.1.14';
13
+ _edrone.platform = 'Magento';
14
+ _edrone.platform_version = '<?php echo Mage::getVersion(); ?>';
15
+ _edrone.trace_url = '<?php echo $helper->getCollectorUrl() ?>';
16
+ _edrone.is_logged_in = '<?php echo $customerData['is_logged_in'] ?>';
17
+ _edrone.email = '<?php echo $customerData['email'] ?>';
18
+ _edrone.phone = '<?php echo $customerData['phone'] ?>';
19
+ _edrone.first_name = '<?php echo urlencode($customerData['first_name']); ?>';
20
+ _edrone.last_name = '<?php echo urlencode($customerData['last_name']); ?>';
21
+ _edrone.product_skus = '';
22
+ _edrone.product_ids = '';
23
+ _edrone.product_titles = '';
24
+ _edrone.product_images = '';
25
+ _edrone.order_id = '';
26
+ _edrone.order_payment_value = '';
27
+ _edrone.currency = '';
28
+ _edrone.action_type = 'other';
29
+ _edrone.country = '<?php echo $customerData['country'] ?>';
30
+ _edrone.city = '<?php echo urlencode($customerData['city']); ?>';
31
+ _edrone.subscriber_status = '<?php echo $customerData['subscriber_status'] ?>';
32
+ _edrone.utc_time = '<?php echo $helper2->utcNow() ?>';
33
+
34
+ var doc = document.createElement('script');
35
+ doc.type = 'text/javascript';
36
+ doc.async = true;
37
+ doc.src = ('https:' == document.location.protocol ? 'https:' : 'http:') + srcjs;
38
+ var s = document.getElementsByTagName('script')[0];
39
+ s.parentNode.insertBefore(doc, s);
40
+
41
+ })("<?php echo $helper->getExternalScriptUrl() ?>");
42
+ </script>
app/design/frontend/base/default/template/edrone/product_view.phtml ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /* @var $this Edrone_Base_Block_Product */
3
+ $helper = $this->getConfigHelper();
4
+ $helper2 = Mage::helper('edrone');
5
+ $customerData = $this->getCustomerData();
6
+ $productData = $this->getProductData();
7
+ ?>
8
+
9
+ <script type="text/javascript">
10
+ (function (srcjs) {
11
+ window._edrone = window._edrone || {};
12
+ _edrone.app_id = '<?php echo $helper->getAppId() ?>';
13
+ _edrone.version = '1.1.14';
14
+ _edrone.platform = 'Magento';
15
+ _edrone.platform_version = '<?php echo Mage::getVersion(); ?>';
16
+ _edrone.trace_url = '<?php echo $helper->getCollectorUrl() ?>';
17
+ _edrone.is_logged_in = '<?php echo $customerData['is_logged_in'] ?>';
18
+ _edrone.email = '<?php echo $customerData['email'] ?>';
19
+ _edrone.phone = '<?php echo $customerData['phone'] ?>';
20
+ _edrone.first_name = '<?php echo urlencode($customerData['first_name']); ?>';
21
+ _edrone.last_name = '<?php echo urlencode($customerData['last_name']); ?>';
22
+ _edrone.product_skus = '<?php echo $productData['sku'] ?>';
23
+ _edrone.product_ids = '';
24
+ _edrone.product_titles = '<?php echo urlencode($productData['title']); ?>';
25
+ _edrone.product_images = '<?php echo urlencode($productData['image']); ?>';
26
+ _edrone.product_urls = '<?php echo $productData['product_url']?>';
27
+ _edrone.product_category_ids = '<?php echo $productData['product_category_ids'] ?>';
28
+ _edrone.product_category_names = '<?php echo urlencode($productData['product_category_names']); ?>';
29
+ _edrone.order_id = '';
30
+ _edrone.order_payment_value = '';
31
+ _edrone.currency = '';
32
+ _edrone.action_type = 'product_view';
33
+ _edrone.country = '<?php echo $customerData['country'] ?>';
34
+ _edrone.city = '<?php echo urlencode($customerData['city']); ?>';
35
+ _edrone.subscriber_status = '<?php echo $customerData['subscriber_status'] ?>';
36
+ _edrone.utc_time = '<?php echo $helper2->utcNow() ?>';
37
+
38
+ var doc = document.createElement('script');
39
+ doc.type = 'text/javascript';
40
+ doc.async = true;
41
+ doc.src = ('https:' == document.location.protocol ? 'https:' : 'http:') + srcjs;
42
+ var s = document.getElementsByTagName('script')[0];
43
+ s.parentNode.insertBefore(doc, s);
44
+
45
+ window.isBasketForm = function(find, txt) {
46
+ txt = txt.split("?")[0];
47
+ return txt.substr(txt.length - find.length) == find;
48
+ }
49
+
50
+ (function() {
51
+ var origOpen = XMLHttpRequest.prototype.open;
52
+ XMLHttpRequest.prototype.open = function() {
53
+ this.addEventListener('load', function() {
54
+ if (isBasketForm('ajaxcart/cart/add/', this.responseURL)) {
55
+ _edrone.action_type = "add_to_cart";
56
+ _edrone.init();
57
+ }
58
+ });
59
+ origOpen.apply(this, arguments);
60
+ };
61
+ })();
62
+
63
+
64
+ })("<?php echo $helper->getExternalScriptUrl() ?>");
65
+ </script>
app/design/frontend/base/default/template/edrone/success_view.phtml ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /* @var $this Edrone_Base_Block_Order */
3
+ $helper = $this->getConfigHelper();
4
+ $helper2 = Mage::helper('edrone');
5
+ $customerData = $this->getCustomerData();
6
+ $orderData = $this->getOrderData();
7
+ $this->sendDataToServer($orderData, $customerData);
8
+ ?>
9
+
10
+ <?php if(!empty($orderData)): ?>
11
+ <script type="text/javascript">
12
+ (function (srcjs) {
13
+ window._edrone = window._edrone || {};
14
+ _edrone.app_id = '<?php echo $helper->getAppId() ?>';
15
+ _edrone.version = '1.1.14';
16
+ _edrone.platform = 'Magento';
17
+ _edrone.platform_version = '<?php echo Mage::getVersion(); ?>';
18
+ _edrone.trace_url = '<?php echo $helper->getCollectorUrl() ?>';
19
+ _edrone.is_logged_in = '<?php echo $customerData['is_logged_in'] ?>';
20
+ _edrone.email = '<?php echo $customerData['email'] ?>';
21
+ _edrone.phone = '<?php echo $customerData['phone'] ?>';
22
+ _edrone.first_name = '<?php echo urlencode($customerData['first_name']); ?>';
23
+ _edrone.last_name = '<?php echo urlencode($customerData['last_name']); ?>';
24
+ _edrone.product_skus = '<?php echo $orderData['sku'] ?>';
25
+ _edrone.product_ids = '';
26
+ _edrone.product_titles = '<?php echo urlencode($orderData['title']); ?>';
27
+ _edrone.product_images = '<?php echo urlencode($orderData['image']); ?>';
28
+ _edrone.product_category_ids = '<?php echo $orderData['product_category_ids'] ?>';
29
+ _edrone.product_category_names = '<?php echo urlencode($orderData['product_category_names']); ?>';
30
+ _edrone.order_id = '<?php echo $orderData['order_id'] ?>';
31
+ _edrone.order_payment_value = '<?php echo $orderData['order_payment_value'] ?>';
32
+ _edrone.base_payment_value = '<?php echo $orderData['base_payment_value'] ?>';
33
+ _edrone.base_currency = '<?php echo $orderData['base_currency'] ?>';
34
+ _edrone.order_currency = '<?php echo $orderData['order_currency'] ?>';
35
+ _edrone.coupon = '<?php echo $orderData['coupon'] ?>';
36
+ _edrone.action_type = 'order';
37
+ _edrone.country = '<?php echo $customerData['country'] ?>';
38
+ _edrone.city = '<?php echo urlencode($customerData['city']); ?>';
39
+ _edrone.subscriber_status = '<?php echo $customerData['subscriber_status'] ?>';
40
+ _edrone.utc_time = '<?php echo $helper2->utcNow() ?>';
41
+ _edrone.product_counts = '<?php echo $orderData['product_counts']?>';
42
+
43
+
44
+ var doc = document.createElement('script');
45
+ doc.type = 'text/javascript';
46
+ doc.async = true;
47
+ doc.src = ('https:' == document.location.protocol ? 'https:' : 'http:') + srcjs;
48
+ var s = document.getElementsByTagName('script')[0];
49
+ s.parentNode.insertBefore(doc, s);
50
+
51
+ })("<?php echo $helper->getExternalScriptUrl() ?>");
52
+ </script>
53
+ <?php endif; ?>
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>edroneCRM</name>
4
- <version>1.0.12</version>
5
  <stability>stable</stability>
6
  <license>GPL</license>
7
  <channel>community</channel>
@@ -9,10 +9,10 @@
9
  <summary>edrone - first CRM for e-commerce Maintain clients &amp; increase customer retention with dynamic e-CRM.</summary>
10
  <description>edrone is collecting and analyzing Magento visitors and customers data. The plugin allows processing personal data in the real-time in order to communicate with them through dynamic and personalized e-mail.</description>
11
  <notes>edrone magento module - initial public release</notes>
12
- <authors><author><name>Micha&#x142; Blak</name><user>MAG002993376</user><email>michalblak@gmail.com</email></author></authors>
13
- <date>2016-11-09</date>
14
- <time>14:05:50</time>
15
- <contents><target name="magelocal"><dir name="Edrone"><dir name="Base"><dir name="Block"><file name="Base.php" hash="d0e605725b25d2bf1bc2d27af954ab69"/><file name="Cart.php" hash="0f1243e1a6e886a8676a407e03e039ea"/><file name="Order.php" hash="629475518c89a89fa990157d463422ca"/><file name="Product.php" hash="6ed93a752b59228a0121cc0d6f8efe15"/></dir><dir name="Helper"><file name="Config.php" hash="194670e7ef6eb1dc89b8a61a38499264"/><file name="Data.php" hash="a9040014b1b54a1d3cc7ebf401f489c0"/></dir><dir name="Model"><file name="Observer.php" hash="f35c3bf591865d6db22e2477580df76c"/></dir><dir name="controllers"><file name="NewsletterController.php" hash="fa9e82363c785ce94e005a7aad141162"/></dir><dir name="etc"><file name="adminhtml.xml" hash="0e715e76c00295dc4e555411455fedfb"/><file name="config.xml" hash="1323c093110806ef1d4eb0092abc922b"/><file name="system.xml" hash="4651c48710b53d58c4b6af0da08f1d4e"/></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="edrone.xml" hash="48e37d1c01507337f8dc33eb9e03af34"/></dir></dir></dir></dir></target><target name="mageetc"><dir><dir name="modules"><file name="Edrone_Base.xml" hash="29d3699c3a83fa4fea848a6cb7800872"/></dir></dir></target><target name="magelocale"><dir name="pl_PL"><file name="Edrone.csv" hash="b8aa59d39815f4d92738129cc9fbdf34"/></dir></target></contents>
16
  <compatible/>
17
  <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
18
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>edroneCRM</name>
4
+ <version>1.1.14</version>
5
  <stability>stable</stability>
6
  <license>GPL</license>
7
  <channel>community</channel>
9
  <summary>edrone - first CRM for e-commerce Maintain clients &amp; increase customer retention with dynamic e-CRM.</summary>
10
  <description>edrone is collecting and analyzing Magento visitors and customers data. The plugin allows processing personal data in the real-time in order to communicate with them through dynamic and personalized e-mail.</description>
11
  <notes>edrone magento module - initial public release</notes>
12
+ <authors><author><name>Micha&#x142; Blak</name><user>MAG002993376</user><email>admin@edrone.me</email></author></authors>
13
+ <date>2016-11-21</date>
14
+ <time>13:18:52</time>
15
+ <contents><target name="magelocal"><dir name="Edrone"><dir name="Base"><dir name="Block"><file name="Base.php" hash="d0e605725b25d2bf1bc2d27af954ab69"/><file name="Cart.php" hash="0f1243e1a6e886a8676a407e03e039ea"/><file name="Order.php" hash="bc369d79c562dd7d84dd9bb193d6d846"/><file name="Product.php" hash="6ed93a752b59228a0121cc0d6f8efe15"/></dir><dir name="Helper"><file name="Config.php" hash="194670e7ef6eb1dc89b8a61a38499264"/><file name="Data.php" hash="a9040014b1b54a1d3cc7ebf401f489c0"/></dir><dir name="Model"><file name="Observer.php" hash="13fe1cf0b1637fb2f085ada2101e35d9"/></dir><dir name="controllers"><file name="NewsletterController.php" hash="fa9e82363c785ce94e005a7aad141162"/></dir><dir name="etc"><file name="adminhtml.xml" hash="0e715e76c00295dc4e555411455fedfb"/><file name="config.xml" hash="4ba2657bff971e6fe7dea70931524405"/><file name="system.xml" hash="4651c48710b53d58c4b6af0da08f1d4e"/></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="template"><dir name="edrone"><file name="cart_view.phtml" hash="ac6cfb66e8ca4266e50f18fd84e5d54a"/><file name="default.phtml" hash="3bb34e47475198e4fd4ac6b2d7d42aff"/><file name="product_view.phtml" hash="9c93ebc96d83b9f388d1ae7f24cf9714"/><file name="success_view.phtml" hash="efacdfc95e0cf2324b37cc4a8e09418f"/></dir></dir><dir name="layout"><file name="edrone.xml" hash="48e37d1c01507337f8dc33eb9e03af34"/></dir></dir></dir></dir></target><target name="mageetc"><dir><dir name="modules"><file name="Edrone_Base.xml" hash="29d3699c3a83fa4fea848a6cb7800872"/></dir></dir></target><target name="magelocale"><dir name="pl_PL"><file name="Edrone.csv" hash="b8aa59d39815f4d92738129cc9fbdf34"/></dir></target></contents>
16
  <compatible/>
17
  <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
18
  </package>