cadence_fbpixel - Version 1.2.1

Version Notes

Tested on CE 1.9.x;
Added Events:
- AddToWishlist
- AddToCart
- InitiateCheckout
- ViewContent (Product)
- Search

1.2.1 - fixed bug with content_ids not being on conversion event.

Download this release

Release Info

Developer Cadence Labs
Extension cadence_fbpixel
Version 1.2.1
Comparing to
See all releases


Code changes from version 1.2.0 to 1.2.1

app/code/community/Cadence/Fbpixel/Helper/Data.php CHANGED
@@ -5,6 +5,8 @@
5
  */
6
  class Cadence_Fbpixel_Helper_Data extends Mage_Core_Helper_Abstract
7
  {
 
 
8
  public function isVisitorPixelEnabled()
9
  {
10
  return Mage::getStoreConfig("cadence_fbpixel/visitor/enabled");
@@ -72,4 +74,63 @@ class Cadence_Fbpixel_Helper_Data extends Mage_Core_Helper_Abstract
72
  HTML;
73
  return $html;
74
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
  }
5
  */
6
  class Cadence_Fbpixel_Helper_Data extends Mage_Core_Helper_Abstract
7
  {
8
+ protected $_order;
9
+
10
  public function isVisitorPixelEnabled()
11
  {
12
  return Mage::getStoreConfig("cadence_fbpixel/visitor/enabled");
74
  HTML;
75
  return $html;
76
  }
77
+
78
+ public function getOrderIDs()
79
+ {
80
+ $orderIDs = array();
81
+
82
+ foreach($this->_getOrder()->getAllVisibleItems() as $item){
83
+ $product = Mage::getModel('catalog/product')->load( $item->getProductId() );
84
+ $orderIDs = array_merge($orderIDs, $this->_getProductTrackID($product));
85
+ }
86
+
87
+ return json_encode($orderIDs);
88
+ }
89
+
90
+ protected function _getOrder(){
91
+ if(!$this->_order){
92
+ $orderId = Mage::getSingleton('checkout/type_onepage')->getCheckout()->getLastOrderId();
93
+ $this->_order = Mage::getModel('sales/order')->load($orderId);
94
+ }
95
+
96
+ return $this->_order;
97
+ }
98
+
99
+ protected function _getProductTrackID($product)
100
+ {
101
+ $productType = $product->getTypeID();
102
+
103
+ if($productType == "grouped") {
104
+ return $this->_getProductIDs($product);
105
+ } else {
106
+ return $this->_getProductID($product);
107
+ }
108
+ }
109
+
110
+ protected function _getProductIDs($product)
111
+ {
112
+ $group = Mage::getModel('catalog/product_type_grouped')->setProduct($product);
113
+ $group_collection = $group->getAssociatedProductCollection();
114
+ $ids = array();
115
+
116
+ foreach ($group_collection as $group_product) {
117
+
118
+ $ids[] = $this->_getProductID($group_product);
119
+ }
120
+
121
+ return $ids;
122
+ }
123
+
124
+ protected function _getProductID($product)
125
+ {
126
+ return array(
127
+ $product->getSku()
128
+ );
129
+ }
130
+
131
+ public function getOrderItemsCount()
132
+ {
133
+ $order = $this->_getOrder();
134
+ return count($order->getItemsCollection());
135
+ }
136
  }
app/design/frontend/base/default/template/cadence/fbpixel/conversion.phtml CHANGED
@@ -1,4 +1,5 @@
1
  <?php
 
2
  $helper = Mage::helper("cadence_fbpixel");
3
  if (!$helper->isConversionPixelEnabled()) {
4
  return;
@@ -15,11 +16,19 @@ if (!$order_id || intval($order_id) < 1) {
15
  $order = Mage::getModel('sales/order')->load($order_id);
16
  $grand_total = round($order->getGrandTotal(), 2);
17
  $currency_code = Mage::app()->getStore()->getCurrentCurrencyCode();
 
 
18
  ?>
19
  <!-- Facebook Conversion Code for Conversions -->
20
  <script>
21
- fbq('track', 'Purchase', {value: '<?php echo $grand_total ?>', currency: '<?php echo $currency_code ?>'});
 
 
 
 
 
 
22
  </script>
23
  <noscript><img height="1" width="1" style="display:none"
24
- src="https://www.facebook.com/tr?id=<?php echo $id ?>&ev=Purchase&cd[value]=<?php echo $grand_total ?>&cd[currency]=<?php echo $currency_code ?>&noscript=1"
25
- /></noscript>
1
  <?php
2
+ /** @var Cadence_Fbpixel_Helper_Data $helper */
3
  $helper = Mage::helper("cadence_fbpixel");
4
  if (!$helper->isConversionPixelEnabled()) {
5
  return;
16
  $order = Mage::getModel('sales/order')->load($order_id);
17
  $grand_total = round($order->getGrandTotal(), 2);
18
  $currency_code = Mage::app()->getStore()->getCurrentCurrencyCode();
19
+ $orderIds = $helper->getOrderIDs();
20
+ $numItems = $helper->getOrderItemsCount();
21
  ?>
22
  <!-- Facebook Conversion Code for Conversions -->
23
  <script>
24
+ fbq('track','Purchase', {
25
+ value: <?php echo $grand_total ?>,
26
+ currency: '<?php echo $currency_code ?>',
27
+ content_ids: <?php echo $orderIds ?>,
28
+ content_type: 'product',
29
+ num_items: <?php echo $numItems; ?>
30
+ });
31
  </script>
32
  <noscript><img height="1" width="1" style="display:none"
33
+ src="https://www.facebook.com/tr?id=<?php echo $id ?>&ev=Purchase&cd[value]=<?php echo $grand_total ?>&cd[currency]=<?php echo $currency_code ?>&cd[num_items]=<?php echo $numItems ?>&noscript=1"
34
+ /></noscript>
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>cadence_fbpixel</name>
4
- <version>1.2.0</version>
5
  <stability>stable</stability>
6
  <license>GNU GPL</license>
7
  <channel>community</channel>
@@ -21,11 +21,13 @@ Added Events:&#xD;
21
  - AddToCart&#xD;
22
  - InitiateCheckout&#xD;
23
  - ViewContent (Product)&#xD;
24
- - Search</notes>
 
 
25
  <authors><author><name>Cadence Labs</name><user>cadencelabs</user><email>alan@cadence-labs.com</email></author></authors>
26
- <date>2017-03-11</date>
27
- <time>22:52:00</time>
28
- <contents><target name="magecommunity"><dir name="Cadence"><dir name="Fbpixel"><dir name="Helper"><file name="Data.php" hash="df6d52af7fe615f77a53a18210b97104"/></dir><dir name="Model"><file name="Observer.php" hash="79f6413f672154a566f4fa2ec85982bf"/><file name="Session.php" hash="285559645c2b83a79556746a16065463"/></dir><dir name="etc"><file name="adminhtml.xml" hash="5b6a3e063450264720f766584dbd5055"/><file name="config.xml" hash="196df3b90f07c5fc95960622463d73c7"/><file name="system.xml" hash="f8f314ddb543665cd206bbd379ce3119"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Cadence_Fbpixel.xml" hash="3a82d06be6deb217df2bf11c543bc068"/></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="cadence_fbpixel.xml" hash="84c0ad44bca8b73138e31fbce73554a2"/></dir><dir name="template"><dir name="cadence"><dir name="fbpixel"><file name="conversion.phtml" hash="e602b1ffe10f1b2e21064ba09002657a"/><file name="events.phtml" hash="e3a770f7b4dec9c4632073cb3fb1191f"/><file name="visitor.phtml" hash="7752c825fd59c10b6971353d2e65fcd8"/></dir></dir></dir></dir></dir></dir></target></contents>
29
  <compatible/>
30
  <dependencies><required><php><min>5.2.0</min><max>7.1.9</max></php></required></dependencies>
31
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>cadence_fbpixel</name>
4
+ <version>1.2.1</version>
5
  <stability>stable</stability>
6
  <license>GNU GPL</license>
7
  <channel>community</channel>
21
  - AddToCart&#xD;
22
  - InitiateCheckout&#xD;
23
  - ViewContent (Product)&#xD;
24
+ - Search&#xD;
25
+ &#xD;
26
+ 1.2.1 - fixed bug with content_ids not being on conversion event.</notes>
27
  <authors><author><name>Cadence Labs</name><user>cadencelabs</user><email>alan@cadence-labs.com</email></author></authors>
28
+ <date>2017-05-30</date>
29
+ <time>19:05:30</time>
30
+ <contents><target name="magecommunity"><dir name="Cadence"><dir name="Fbpixel"><dir name="Helper"><file name="Data.php" hash="5eb6200274634386f7a3998be55dd19b"/></dir><dir name="Model"><file name="Observer.php" hash="79f6413f672154a566f4fa2ec85982bf"/><file name="Session.php" hash="285559645c2b83a79556746a16065463"/></dir><dir name="etc"><file name="adminhtml.xml" hash="5b6a3e063450264720f766584dbd5055"/><file name="config.xml" hash="196df3b90f07c5fc95960622463d73c7"/><file name="system.xml" hash="f8f314ddb543665cd206bbd379ce3119"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Cadence_Fbpixel.xml" hash="3a82d06be6deb217df2bf11c543bc068"/></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="cadence_fbpixel.xml" hash="84c0ad44bca8b73138e31fbce73554a2"/></dir><dir name="template"><dir name="cadence"><dir name="fbpixel"><file name="conversion.phtml" hash="8f9af4b43ad5a97d6373dfbcf7d8968a"/><file name="events.phtml" hash="e3a770f7b4dec9c4632073cb3fb1191f"/><file name="visitor.phtml" hash="7752c825fd59c10b6971353d2e65fcd8"/></dir></dir></dir></dir></dir></dir></target></contents>
31
  <compatible/>
32
  <dependencies><required><php><min>5.2.0</min><max>7.1.9</max></php></required></dependencies>
33
  </package>