yireo_googletagmanager - Version 1.1.0

Version Notes

No notes

Download this release

Release Info

Developer Yireo
Extension yireo_googletagmanager
Version 1.1.0
Comparing to
See all releases


Code changes from version 1.0.0 to 1.1.0

app/code/community/Yireo/GoogleTagManager/Block/Default.php CHANGED
@@ -4,18 +4,12 @@
4
  *
5
  * @package Yireo_GoogleTagManager
6
  * @author Yireo (http://www.yireo.com/)
7
- * @copyright Copyright (c) 2012 Yireo (http://www.yireo.com/)
8
- * @license Open Software License
9
  */
10
 
11
  class Yireo_GoogleTagManager_Block_Default extends Mage_Core_Block_Template
12
  {
13
- public function _construct()
14
- {
15
- parent::_construct();
16
- $this->setTemplate('googletagmanager/default.phtml');
17
- }
18
-
19
  public function isEnabled()
20
  {
21
  return (bool)$this->getConfig('active');
4
  *
5
  * @package Yireo_GoogleTagManager
6
  * @author Yireo (http://www.yireo.com/)
7
+ * @copyright Copyright (C) 2014 Yireo (http://www.yireo.com/)
8
+ * @license Open Source License
9
  */
10
 
11
  class Yireo_GoogleTagManager_Block_Default extends Mage_Core_Block_Template
12
  {
 
 
 
 
 
 
13
  public function isEnabled()
14
  {
15
  return (bool)$this->getConfig('active');
app/code/community/Yireo/GoogleTagManager/Block/Order.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * GoogleTagManager plugin for Magento
4
+ *
5
+ * @package Yireo_GoogleTagManager
6
+ * @author Yireo (http://www.yireo.com/)
7
+ * @copyright Copyright (C) 2014 Yireo (http://www.yireo.com/)
8
+ * @license Open Source License
9
+ */
10
+
11
+ class Yireo_GoogleTagManager_Block_Order extends Yireo_GoogleTagManager_Block_Default
12
+ {
13
+ public function getItemsAsJson()
14
+ {
15
+ $data = array();
16
+ foreach($this->getOrder()->getAllItems() as $item) {
17
+ $data[] = array(
18
+ 'sku' => $item->getProduct()->getSku(),
19
+ 'name' => $item->getProduct()->getName(),
20
+ 'price' => $item->getProduct()->getPrice(),
21
+ 'quantity' => $item->getQty(),
22
+ );
23
+ }
24
+ return json_encode($data);
25
+ }
26
+ }
app/code/community/Yireo/GoogleTagManager/Block/Quote.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * GoogleTagManager plugin for Magento
4
+ *
5
+ * @package Yireo_GoogleTagManager
6
+ * @author Yireo (http://www.yireo.com/)
7
+ * @copyright Copyright (C) 2014 Yireo (http://www.yireo.com/)
8
+ * @license Open Source License
9
+ */
10
+
11
+ class Yireo_GoogleTagManager_Block_Quote extends Yireo_GoogleTagManager_Block_Default
12
+ {
13
+ public function getItemsAsJson()
14
+ {
15
+ $data = array();
16
+ foreach($this->getQuote()->getAllItems() as $item) {
17
+ $data[] = array(
18
+ 'sku' => $item->getProduct()->getSku(),
19
+ 'name' => $item->getProduct()->getName(),
20
+ 'price' => $item->getProduct()->getPrice(),
21
+ 'quantity' => $item->getQty(),
22
+ );
23
+ }
24
+ return json_encode($data);
25
+ }
26
+ }
app/code/community/Yireo/GoogleTagManager/Helper/Data.php CHANGED
@@ -3,9 +3,9 @@
3
  * GoogleTagManager plugin for Magento
4
  *
5
  * @package Yireo_GoogleTagManager
6
- * @author Yireo
7
- * @copyright Copyright (c) 2012 Yireo (http://www.yireo.com/)
8
- * @license Open Software License
9
  */
10
 
11
  class Yireo_GoogleTagManager_Helper_Data extends Mage_Core_Helper_Abstract
@@ -25,14 +25,37 @@ class Yireo_GoogleTagManager_Helper_Data extends Mage_Core_Helper_Abstract
25
  */
26
  public function getHeaderScript()
27
  {
 
 
 
28
  if (!($layout = Mage::app()->getFrontController()->getAction()->getLayout())) {
29
- return '';
30
  }
31
 
 
32
  if (!($block = $layout->getBlock('googletagmanager'))) {
33
- return '';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  }
35
 
36
- return $block->toHtml();
 
37
  }
38
  }
3
  * GoogleTagManager plugin for Magento
4
  *
5
  * @package Yireo_GoogleTagManager
6
+ * @author Yireo (http://www.yireo.com/)
7
+ * @copyright Copyright (C) 2014 Yireo (http://www.yireo.com/)
8
+ * @license Open Source License
9
  */
10
 
11
  class Yireo_GoogleTagManager_Helper_Data extends Mage_Core_Helper_Abstract
25
  */
26
  public function getHeaderScript()
27
  {
28
+ $html = '';
29
+
30
+ // Check for the frontend layout
31
  if (!($layout = Mage::app()->getFrontController()->getAction()->getLayout())) {
32
+ return $html;
33
  }
34
 
35
+ // Check for the Google Tag Manager block
36
  if (!($block = $layout->getBlock('googletagmanager'))) {
37
+ return $html;
38
+ }
39
+
40
+ // Add order-information
41
+ $lastOrderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
42
+ if(!empty($lastOrderId)) {
43
+ $order = Mage::getModel('sales/order')->loadByIncrementId($lastOrderId);
44
+ $orderBlock = $layout->getBlock('googletagmanager_order');
45
+ $orderBlock->setQuote($order);
46
+ $html .= $orderBlock->toHtml();
47
+
48
+ // Add quote-information
49
+ } else {
50
+ $quote = Mage::getModel('checkout/cart')->getQuote();
51
+ if($quote->getId() > 0) {
52
+ $quoteBlock = $layout->getBlock('googletagmanager_quote');
53
+ $quoteBlock->setQuote($quote);
54
+ $html .= $quoteBlock->toHtml();
55
+ }
56
  }
57
 
58
+ $html .= $block->toHtml();
59
+ return $html;
60
  }
61
  }
app/code/community/Yireo/GoogleTagManager/Model/Observer.php CHANGED
@@ -4,8 +4,8 @@
4
  *
5
  * @package Yireo_GoogleTagManager
6
  * @author Yireo (http://www.yireo.com/)
7
- * @copyright Copyright (c) 2012 Yireo (http://www.yireo.com/)
8
- * @license Open Software License
9
  */
10
 
11
  class Yireo_GoogleTagManager_Model_Observer
4
  *
5
  * @package Yireo_GoogleTagManager
6
  * @author Yireo (http://www.yireo.com/)
7
+ * @copyright Copyright (C) 2014 Yireo (http://www.yireo.com/)
8
+ * @license Open Source License
9
  */
10
 
11
  class Yireo_GoogleTagManager_Model_Observer
app/code/community/Yireo/GoogleTagManager/etc/config.xml CHANGED
@@ -3,17 +3,16 @@
3
  /**
4
  * GoogleTagManager plugin for Magento
5
  *
6
- * @category design_default
7
  * @package Yireo_GoogleTagManager
8
  * @author Yireo
9
- * @copyright Copyright (c) 2012 Yireo (http://www.yireo.com/)
10
  * @license Open Software License
11
  */
12
  -->
13
  <config>
14
  <modules>
15
  <Yireo_GoogleTagManager>
16
- <version>1.0.0</version>
17
  </Yireo_GoogleTagManager>
18
  </modules>
19
 
3
  /**
4
  * GoogleTagManager plugin for Magento
5
  *
 
6
  * @package Yireo_GoogleTagManager
7
  * @author Yireo
8
+ * @copyright Copyright (C) 2014 Yireo (http://www.yireo.com/)
9
  * @license Open Software License
10
  */
11
  -->
12
  <config>
13
  <modules>
14
  <Yireo_GoogleTagManager>
15
+ <version>1.1.0</version>
16
  </Yireo_GoogleTagManager>
17
  </modules>
18
 
app/code/community/Yireo/GoogleTagManager/etc/system.xml CHANGED
@@ -6,7 +6,7 @@
6
  * @category design_default
7
  * @package Yireo_GoogleTagManager
8
  * @author Yireo
9
- * @copyright Copyright (c) 2012 Yireo (http://www.yireo.com/)
10
  * @license Open Software License
11
  */
12
  -->
6
  * @category design_default
7
  * @package Yireo_GoogleTagManager
8
  * @author Yireo
9
+ * @copyright Copyright (C) 2014 Yireo (http://www.yireo.com/)
10
  * @license Open Software License
11
  */
12
  -->
app/design/frontend/base/default/layout/googletagmanager.xml CHANGED
@@ -12,5 +12,7 @@
12
  <layout>
13
  <default>
14
  <block type="googletagmanager/default" name="googletagmanager" template="googletagmanager/default.phtml" />
 
 
15
  </default>
16
  </layout>
12
  <layout>
13
  <default>
14
  <block type="googletagmanager/default" name="googletagmanager" template="googletagmanager/default.phtml" />
15
+ <block type="googletagmanager/order" name="googletagmanager_order" template="googletagmanager/order.phtml" />
16
+ <block type="googletagmanager/quote" name="googletagmanager_quote" template="googletagmanager/quote.phtml" />
17
  </default>
18
  </layout>
app/design/frontend/base/default/template/googletagmanager/default.phtml CHANGED
@@ -4,7 +4,7 @@
4
  *
5
  * @package Yireo_GoogleTagManager
6
  * @author Yireo (http://www.yireo.com/)
7
- * @copyright Copyright (c) 2012 Yireo (http://www.yireo.com/)
8
  * @license Open Software License
9
  */
10
  ?>
4
  *
5
  * @package Yireo_GoogleTagManager
6
  * @author Yireo (http://www.yireo.com/)
7
+ * @copyright Copyright (c) 2014 Yireo (http://www.yireo.com/)
8
  * @license Open Software License
9
  */
10
  ?>
app/design/frontend/base/default/template/googletagmanager/order.phtml ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * GoogleTagManager plugin for Magento
4
+ *
5
+ * @package Yireo_GoogleTagManager
6
+ * @author Yireo (http://www.yireo.com/)
7
+ * @copyright Copyright (c) 2014 Yireo (http://www.yireo.com/)
8
+ * @license Open Software License
9
+ */
10
+ ?>
11
+ <?php if($this->isEnabled()) : ?>
12
+ <script>
13
+ <?php $order = $this->getOrder(); ?>
14
+ <?php if($order->getId() > 0) : ?>
15
+ dataLayer = [{
16
+ 'transactionId': '<?php echo $order->getIncrementId(); ?>',
17
+ 'transactionAffiliation': '<?php echo Mage::app()->getWebsite()->getName(); ?>',
18
+ 'transactionTotal': <?php echo $order->getGrandTotal(); ?>,
19
+ 'transactionTax': <?php echo $order->getGrandTotal() - $order->getSubtotal(); ?>,
20
+ 'transactionShipping': <?php echo $order->getShippingAmount(); ?>,
21
+ 'transactionProducts': <?php echo $this->getItemsAsJson(); ?>
22
+ }];
23
+ <?php endif; ?>
24
+ </script>
25
+ <?php endif; ?>
app/design/frontend/base/default/template/googletagmanager/quote.phtml ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * GoogleTagManager plugin for Magento
4
+ *
5
+ * @package Yireo_GoogleTagManager
6
+ * @author Yireo (http://www.yireo.com/)
7
+ * @copyright Copyright (c) 2014 Yireo (http://www.yireo.com/)
8
+ * @license Open Software License
9
+ */
10
+ ?>
11
+ <?php if($this->isEnabled()) : ?>
12
+ <script>
13
+ <?php $quote = $this->getQuote(); ?>
14
+ <?php if($quote->getId() > 0) : ?>
15
+ dataLayer = [{
16
+ 'transactionId': '<?php echo $quote->getId(); ?>',
17
+ 'transactionAffiliation': '<?php echo Mage::app()->getWebsite()->getName(); ?>',
18
+ 'transactionTotal': <?php echo $quote->getGrandTotal(); ?>,
19
+ 'transactionTax': <?php echo $quote->getGrandTotal() - $quote->getSubtotal(); ?>,
20
+ 'transactionProducts': <?php echo $this->getItemsAsJson(); ?>
21
+ }];
22
+ <?php endif; ?>
23
+ </script>
24
+ <?php endif; ?>
app/etc/modules/Yireo_GoogleTagManager.xml CHANGED
@@ -5,7 +5,7 @@
5
  *
6
  * @package Yireo_GoogleTagManager
7
  * @author Yireo (http://www.yireo.com/)
8
- * @copyright Copyright (c) 2012 Yireo (http://www.yireo.com/)
9
  * @license Open Software License
10
  */
11
  -->
5
  *
6
  * @package Yireo_GoogleTagManager
7
  * @author Yireo (http://www.yireo.com/)
8
+ * @copyright Copyright (c) 2013 Yireo (http://www.yireo.com/)
9
  * @license Open Software License
10
  */
11
  -->
package.xml CHANGED
@@ -1,18 +1,2 @@
1
  <?xml version="1.0"?>
2
- <package>
3
- <name>yireo_googletagmanager</name>
4
- <version>1.0.0</version>
5
- <stability>stable</stability>
6
- <license>Open Source License</license>
7
- <channel>community</channel>
8
- <extends/>
9
- <summary>Implements Google Tag Manager into Magento</summary>
10
- <description>Implements Google Tag Manager into Magento</description>
11
- <notes>Implements Google Tag Manager into Magento</notes>
12
- <authors><author><name>Yireo</name><user>yireo</user><email>info@yireo.com</email></author></authors>
13
- <date>2012-10-02</date>
14
- <time>11:11:01</time>
15
- <contents><target name="mageetc"><dir name="modules"><file name="Yireo_GoogleTagManager.xml" hash="ffed7b579c7b75d0f7618d77c2c2b994"/></dir></target><target name="magecommunity"><dir name="Yireo"><dir name="GoogleTagManager"><dir name="Block"><file name="Default.php" hash="ac9e0fa686f8ab0518b67ba96d378957"/></dir><dir name="Helper"><file name="Data.php" hash="d5577fc9ab656bc97ad4a332852c06eb"/></dir><dir name="Model"><file name="Observer.php" hash="89c0ad0e22bf669a0a835e2ac7952825"/></dir><dir name="etc"><file name="config.xml" hash="4618e779a452c171b73a918656f182bc"/><file name="system.xml" hash="fd14e2cabf60a28eb70647e44b02a560"/></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="googletagmanager.xml" hash="17873ec53b53ef52529d401c125be1e2"/></dir><dir name="template"><dir name="googletagmanager"><file name="default.phtml" hash="beaf3c29e9cb4b479bdb7ca07282b837"/></dir></dir></dir></dir></dir></target></contents>
16
- <compatible/>
17
- <dependencies><required><php><min>5.2.8</min><max>6.0.0</max></php></required></dependencies>
18
- </package>
1
  <?xml version="1.0"?>
2
+ <package><name>yireo_googletagmanager</name><version>1.1.0</version><stability>stable</stability><license>Open Source License</license><channel>community</channel><extends></extends><summary>No summary</summary><description>No description</description><notes>No notes</notes><authors><author><name>Yireo</name><user>yireo</user><email>info@yireo.com</email></author></authors><date>2014-01-16</date><time>10:28:13</time><compatible></compatible><dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies><contents><target name="mage"><dir name="app"><dir name="etc"><dir name="modules"><file name="Yireo_GoogleTagManager.xml" hash="90f31b076dbc2f5c293c1b61147743ab"/></dir></dir><dir name="code"><dir name="community"><dir name="Yireo"><dir name="GoogleTagManager"><dir name="Block"><file name="Default.php" hash="e714367b7520c63c483f9f2a01ec54e6"/><file name="Order.php" hash="fe2b3e92572278c60b4123c05bd1ddb5"/><file name="Quote.php" hash="32d1071a8d3696a755cb9c2e6d20ed9e"/></dir><dir name="etc"><file name="config.xml" hash="c87c6ae7deef1994488ba967c00d587f"/><file name="system.xml" hash="fc7295c6a7f44f3e4e7336ac5b8ee446"/></dir><dir name="Helper"><file name="Data.php" hash="3f4f9548d7235daffb0d8fa2c7eff71b"/></dir><dir name="Model"><file name="Observer.php" hash="e382a808ed44288f41964145ee683ea1"/></dir></dir></dir></dir></dir><dir name="design"><dir name="frontend"><dir name="base"><dir name="default"><dir name="template"><dir name="googletagmanager"><file name="default.phtml" hash="ae2ad18abddfd2537e6dcb812d29ce80"/><file name="order.phtml" hash="30ff5b339df44eb1940399afaada118e"/><file name="quote.phtml" hash="2d6aa496ee5ed68135a0e8f9d86b95ce"/></dir></dir><dir name="layout"><file name="googletagmanager.xml" hash="074c43895018fb372b6fda747066aa32"/></dir></dir></dir></dir></dir></dir></target></contents></package>