StarSMP_Customers_Tracking_Integration - Version 1.0.4

Version Notes

working update + JS

Download this release

Release Info

Developer KremsaDigital
Extension StarSMP_Customers_Tracking_Integration
Version 1.0.4
Comparing to
See all releases


Code changes from version 1.0.1 to 1.0.4

app/code/community/KremsaDigital/StarSocial/Helper/Data.php CHANGED
@@ -2,5 +2,22 @@
2
 
3
  class KremsaDigital_StarSocial_Helper_Data extends Mage_Core_Helper_Abstract
4
  {
5
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  }
2
 
3
  class KremsaDigital_StarSocial_Helper_Data extends Mage_Core_Helper_Abstract
4
  {
5
+
6
+ private $moduleActive = null;
7
+
8
+ public function isModuleActive() {
9
+ if ($this->moduleActive == null) {
10
+ $act = Mage::getStoreConfig('starsocial/conf/active');
11
+ $lid = Mage::getStoreConfig('starsocial/conf/loyalty_id');
12
+ $cid = Mage::getStoreConfig('starsocial/conf/client_id');
13
+ $cs = Mage::getStoreConfig('starsocial/conf/client_secret');
14
+ $ret = (isset($act) && ($act == '1') && !empty($lid) && !empty($cid) && !empty($cs));
15
+ }
16
+ $this->moduleActive = $ret;
17
+ return $ret;
18
+ }
19
+
20
+ public function getLibUrl() {
21
+ return '/js/KremsaDigital/StarSocial';
22
+ }
23
  }
app/code/community/KremsaDigital/StarSocial/Model/Observer.php CHANGED
@@ -33,7 +33,10 @@ class KremsaDigital_StarSocial_Model_Observer {
33
  $product = Mage::getModel('catalog/product')
34
  ->load(Mage::app()->getRequest()->getParam('product', 0));
35
  $product_qty = Mage::app()->getRequest()->getParam('qty', 0);
36
- $sum = $product->getFinalPrice()*$product_qty;
 
 
 
37
  $track->track('add_to_cart', $sum);
38
  }
39
 
@@ -42,7 +45,8 @@ class KremsaDigital_StarSocial_Model_Observer {
42
  $sum = 0;
43
  foreach ($order_ids as $order_id) {
44
  $order = Mage::getModel('sales/order')->load($order_id);
45
- $sum += $order->getSubtotalInclTax();
 
46
  }
47
 
48
  $track = Mage::getModel('starsocial/track');
33
  $product = Mage::getModel('catalog/product')
34
  ->load(Mage::app()->getRequest()->getParam('product', 0));
35
  $product_qty = Mage::app()->getRequest()->getParam('qty', 0);
36
+ if (!empty($product_qty))
37
+ $sum = $product->getFinalPrice()*$product_qty;
38
+ else
39
+ $sum = $product->getFinalPrice();
40
  $track->track('add_to_cart', $sum);
41
  }
42
 
45
  $sum = 0;
46
  foreach ($order_ids as $order_id) {
47
  $order = Mage::getModel('sales/order')->load($order_id);
48
+ //$sum += $order->getSubtotalInclTax();
49
+ $sum += $order->getGrandTotal();
50
  }
51
 
52
  $track = Mage::getModel('starsocial/track');
app/code/community/KremsaDigital/StarSocial/Model/Track.php CHANGED
@@ -4,8 +4,14 @@ require_once(Mage::getBaseDir('lib') . '/KremsaDigital/StarSocial/starsmp.php');
4
  class KremsaDigital_StarSocial_Model_Track {
5
  private $smpInstance = null;
6
  private $siteUrl = null;
 
7
  const VIPFAN_KEY = 'starsocial_vipfan_id';
8
 
 
 
 
 
 
9
  private function isAuthorized() {
10
  return !($this->smpInstance == null);
11
  }
@@ -16,7 +22,7 @@ class KremsaDigital_StarSocial_Model_Track {
16
  }
17
 
18
  private function authorize() {
19
- if (Mage::getStoreConfig('starsocial/conf/active') == '0') {
20
  return;
21
  }
22
  $smpSettings = new StarSMPSettings();
@@ -34,13 +40,17 @@ class KremsaDigital_StarSocial_Model_Track {
34
  throw $e;
35
  }
36
  $this->smpInstance = $smp;
37
- $this->siteUrl = $this->getProtocol() . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];
 
 
 
38
  }
39
 
40
  public function track($action, $value) {
41
- if (Mage::getStoreConfig('starsocial/conf/active') == '0') {
42
  return;
43
  }
 
44
  if (!$this->isAuthorized()) {
45
  $this->authorize();
46
  }
@@ -50,14 +60,15 @@ class KremsaDigital_StarSocial_Model_Track {
50
  if ($vipfanId) {
51
  $this->smpInstance->setVipfanID($vipfanId);
52
  }
 
53
  $this->smpInstance->track($action, $this->siteUrl, $value); // tracked under vipfan opted in above
54
  } catch (Exception $e) {
55
- throw $e;
56
  }
57
  }
58
 
59
  public function optin($data) {
60
- if (Mage::getStoreConfig('starsocial/conf/active') == '0') {
61
  return;
62
  }
63
  if (!$this->isAuthorized()) {
@@ -68,12 +79,12 @@ class KremsaDigital_StarSocial_Model_Track {
68
  Mage::register($this::VIPFAN_KEY, $vipfan['id']);
69
  Mage::getSingleton('core/session')->setVipfanId($vipfan['id']);
70
  } catch (Exception $e) {
71
- throw $e;
72
  }
73
  }
74
 
75
  public function logout() {
76
- if (Mage::getStoreConfig('starsocial/conf/active') == '0') {
77
  return;
78
  }
79
  if (!$this->isAuthorized()) {
@@ -82,7 +93,7 @@ class KremsaDigital_StarSocial_Model_Track {
82
  try {
83
  $this->smpInstance->logout();
84
  } catch (Exception $e) {
85
- throw $e;
86
  }
87
  Mage::getSingleton('core/session')->unsVipfanId();
88
  Mage::register($this::VIPFAN_KEY, null);
4
  class KremsaDigital_StarSocial_Model_Track {
5
  private $smpInstance = null;
6
  private $siteUrl = null;
7
+ private $isModuleActive = null;
8
  const VIPFAN_KEY = 'starsocial_vipfan_id';
9
 
10
+ public function __construct() {
11
+ $this->isModuleActive = Mage::helper('starsocial')->isModuleActive();
12
+ $this->siteUrl = $this->getProtocol() . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];
13
+ }
14
+
15
  private function isAuthorized() {
16
  return !($this->smpInstance == null);
17
  }
22
  }
23
 
24
  private function authorize() {
25
+ if (!$this->isModuleActive) {
26
  return;
27
  }
28
  $smpSettings = new StarSMPSettings();
40
  throw $e;
41
  }
42
  $this->smpInstance = $smp;
43
+ $smpToken = Mage::getSingleton('core/session')->getSmpToken();
44
+ if (!empty($smpToken)) {
45
+ $this->smpInstance->setAccessToken($smpToken);
46
+ }
47
  }
48
 
49
  public function track($action, $value) {
50
+ if (!$this->isModuleActive) {
51
  return;
52
  }
53
+
54
  if (!$this->isAuthorized()) {
55
  $this->authorize();
56
  }
60
  if ($vipfanId) {
61
  $this->smpInstance->setVipfanID($vipfanId);
62
  }
63
+ // var_dump($this->smpInstance);die();
64
  $this->smpInstance->track($action, $this->siteUrl, $value); // tracked under vipfan opted in above
65
  } catch (Exception $e) {
66
+ Mage::log($e->getMessage(), null, 'starsocial.log');
67
  }
68
  }
69
 
70
  public function optin($data) {
71
+ if (!$this->isModuleActive) {
72
  return;
73
  }
74
  if (!$this->isAuthorized()) {
79
  Mage::register($this::VIPFAN_KEY, $vipfan['id']);
80
  Mage::getSingleton('core/session')->setVipfanId($vipfan['id']);
81
  } catch (Exception $e) {
82
+ Mage::log($e->getMessage(), null, 'starsocial.log');
83
  }
84
  }
85
 
86
  public function logout() {
87
+ if (!$this->isModuleActive) {
88
  return;
89
  }
90
  if (!$this->isAuthorized()) {
93
  try {
94
  $this->smpInstance->logout();
95
  } catch (Exception $e) {
96
+ Mage::log($e->getMessage(), null, 'starsocial.log');
97
  }
98
  Mage::getSingleton('core/session')->unsVipfanId();
99
  Mage::register($this::VIPFAN_KEY, null);
app/code/community/KremsaDigital/StarSocial/etc/system.xml CHANGED
@@ -26,7 +26,8 @@
26
  <active translate="label">
27
  <label>Extentions Active</label>
28
  <frontend_type>select</frontend_type>
29
- <source_model>adminhtml/system_config_source_yesno</source_model> <sort_order>3</sort_order>
 
30
  <show_in_default>1</show_in_default>
31
  <show_in_website>1</show_in_website>
32
  <show_in_store>1</show_in_store>
@@ -34,7 +35,8 @@
34
  <is_beta translate="label">
35
  <label>Beta env.?</label>
36
  <frontend_type>select</frontend_type>
37
- <source_model>adminhtml/system_config_source_yesno</source_model> <sort_order>5</sort_order>
 
38
  <show_in_default>1</show_in_default>
39
  <show_in_website>1</show_in_website>
40
  <show_in_store>1</show_in_store>
26
  <active translate="label">
27
  <label>Extentions Active</label>
28
  <frontend_type>select</frontend_type>
29
+ <source_model>adminhtml/system_config_source_yesno</source_model>
30
+ <sort_order>3</sort_order>
31
  <show_in_default>1</show_in_default>
32
  <show_in_website>1</show_in_website>
33
  <show_in_store>1</show_in_store>
35
  <is_beta translate="label">
36
  <label>Beta env.?</label>
37
  <frontend_type>select</frontend_type>
38
+ <source_model>adminhtml/system_config_source_yesno</source_model>
39
+ <sort_order>5</sort_order>
40
  <show_in_default>1</show_in_default>
41
  <show_in_website>1</show_in_website>
42
  <show_in_store>1</show_in_store>
app/design/frontend/default/default/template/starsocial/tags-checkout.phtml CHANGED
@@ -1,12 +1,14 @@
1
  <?php
2
- $orderId = Mage::getSingleton('checkout/session')->getLastOrderId();
3
- $order = Mage::getSingleton('sales/order')->load($orderId);
4
- $subtotal = $order->getSubtotalInclTax();
5
- $total = $order->getGrandTotal();
6
- ?>
7
- <script type="text/javascript">
8
- var SUBTOTAL_INCL_TAX = <?php echo json_encode($subtotal);?>;
9
- var GRANDTOTAL_INCL_TAX = <?php echo json_encode($total);?>;
10
- </script>
11
- <?
12
- echo Mage::getStoreConfig('starsocial/conf/tag_starsmp_checkout');
 
 
1
  <?php
2
+ if (Mage::helper('starsocial')->isModuleActive()) {
3
+ $orderId = Mage::getSingleton('checkout/session')->getLastOrderId();
4
+ $order = Mage::getSingleton('sales/order')->load($orderId);
5
+ $subtotal = $order->getSubtotalInclTax();
6
+ $total = $order->getGrandTotal();
7
+ ?>
8
+ <script type="text/javascript">
9
+ var SUBTOTAL_INCL_TAX = <?php echo json_encode($subtotal);?>;
10
+ var GRANDTOTAL_INCL_TAX = <?php echo json_encode($total);?>;
11
+ </script>
12
+ <?
13
+ echo Mage::getStoreConfig('starsocial/conf/tag_starsmp_checkout');
14
+ }
app/design/frontend/default/default/template/starsocial/tags.phtml CHANGED
@@ -1,3 +1,39 @@
1
  <?php
 
 
 
 
2
 
3
- echo Mage::getStoreConfig('starsocial/conf/tag_starsmp');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  <?php
2
+ if (Mage::helper('starsocial')->isModuleActive()):
3
+ echo Mage::getStoreConfig('starsocial/conf/tag_starsmp');
4
+ ?>
5
+ <div id="smp-root"></div>
6
 
7
+ <script>
8
+
9
+ var STARSMP_API_PATH = <?php if (Mage::getStoreConfig('starsocial/conf/is_beta') == '1'):?>'//api.starsmp.com-beta.com'<?php else:?>'//api.starsmp.com'<?php endif; ?>;
10
+ window.smpAsyncInit = function() {
11
+ StarSMP.init({
12
+ loyaltyId: <?php echo json_encode(Mage::getStoreConfig('starsocial/conf/loyalty_id'))?>,
13
+ apiServer: STARSMP_API_PATH + '/api/',
14
+ clientId: <?php echo json_encode(Mage::getStoreConfig('starsocial/conf/client_id'))?>,
15
+ channelUrl: '//' + document.location.host + <?php echo json_encode(Mage::helper('starsocial')->getLibUrl())?> + '/channel.html',
16
+ smpLoginService: '//' + document.location.host + <?php echo json_encode(Mage::helper('starsocial')->getLibUrl())?> + '/smp_login.php' // TODO update path to smp_login.php from PHP sdk
17
+ }, function(data) {
18
+
19
+ // method call
20
+ StarSMP.api("auth.token", {"grant_type":"none","client_id":<?php echo json_encode(Mage::getStoreConfig('starsocial/conf/client_id'))?>,"return":"true"}, function(data) {
21
+ if(typeof StarSMP.accessToken!='undefined') {
22
+ jQuery.post(
23
+ '//' + document.location.host + <?php echo json_encode(Mage::helper('starsocial')->getLibUrl())?> + '/smp_login.php',
24
+ { tkn: StarSMP.accessToken },
25
+ function(resp) {}
26
+ );
27
+ }
28
+ });
29
+ });
30
+ };
31
+
32
+
33
+ var e = document.createElement("script"); e.async = true;
34
+ e.src = document.location.protocol + STARSMP_API_PATH + "/connect/all.js";
35
+ document.getElementById("smp-root").appendChild(e);
36
+
37
+ </script>
38
+ <?php
39
+ endif;
js/KremsaDigital/StarSocial/channel.html ADDED
File without changes
js/KremsaDigital/StarSocial/smp_login.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if(!empty($_POST['tkn']))
3
+ {
4
+ if (!defined('MAGENTO_ROOT'))
5
+ define('MAGENTO_ROOT', getcwd());
6
+
7
+ $compilerConfig = MAGENTO_ROOT . '/../../../includes/config.php';
8
+ if (file_exists($compilerConfig)) {
9
+ include $compilerConfig;
10
+ }
11
+
12
+ $mageFilename = MAGENTO_ROOT . '/../../../app/Mage.php';
13
+
14
+ require_once $mageFilename;
15
+ umask(0);
16
+ Mage::app();
17
+
18
+ require_once(Mage::getBaseDir('lib') . '/KremsaDigital/StarSocial/starsmp.php');
19
+
20
+ define("SMP_CLIENT_ID", Mage::getStoreConfig('starsocial/conf/client_id'));
21
+ define("SMP_CLIENT_SECRET", Mage::getStoreConfig('starsocial/conf/client_secret'));
22
+
23
+ $ret = $_POST['tkn'] != Mage::getSingleton('core/session', array('name'=>'frontend'))->getSmpToken() ? "updated" : "not_changed";
24
+ Mage::getSingleton('core/session', array('name'=>'frontend'))->setSmpToken($_POST['tkn']);
25
+ echo json_encode(array("result"=>$ret));
26
+ }
27
+ else
28
+ {
29
+ // TODO this e-shop doesn't have login possibility
30
+ if (isset($_SESSION["logged"]) && $_SESSION["logged"] == true) {
31
+ }
32
+ else {
33
+ echo json_encode(array("signedRequest" => ""));
34
+ }
35
+
36
+ }
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>StarSMP_Customers_Tracking_Integration</name>
4
- <version>1.0.1</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
  <channel>community</channel>
@@ -21,11 +21,11 @@ StarSMP Universal Tag Features: &#xD;
21
  - add custom tracking codes&#xD;
22
  - automatically deploys to your Magento e-shop&#xD;
23
  - control access to your tracking codes</description>
24
- <notes>First stable version</notes>
25
  <authors><author><name>KremsaDigital</name><user>kremsa_design</user><email>kremsa.office.sk@gmail.com</email></author></authors>
26
- <date>2014-10-07</date>
27
- <time>19:33:16</time>
28
- <contents><target name="magecommunity"><dir name="KremsaDigital"><dir name="StarSocial"><dir name="Helper"><file name="Data.php" hash="f2178de63bddfcaffe71bef7b8fcf829"/></dir><dir name="Model"><file name="Observer.php" hash="6cc3b6d784af3b900d61cf4cce27c83d"/><file name="Track.php" hash="77e647afddb19e3add21069c39965f46"/></dir><dir name="etc"><file name="adminhtml.xml" hash="735e6dfffa1e18830ec0f9a061eaa480"/><file name="config.xml" hash="5ba3521633493ef0b9ef9b9d4943fe47"/><file name="system.xml" hash="559342dbfacd62b62e8f05b15828bffd"/></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="default"><dir name="default"><dir name="layout"><file name="StarSocial.xml" hash="44aa76355559f1ab659e76fa5767dbd2"/></dir><dir name="template"><dir name="starsocial"><file name="tags-checkout.phtml" hash="259497eae83a0aa571b83f3de7713ea4"/><file name="tags.phtml" hash="0b2867be89168097b89c1368038e376e"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="KremsaDesign_StarSocial.xml" hash="f07ad022b4e7aaa1c67f0bd9d2458f99"/></dir></target><target name="magelib"><dir name="KremsaDigital"><dir name="StarSocial"><file name="starsmp.php" hash="d6c0f4ca17813c9ce955fab7b10cb40a"/></dir></dir></target></contents>
29
  <compatible/>
30
- <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php><package><name>Mage_Core_Modules</name><channel>community</channel><min>1.6.0.0</min><max>1.9.0.1</max></package></required></dependencies>
31
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>StarSMP_Customers_Tracking_Integration</name>
4
+ <version>1.0.4</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
  <channel>community</channel>
21
  - add custom tracking codes&#xD;
22
  - automatically deploys to your Magento e-shop&#xD;
23
  - control access to your tracking codes</description>
24
+ <notes>working update + JS</notes>
25
  <authors><author><name>KremsaDigital</name><user>kremsa_design</user><email>kremsa.office.sk@gmail.com</email></author></authors>
26
+ <date>2014-10-09</date>
27
+ <time>19:52:47</time>
28
+ <contents><target name="magecommunity"><dir name="KremsaDigital"><dir name="StarSocial"><dir name="Helper"><file name="Data.php" hash="57738c870b8074617d374e0e158018db"/></dir><dir name="Model"><file name="Observer.php" hash="f1af5f191e0cb9116b0015fd02cafa06"/><file name="Track.php" hash="5fae090c6ae99f6599bd8db080cf5b5f"/></dir><dir name="etc"><file name="adminhtml.xml" hash="735e6dfffa1e18830ec0f9a061eaa480"/><file name="config.xml" hash="5ba3521633493ef0b9ef9b9d4943fe47"/><file name="system.xml" hash="5c4f4fdb3735ea7c3396dcf681509e86"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="KremsaDesign_StarSocial.xml" hash="f07ad022b4e7aaa1c67f0bd9d2458f99"/></dir></target><target name="magedesign"><dir name="frontend"><dir name="default"><dir name="default"><dir name="layout"><file name="StarSocial.xml" hash="44aa76355559f1ab659e76fa5767dbd2"/></dir><dir name="template"><dir name="starsocial"><file name="tags-checkout.phtml" hash="f1986a33e545c1246ad07fa7fa5d2a4b"/><file name="tags.phtml" hash="82ccdaaf43964967d385abb163b6a7bf"/></dir></dir></dir></dir></dir></target><target name="mageweb"><dir name="js"><dir name="KremsaDigital"><dir name="StarSocial"><file name="channel.html" hash="d41d8cd98f00b204e9800998ecf8427e"/><file name="smp_login.php" hash="6edf68fb880bee500976a3a1a833a2fe"/></dir></dir></dir></target><target name="magelib"><dir name="KremsaDigital"><dir name="StarSocial"><file name="starsmp.php" hash="d6c0f4ca17813c9ce955fab7b10cb40a"/></dir></dir></target></contents>
29
  <compatible/>
30
+ <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
31
  </package>