shoppingfeeder - Version 1.4.2

Version Notes

Bugfix for category listing in Facebook Audience Pixel Tracking

Download this release

Release Info

Developer ShoppingFeeder
Extension shoppingfeeder
Version 1.4.2
Comparing to
See all releases


Code changes from version 1.4.1 to 1.4.2

app/code/community/ShoppingFeeder/Fbtrack/Block/Adminhtml/Service.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Admin grid container
4
+ *
5
+ * @author ShoppingFeeder
6
+ */
7
+ class ShoppingFeeder_Fbtrack_Block_Adminhtml_Service extends
8
+ Mage_adminhtml_Block_Widget_Grid_Container
9
+ {
10
+ /**
11
+ * Block constructor
12
+ */
13
+ public function __construct()
14
+ {
15
+ $this->_blockGroup = 'shoppingfeeder_fbtrack';
16
+ $this->_controller = 'adminhtml_service';
17
+ $this->_headerText = Mage::helper('shoppingfeeder_fbtrack')->__('Manage Service');
18
+ }
19
+ }
app/code/community/ShoppingFeeder/Fbtrack/Block/Service.php ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * ShoppingFeeder XML generation code
5
+ *
6
+ * @category ShoppingFeeder
7
+ * @package ShoppingFeeder_Fbtrack
8
+ * @copyright Copyright (c) 2014 Kevin Tucker (http://www.shoppingfeeder.com)
9
+ *
10
+ */
11
+
12
+ class ShoppingFeeder_Fbtrack_Block_Service extends Mage_Core_Block_Template
13
+ {
14
+ }
app/code/community/ShoppingFeeder/Fbtrack/Block/Tracking/Fb.php ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * ShoppingFeeder XML generation code
5
+ *
6
+ * @category ShoppingFeeder
7
+ * @package ShoppingFeeder_Fbtrack
8
+ * @copyright Copyright (c) 2014 Kevin Tucker (http://www.shoppingfeeder.com)
9
+ *
10
+ */
11
+
12
+ class ShoppingFeeder_Fbtrack_Block_Tracking_Fb extends Mage_Core_Block_Template
13
+ {
14
+ protected function _toHtml() {
15
+ $trackFb = Mage::getStoreConfig('shoppingfeeder_fbtrack/fb_track_config/fb_track');
16
+
17
+ if (!$trackFb) {
18
+ return '';
19
+ }
20
+
21
+ return parent::_toHtml();
22
+ }
23
+
24
+ /**
25
+ * return the price of the product
26
+ *
27
+ * @return string
28
+ */
29
+ public function getProductPrice()
30
+ {
31
+ $currentCurrencyCode = Mage::app()->getStore()->getCurrentCurrencyCode();
32
+ $baseCurrencyCode = Mage::app()->getStore()->getBaseCurrencyCode();
33
+
34
+ $finalPrice = $this->getData('product')->getFinalPrice();
35
+ if ($currentCurrencyCode && ($currentCurrencyCode != $baseCurrencyCode)) {
36
+ $finalPrice = Mage::helper('directory')->currencyConvert($finalPrice, $baseCurrencyCode, $currentCurrencyCode);
37
+ }
38
+
39
+ return number_format($finalPrice, 2);
40
+ }
41
+
42
+ /**
43
+ * Return the current currency code
44
+ *
45
+ * @return string
46
+ */
47
+ public function getCurrency()
48
+ {
49
+ return Mage::app()->getStore()->getCurrentCurrencyCode();
50
+ }
51
+
52
+ /**
53
+ * Return the FB pixel ID
54
+ *
55
+ * @return string
56
+ */
57
+ public function getPixelId()
58
+ {
59
+ return Mage::getStoreConfig('shoppingfeeder_fbtrack/fb_track_config/fb_track_code');
60
+ }
61
+ }
app/code/community/ShoppingFeeder/Fbtrack/Helper/Data.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Service Data Helper
4
+ *
5
+ * @author ShoppingFeeder
6
+ */
7
+ class ShoppingFeeder_Fbtrack_Helper_Data extends Mage_Core_Helper_Data
8
+ {
9
+
10
+ }
app/code/community/ShoppingFeeder/Fbtrack/Model/Observer.php ADDED
@@ -0,0 +1,188 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class ShoppingFeeder_Fbtrack_Model_Observer extends Varien_Object
3
+ {
4
+ public function salesOrderPlaceAfter($observer)
5
+ {
6
+ try{
7
+ $fbTracking = Mage::getStoreConfig('shoppingfeeder_fbtrack/fb_track_config/fb_track');
8
+ if (!is_null($fbTracking) && $fbTracking)
9
+ {
10
+ /* @var Mage_Sales_Model_Order $order */
11
+ $order = $observer->getEvent()->getOrder();
12
+
13
+ //set the order for JS tracking code
14
+ $orderItems = array();
15
+ foreach ($order->getAllItems() as $item)
16
+ {
17
+ $orderItems[] = '\''.$item->getProductId().'\'';
18
+ }
19
+ $orderInfo = array(
20
+ 'items' => $orderItems,
21
+ 'value' => $order->getGrandTotal()
22
+ );
23
+ Mage::getModel('core/session')->setOrderForJsTrackingShoppingFeederFbtrack($orderInfo);
24
+ }
25
+ }
26
+ catch (Exception $e)
27
+ {
28
+ Mage::log('_notifyShoppingFeeder Order ID: '.$order->getRealOrderId().' FAILED! Message: '.$e->getMessage());
29
+ }
30
+ }
31
+
32
+ /**
33
+ * @param Varien_Event_Observer $observer
34
+ */
35
+ public function generateBlocksAfter($observer)
36
+ {
37
+ try{
38
+ $fbTracking = Mage::getStoreConfig('shoppingfeeder_fbtrack/fb_track_config/fb_track');
39
+ if (!is_null($fbTracking) && $fbTracking)
40
+ {
41
+ $actionName = $observer->getEvent()->getAction()->getFullActionName();
42
+ // var_dump($actionName);
43
+ // exit();
44
+ $block = Mage::app()->getFrontController()->getAction()->getLayout()->getBlock('shoppingfeeder_fbtrack_tracking_fb');
45
+
46
+ if ($actionName == 'catalog_product_view' || $actionName == 'checkout_cart_index')
47
+ {
48
+ $product = Mage::registry('current_product');
49
+ if (is_null($product))
50
+ {
51
+ $product = Mage::getModel('core/session')->getProductToShoppingCartShoppingFeederFbtrack();
52
+ }
53
+
54
+ //if we still don't have a product, don't do anything
55
+ if (is_null($product))
56
+ {
57
+ return;
58
+ }
59
+
60
+ $pathToUse = '';
61
+
62
+ $category = Mage::registry('current_category');
63
+ $currentCategoryPath = null;
64
+ if (!is_null($category))
65
+ {
66
+ $currentCategoryPath = $category->getPath();
67
+ }
68
+
69
+ $startTime = microtime(true);
70
+
71
+ $storeRootCategoryId = Mage::app()->getStore()->getRootCategoryId();
72
+ $storeRootCategoryName = Mage::getModel('catalog/category')->load($storeRootCategoryId)->getName();
73
+ if (is_null($currentCategoryPath))
74
+ {
75
+ if (!is_null($product) && is_object($product))
76
+ {
77
+ /** @var Mage_Catalog_Model_Resource_Category_Collection $categoryCollection */
78
+ $categoryCollection = $product->getCategoryCollection()->addAttributeToSelect('name');
79
+
80
+ $depth = 0;
81
+ foreach($categoryCollection as $cat1){
82
+ $pathIds = explode('/', $cat1->getPath());
83
+ unset($pathIds[0]);
84
+
85
+ $collection = Mage::getModel('catalog/category')->getCollection()
86
+ ->setStoreId(Mage::app()->getStore()->getId())
87
+ ->addAttributeToSelect('name')
88
+ ->addAttributeToSelect('is_active')
89
+ ->addFieldToFilter('entity_id', array('in' => $pathIds));
90
+
91
+ $pathByName = array();
92
+ /** @var Mage_Catalog_Model_Category $cat */
93
+ foreach($collection as $cat){
94
+ if ($cat->getName() != $storeRootCategoryName)
95
+ {
96
+ $pathByName[] = $cat->getName();
97
+ }
98
+ }
99
+
100
+ //take the longest (generally more detailed) path
101
+ $thisDepth = count($pathByName);
102
+ if ($thisDepth > $depth)
103
+ {
104
+ $depth = $thisDepth;
105
+ $pathToUse = implode(' > ', $pathByName);
106
+ }
107
+ }
108
+ }
109
+ }
110
+ else
111
+ {
112
+ $pathIds = explode('/', $currentCategoryPath);
113
+ unset($pathIds[0]);
114
+
115
+ $collection = Mage::getModel('catalog/category')->getCollection()
116
+ ->setStoreId(Mage::app()->getStore()->getId())
117
+ ->addAttributeToSelect('name')
118
+ ->addAttributeToSelect('is_active')
119
+ ->addFieldToFilter('entity_id', array('in' => $pathIds));
120
+
121
+ $pathByName = array();
122
+ /** @var Mage_Catalog_Model_Category $cat */
123
+ foreach($collection as $cat){
124
+ if ($cat->getName() != $storeRootCategoryName)
125
+ {
126
+ $pathByName[] = $cat->getName();
127
+ }
128
+ }
129
+ $pathToUse = implode(' > ', $pathByName);
130
+ }
131
+
132
+ if ($product)
133
+ {
134
+ $block->setData('product', $product);
135
+ $block->setData('category', $pathToUse);
136
+
137
+ if ($actionName == 'catalog_product_view')
138
+ {
139
+ $block->setData('action_type', 'ViewContent');
140
+ }
141
+ elseif ($actionName == 'checkout_cart_index')
142
+ {
143
+ $block->setData('action_type', 'AddToCart');
144
+ //reset the cart product
145
+ Mage::getModel('core/session')->setProductToShoppingCartShoppingFeederFbtrack(null);
146
+ }
147
+ }
148
+ }
149
+
150
+
151
+ elseif ($actionName == 'checkout_onepage_success' || $actionName == 'checkout_multishipping_success')
152
+ {
153
+ Mage::log('After template action: '.$actionName);
154
+ $orderInfo = Mage::getModel('core/session')->getOrderForJsTrackingShoppingFeederFbtrack();
155
+ if (!is_null($orderInfo) && $block)
156
+ {
157
+ $block->setData('order', $orderInfo);
158
+ $block->setData('action_type', 'Purchase');
159
+ Mage::getModel('core/session')->setOrderForJsTrackingShoppingFeederFbtrack(null);
160
+ }
161
+ }
162
+ }
163
+ }
164
+ catch (Exception $e)
165
+ {
166
+
167
+ }
168
+ }
169
+
170
+ /**
171
+ * @param Varien_Event_Observer $observer
172
+ */
173
+ public function setAddToCartProduct($observer)
174
+ {
175
+ try{
176
+
177
+ //add the cart product to the session
178
+ $product = Mage::getModel('catalog/product')
179
+ ->load(Mage::app()->getRequest()->getParam('product', 0));
180
+
181
+ Mage::getModel('core/session')->setProductToShoppingCartShoppingFeederFbtrack($product);
182
+ }
183
+ catch (Exception $e)
184
+ {
185
+
186
+ }
187
+ }
188
+ }
app/code/community/ShoppingFeeder/Fbtrack/etc/config.xml ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Module config
5
+ *
6
+ * @author ShoppingFeeder
7
+ */
8
+ -->
9
+ <config>
10
+ <modules>
11
+ <ShoppingFeeder_Fbtrack>
12
+ <version>1.0.1</version>
13
+ </ShoppingFeeder_Fbtrack>
14
+ </modules>
15
+ <global>
16
+ <models>
17
+ <shoppingfeeder_fbtrack>
18
+ <class>ShoppingFeeder_Fbtrack_Model</class>
19
+ </shoppingfeeder_fbtrack>
20
+ </models>
21
+ <helpers>
22
+ <shoppingfeeder_fbtrack>
23
+ <class>ShoppingFeeder_Fbtrack_Helper</class>
24
+ </shoppingfeeder_fbtrack>
25
+ </helpers>
26
+ <blocks>
27
+ <shoppingfeeder_fbtrack>
28
+ <class>ShoppingFeeder_Fbtrack_Block</class>
29
+ </shoppingfeeder_fbtrack>
30
+ </blocks>
31
+ <resources>
32
+ <shoppingfeeder_fbtrack_setup>
33
+ <setup>
34
+ <module>ShoppingFeeder_Fbtrack</module>
35
+ <class>Mage_Core_Model_Resource_Setup</class>
36
+ </setup>
37
+ </shoppingfeeder_fbtrack_setup>
38
+ </resources>
39
+ <events>
40
+ <sales_order_place_after>
41
+ <observers>
42
+ <shoppingfeeder_fbtrack_notify_sales_order_place_after>
43
+ <class>shoppingfeeder_fbtrack/observer</class>
44
+ <method>salesOrderPlaceAfter</method>
45
+ </shoppingfeeder_fbtrack_notify_sales_order_place_after>
46
+ </observers>
47
+ </sales_order_place_after>
48
+ </events>
49
+ </global>
50
+ <frontend>
51
+ <layout>
52
+ <updates>
53
+ <shoppingfeeder_fbtrack>
54
+ <file>shoppingfeeder_fbtrack.xml</file>
55
+ </shoppingfeeder_fbtrack>
56
+ </updates>
57
+ </layout>
58
+ <events>
59
+ <controller_action_layout_generate_blocks_after>
60
+ <observers>
61
+ <shoppingfeeder_fbtrack_fbtrack_view>
62
+ <class>shoppingfeeder_fbtrack/observer</class>
63
+ <method>generateBlocksAfter</method>
64
+ </shoppingfeeder_fbtrack_fbtrack_view>
65
+ </observers>
66
+ </controller_action_layout_generate_blocks_after>
67
+ <checkout_cart_product_add_after>
68
+ <observers>
69
+ <shoppingfeeder_fbtrack_fbtrack_add_to_cart>
70
+ <class>shoppingfeeder_fbtrack/observer</class>
71
+ <method>setAddToCartProduct</method>
72
+ </shoppingfeeder_fbtrack_fbtrack_add_to_cart>
73
+ </observers>
74
+ </checkout_cart_product_add_after>
75
+ </events>
76
+ </frontend>
77
+ <admin>
78
+ <routers>
79
+ <adminhtml>
80
+ <args>
81
+ <modules>
82
+ <ShoppingFeeder_Fbtrack before="Mage_adminhtml">ShoppingFeeder_Fbtrack_Adminhtml</ShoppingFeeder_Fbtrack>
83
+ </modules>
84
+ </args>
85
+ </adminhtml>
86
+ </routers>
87
+ </admin>
88
+ <adminhtml>
89
+ <acl>
90
+ <resources>
91
+ <admin>
92
+ <children>
93
+ <system>
94
+ <children>
95
+ <config>
96
+ <children>
97
+ <shoppingfeeder_fbtrack>
98
+ <title>ShoppingFeeder Facebook Audience Pixel</title>
99
+ </shoppingfeeder_fbtrack>
100
+ </children>
101
+ </config>
102
+ </children>
103
+ </system>
104
+ </children>
105
+ </admin>
106
+ </resources>
107
+ </acl>
108
+ </adminhtml>
109
+ <default>
110
+ <shoppingfeeder_fbtrack>
111
+ <fb_track_config>
112
+ <enable>1</enable>
113
+ <fb_track>0</fb_track>
114
+ </fb_track_config>
115
+ </shoppingfeeder_fbtrack>
116
+ </default>
117
+ </config>
app/code/community/ShoppingFeeder/Fbtrack/etc/system.xml ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Admin menu config
5
+ *
6
+ * @author ShoppingFeeder
7
+ */
8
+ -->
9
+ <config>
10
+ <sections>
11
+ <shoppingfeeder_fbtrack translate="label">
12
+ <class>separator-top</class>
13
+ <label>Facebook Dynamic Product Ads</label>
14
+ <tab>catalog</tab>
15
+ <frontend_type>text</frontend_type>
16
+ <sort_order>600</sort_order>
17
+ <show_in_default>1</show_in_default>
18
+ <show_in_website>1</show_in_website>
19
+ <show_in_store>1</show_in_store>
20
+
21
+ <groups>
22
+ <fb_track_config translate="label">
23
+ <label>Facebook Audience Tracking Pixel Configuration</label>
24
+ <frontend_type>text</frontend_type>
25
+ <sort_order>2</sort_order>
26
+ <show_in_default>1</show_in_default>
27
+ <show_in_website>1</show_in_website>
28
+ <show_in_store>1</show_in_store>
29
+ <expanded>1</expanded>
30
+ <fields>
31
+ <fb_track translate="label">
32
+ <label>Enable Facebook Audience Tracking Pixel</label>
33
+ <frontend_type>select</frontend_type>
34
+ <source_model>adminhtml/system_config_source_yesno</source_model>
35
+ <sort_order>4</sort_order>
36
+ <show_in_default>1</show_in_default>
37
+ <show_in_website>1</show_in_website>
38
+ <show_in_store>1</show_in_store>
39
+ </fb_track>
40
+ <fb_track_code translate="label">
41
+ <label>Facebook Audience Tracking Pixel Code</label>
42
+ <comment><![CDATA[Be sure to get your tracking code ID from Facebook. You can <a href="https://developers.facebook.com/docs/ads-for-websites/website-custom-audiences/getting-started#install-the-pixel" target="_blank">read more here</a>. Don't worry about all the JavaScript, this module sets all that up for you.
43
+ <br><br>
44
+ <div style="background-image: url('https://www.shoppingfeeder.com/images/sprite.png');background-repeat: no-repeat;background-position: 0 0;width: 143px;height: 57px;">
45
+ </div>
46
+ <br>
47
+ This useful Magento module is brought to you by <a href="http://www.shoppingfeeder.com/?" target="_blank">ShoppingFeeder</a>, a feeed management and multi-channel marketing solution. Once you've started tracking visitors to your store
48
+ using Facebook Audience Tracking, sign up to ShoppingFeeder and get a feed to use on Facebook Dynamic Product Ads. We make it super-easy and completely non-technical.
49
+ <br>
50
+ ]]>
51
+ </comment>
52
+ <frontend_type>text</frontend_type>
53
+ <source_model>adminhtml/system_config_source_yesno</source_model>
54
+ <sort_order>5</sort_order>
55
+ <show_in_default>1</show_in_default>
56
+ <show_in_website>1</show_in_website>
57
+ <show_in_store>1</show_in_store>
58
+ <validate>required-entry</validate>
59
+ <depends><fb_track>1</fb_track></depends>
60
+ </fb_track_code>
61
+ </fields>
62
+ </fb_track_config>
63
+ </groups>
64
+ </shoppingfeeder_fbtrack>
65
+ </sections>
66
+ </config>
app/code/community/ShoppingFeeder/Service/Model/Observer.php CHANGED
@@ -11,7 +11,8 @@ class ShoppingFeeder_Service_Model_Observer extends Varien_Object
11
  //$sfEnabled = Mage::getStoreConfig('shoppingfeeder/service/enable');
12
  $sfEnabled = true;
13
  $sfTracking = Mage::getStoreConfig('shoppingfeeder/service/tracking');
14
- if ($sfEnabled && $sfTracking)
 
15
  {
16
  /* @var Mage_Sales_Model_Order $order */
17
  $order = $observer->getEvent()->getOrder();
@@ -30,7 +31,11 @@ class ShoppingFeeder_Service_Model_Observer extends Varien_Object
30
  );
31
  Mage::getModel('core/session')->setOrderForJsTracking($orderInfo);
32
 
33
- $this->_notifyShoppingFeeder($order);
 
 
 
 
34
  }
35
  }
36
  catch (Exception $e)
@@ -61,44 +66,81 @@ class ShoppingFeeder_Service_Model_Observer extends Varien_Object
61
  public function generateBlocksAfter($observer)
62
  {
63
  try{
64
- $actionName = $observer->getEvent()->getAction()->getFullActionName();
65
- // var_dump($actionName);
66
- // exit();
67
- $block = Mage::app()->getFrontController()->getAction()->getLayout()->getBlock('shoppingfeeder_service_tracking_fb');
68
-
69
- if ($actionName == 'catalog_product_view' || $actionName == 'checkout_cart_index')
70
  {
71
- $product = Mage::registry('current_product');
72
- if (is_null($product))
73
- {
74
- $product = Mage::getModel('core/session')->getProductToShoppingCart();
75
- }
76
 
77
- //if we still don't have a product, don't do anything
78
- if (is_null($product))
79
  {
80
- return;
81
- }
 
 
 
82
 
83
- $category = Mage::registry('current_category');
84
- $currentCategoryPath = null;
85
- if (!is_null($category))
86
- {
87
- $currentCategoryPath = $category->getPath();
88
- }
89
 
90
- $startTime = microtime(true);
91
 
92
- $storeRootCategoryId = Mage::app()->getStore()->getRootCategoryId();
93
- $storeRootCategoryName = Mage::getModel('catalog/category')->load($storeRootCategoryId)->getName();
94
- if (is_null($currentCategoryPath))
95
- {
96
- /** @var Mage_Catalog_Model_Resource_Category_Collection $categoryCollection */
97
- $categoryCollection = $product->getCategoryCollection()->addAttributeToSelect('name');
98
 
99
- $depth = 0;
100
- foreach($categoryCollection as $cat1){
101
- $pathIds = explode('/', $cat1->getPath());
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
  unset($pathIds[0]);
103
 
104
  $collection = Mage::getModel('catalog/category')->getCollection()
@@ -115,68 +157,40 @@ class ShoppingFeeder_Service_Model_Observer extends Varien_Object
115
  $pathByName[] = $cat->getName();
116
  }
117
  }
 
 
 
 
 
 
 
118
 
119
- //take the longest (generally more detailed) path
120
- $thisDepth = count($pathByName);
121
- if ($thisDepth > $depth)
122
  {
123
- $depth = $thisDepth;
124
- $pathToUse = implode(' > ', $pathByName);
125
  }
126
- }
127
- }
128
- else
129
- {
130
- $pathIds = explode('/', $currentCategoryPath);
131
- unset($pathIds[0]);
132
-
133
- $collection = Mage::getModel('catalog/category')->getCollection()
134
- ->setStoreId(Mage::app()->getStore()->getId())
135
- ->addAttributeToSelect('name')
136
- ->addAttributeToSelect('is_active')
137
- ->addFieldToFilter('entity_id', array('in' => $pathIds));
138
-
139
- $pathByName = array();
140
- /** @var Mage_Catalog_Model_Category $cat */
141
- foreach($collection as $cat){
142
- if ($cat->getName() != $storeRootCategoryName)
143
  {
144
- $pathByName[] = $cat->getName();
 
 
145
  }
146
  }
147
- $pathToUse = implode(' > ', $pathByName);
148
  }
149
 
150
- if ($product)
151
- {
152
- $block->setData('product', $product);
153
- $block->setData('category', $pathToUse);
154
 
155
- if ($actionName == 'catalog_product_view')
156
- {
157
- $block->setData('action_type', 'ViewContent');
158
- }
159
- elseif ($actionName == 'checkout_cart_index')
160
  {
161
- $block->setData('action_type', 'AddToCart');
162
- //reset the cart product
163
- Mage::getModel('core/session')->setProductToShoppingCart(null);
164
  }
165
  }
166
  }
167
-
168
-
169
- elseif ($actionName == 'checkout_onepage_success' || $actionName == 'checkout_multishipping_success')
170
- {
171
- Mage::log('After template action: '.$actionName);
172
- $orderInfo = Mage::getModel('core/session')->getOrderForJsTracking();
173
- if (!is_null($orderInfo) && $block)
174
- {
175
- $block->setData('order', $orderInfo);
176
- $block->setData('action_type', 'Purchase');
177
- Mage::getModel('core/session')->setOrderForJsTracking(null);
178
- }
179
- }
180
  }
181
  catch (Exception $e)
182
  {
11
  //$sfEnabled = Mage::getStoreConfig('shoppingfeeder/service/enable');
12
  $sfEnabled = true;
13
  $sfTracking = Mage::getStoreConfig('shoppingfeeder/service/tracking');
14
+ $fbTracking = Mage::getStoreConfig('shoppingfeeder/fb_track_config/fb_track');
15
+ if (($sfEnabled && $sfTracking) || (!is_null($fbTracking) && $fbTracking))
16
  {
17
  /* @var Mage_Sales_Model_Order $order */
18
  $order = $observer->getEvent()->getOrder();
31
  );
32
  Mage::getModel('core/session')->setOrderForJsTracking($orderInfo);
33
 
34
+ //only notify ShoppingFeeder if required
35
+ if ($sfEnabled && $sfTracking)
36
+ {
37
+ $this->_notifyShoppingFeeder($order);
38
+ }
39
  }
40
  }
41
  catch (Exception $e)
66
  public function generateBlocksAfter($observer)
67
  {
68
  try{
69
+ $fbTracking = Mage::getStoreConfig('shoppingfeeder/fb_track_config/fb_track');
70
+ if (!is_null($fbTracking) && $fbTracking)
 
 
 
 
71
  {
72
+ $actionName = $observer->getEvent()->getAction()->getFullActionName();
73
+ // var_dump($actionName);
74
+ // exit();
75
+ $block = Mage::app()->getFrontController()->getAction()->getLayout()->getBlock('shoppingfeeder_service_tracking_fb');
 
76
 
77
+ if ($actionName == 'catalog_product_view' || $actionName == 'checkout_cart_index')
 
78
  {
79
+ $product = Mage::registry('current_product');
80
+ if (is_null($product))
81
+ {
82
+ $product = Mage::getModel('core/session')->getProductToShoppingCart();
83
+ }
84
 
85
+ //if we still don't have a product, don't do anything
86
+ if (is_null($product))
87
+ {
88
+ return;
89
+ }
 
90
 
91
+ $pathToUse = '';
92
 
93
+ $category = Mage::registry('current_category');
94
+ $currentCategoryPath = null;
95
+ if (!is_null($category))
96
+ {
97
+ $currentCategoryPath = $category->getPath();
98
+ }
99
 
100
+ $startTime = microtime(true);
101
+
102
+ $storeRootCategoryId = Mage::app()->getStore()->getRootCategoryId();
103
+ $storeRootCategoryName = Mage::getModel('catalog/category')->load($storeRootCategoryId)->getName();
104
+ if (is_null($currentCategoryPath))
105
+ {
106
+ if (!is_null($product) && is_object($product))
107
+ {
108
+ /** @var Mage_Catalog_Model_Resource_Category_Collection $categoryCollection */
109
+ $categoryCollection = $product->getCategoryCollection()->addAttributeToSelect('name');
110
+
111
+ $depth = 0;
112
+ foreach($categoryCollection as $cat1){
113
+ $pathIds = explode('/', $cat1->getPath());
114
+ unset($pathIds[0]);
115
+
116
+ $collection = Mage::getModel('catalog/category')->getCollection()
117
+ ->setStoreId(Mage::app()->getStore()->getId())
118
+ ->addAttributeToSelect('name')
119
+ ->addAttributeToSelect('is_active')
120
+ ->addFieldToFilter('entity_id', array('in' => $pathIds));
121
+
122
+ $pathByName = array();
123
+ /** @var Mage_Catalog_Model_Category $cat */
124
+ foreach($collection as $cat){
125
+ if ($cat->getName() != $storeRootCategoryName)
126
+ {
127
+ $pathByName[] = $cat->getName();
128
+ }
129
+ }
130
+
131
+ //take the longest (generally more detailed) path
132
+ $thisDepth = count($pathByName);
133
+ if ($thisDepth > $depth)
134
+ {
135
+ $depth = $thisDepth;
136
+ $pathToUse = implode(' > ', $pathByName);
137
+ }
138
+ }
139
+ }
140
+ }
141
+ else
142
+ {
143
+ $pathIds = explode('/', $currentCategoryPath);
144
  unset($pathIds[0]);
145
 
146
  $collection = Mage::getModel('catalog/category')->getCollection()
157
  $pathByName[] = $cat->getName();
158
  }
159
  }
160
+ $pathToUse = implode(' > ', $pathByName);
161
+ }
162
+
163
+ if ($product)
164
+ {
165
+ $block->setData('product', $product);
166
+ $block->setData('category', $pathToUse);
167
 
168
+ if ($actionName == 'catalog_product_view')
 
 
169
  {
170
+ $block->setData('action_type', 'ViewContent');
 
171
  }
172
+ elseif ($actionName == 'checkout_cart_index')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
173
  {
174
+ $block->setData('action_type', 'AddToCart');
175
+ //reset the cart product
176
+ Mage::getModel('core/session')->setProductToShoppingCart(null);
177
  }
178
  }
 
179
  }
180
 
 
 
 
 
181
 
182
+ elseif ($actionName == 'checkout_onepage_success' || $actionName == 'checkout_multishipping_success')
183
+ {
184
+ Mage::log('After template action: '.$actionName);
185
+ $orderInfo = Mage::getModel('core/session')->getOrderForJsTracking();
186
+ if (!is_null($orderInfo) && $block)
187
  {
188
+ $block->setData('order', $orderInfo);
189
+ $block->setData('action_type', 'Purchase');
190
+ Mage::getModel('core/session')->setOrderForJsTracking(null);
191
  }
192
  }
193
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
194
  }
195
  catch (Exception $e)
196
  {
app/code/community/ShoppingFeeder/Service/controllers/VersionController.php CHANGED
@@ -5,7 +5,7 @@ require_once(Mage::getModuleDir('Controller','ShoppingFeeder_Service').DS.'Contr
5
 
6
  class ShoppingFeeder_Service_VersionController extends Mage_Core_Controller_Front_Action
7
  {
8
- protected static $_version = '1.4.0';
9
 
10
  public function indexAction()
11
  {
5
 
6
  class ShoppingFeeder_Service_VersionController extends Mage_Core_Controller_Front_Action
7
  {
8
+ protected static $_version = '1.4.2';
9
 
10
  public function indexAction()
11
  {
app/code/community/ShoppingFeeder/Service/etc/config.xml CHANGED
@@ -9,7 +9,7 @@
9
  <config>
10
  <modules>
11
  <ShoppingFeeder_Service>
12
- <version>1.4.0</version>
13
  </ShoppingFeeder_Service>
14
  </modules>
15
  <global>
9
  <config>
10
  <modules>
11
  <ShoppingFeeder_Service>
12
+ <version>1.4.2</version>
13
  </ShoppingFeeder_Service>
14
  </modules>
15
  <global>
app/code/community/ShoppingFeeder/Service/etc/system.xml CHANGED
@@ -88,6 +88,7 @@
88
  </fb_track>
89
  <fb_track_code translate="label">
90
  <label>Facebook Audience Tracking Pixel Code</label>
 
91
  <frontend_type>text</frontend_type>
92
  <source_model>adminhtml/system_config_source_yesno</source_model>
93
  <sort_order>5</sort_order>
88
  </fb_track>
89
  <fb_track_code translate="label">
90
  <label>Facebook Audience Tracking Pixel Code</label>
91
+ <comment><![CDATA[Be sure to get your tracking code ID from Facebook. You can <a href="https://developers.facebook.com/docs/ads-for-websites/website-custom-audiences/getting-started#install-the-pixel" target="_blank">read more here</a>. Don't worry about all the JavaScript, this module sets all that up for you.]]></comment>
92
  <frontend_type>text</frontend_type>
93
  <source_model>adminhtml/system_config_source_yesno</source_model>
94
  <sort_order>5</sort_order>
app/design/frontend/base/default/template/shoppingfeeder/fbtrack_standalone.phtml ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * Facebook Dynamic Product Ads tracking code by ShoppingFeeder
5
+ * Get ShoppingFeeder Feed Management & Channel Marketing Service now: http://www.shoppingfeeder.com
6
+ *
7
+ * @category design
8
+ * @package base_default_template_shoppingfeeder_fbtrack
9
+ * @copyright Copyright (c) 2015 Kevin Tucker (ShoppingFeeder)
10
+ *
11
+ */
12
+ ?>
13
+
14
+ <!-- Custom Audience Pixel Code -->
15
+ <script>
16
+ !function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?
17
+ n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n;
18
+ n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0;
19
+ t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window,
20
+ document,'script','//connect.facebook.net/en_US/fbevents.js');
21
+ // Insert Your Custom Audience Pixel ID below.
22
+ fbq('init', '<?php echo $this->getPixelId();?>');
23
+
24
+ <?php if ($this->getData('product') !== null):?>
25
+ fbq('track', '<?php echo addslashes($this->getData('action_type'));?>', {
26
+ content_name: '<?php echo addslashes($this->getData('product')->name);?>',
27
+ content_category: '<?php echo addslashes($this->getData('category'));?>',
28
+ content_ids: ['<?php echo addslashes($this->getData('product')->getId());?>'],
29
+ content_type: 'product',
30
+ value: <?php echo $this->getProductPrice();?>,
31
+ currency: '<?php echo $this->getCurrency();?>'
32
+ });
33
+ <?php endif;?>
34
+ <?php if ($this->getData('order') !== null):?>
35
+ fbq('track', '<?php echo addslashes($this->getData('action_type'));?>', {
36
+ content_ids: [<?php echo implode(',', $this->getData('order')['items']);?>],
37
+ content_type: 'product',
38
+ value: <?php echo $this->getData('order')['value'];?>,
39
+ currency: '<?php echo $this->getCurrency();?>'
40
+ });
41
+ <?php endif;?>
42
+
43
+ </script>
44
+ <!-- End Custom Audience Pixel Code -->
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>shoppingfeeder</name>
4
- <version>1.4.1</version>
5
  <stability>stable</stability>
6
  <license>GNU General Public License (GPL)</license>
7
  <channel>community</channel>
@@ -16,13 +16,11 @@ Use ShoppingFeeder to import your Shopify product catalogue, export it to numero
16
  Export to Google, Shopping.com, Nextag, kelkoo, PriceCheck, Shopmania, Fruugo and more!&#xD;
17
  &#xD;
18
  To set up your ShoppingFeeder account and install this extension seamlessly, create an account at: &lt;a href="http://www.shoppingfeeder.com/register"&gt;http://www.shoppingfeeder.com/register&lt;/a&gt;</description>
19
- <notes>Version 1.4 brings optimisations and a very exciting update enabling "Facebook Audience Pixel Tracking".&#xD;
20
- &#xD;
21
- ShoppingFeeder now helps you list and manage your product listings on Facebook Dynamic Product Ads.</notes>
22
  <authors><author><name>ShoppingFeeder</name><user>shoppingfeeder</user><email>support@shoppingfeeder.com</email></author></authors>
23
- <date>2015-10-12</date>
24
- <time>12:36:02</time>
25
- <contents><target name="mageetc"><dir name="modules"><file name="ShoppingFeeder_Service.xml" hash="90b374109c2d1281ddf527f24fa7d914"/></dir></target><target name="magecommunity"><dir name="ShoppingFeeder"><dir name="Service"><dir name="Block"><dir name="Adminhtml"><file name="Service.php" hash="8feb1712d6aa6a6897be8f80ba5d3f0b"/></dir><file name="Service.php" hash="48874f0e80ce70686b81eb5380e9f498"/><dir name="Tracking"><file name="Fb.php" hash="060687f842c896df73feb233b68b069b"/></dir></dir><dir name="Controller"><file name="FrontAuth.php" hash="28ed32e1bf3250362911a26869f0e6d7"/></dir><dir name="Helper"><file name="Data.php" hash="17589bd08352e497806bef9884972300"/></dir><dir name="Model"><file name="Auth.php" hash="2cff17b0750ff70695b32524627b2aaf"/><file name="Observer.php" hash="f4ab8f959787e1ecbcee704d974fdd2c"/><file name="Offers.php" hash="e387d6b513a9e6c1611f9ef74aa3782a"/><file name="Orders.php" hash="cc3c9f38ae41c11ab7dda0bcb8dd001f"/></dir><dir name="controllers"><file name="AttributesController.php" hash="e937c492f770bc8381a003a080cf878b"/><file name="FeedController.php" hash="92b70af3a048ece99d262480c51aa862"/><file name="OrdersController.php" hash="e0dcf407e15ca212b43ee0015c918675"/><file name="StoresController.php" hash="a29fa0e97299ce764fd66360cbf6632a"/><file name="TestController.php" hash="5138a844cb7cbc8e792df664057bdf9b"/><file name="VersionController.php" hash="122addf6d3a99fd34348448682dda505"/></dir><dir name="data"><file name="cacert.pem" hash="380df856e8f789c1af97d0da9a243769"/></dir><dir name="etc"><file name="config.xml" hash="8b8d53817319b7dcaffd44f0aa578532"/><file name="system.xml" hash="0c4b7f9ba0e97dc471216ea8149ac0e4"/></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="shoppingfeeder_service.xml" hash="4f3a5b5018c0328da4f9490d4c6042fd"/></dir><dir name="template"><dir name="shoppingfeeder"><file name="fbtrack.phtml" hash="a7d90e8f55037c9c5bdab515151db364"/></dir></dir></dir></dir></dir></target></contents>
26
  <compatible/>
27
  <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
28
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>shoppingfeeder</name>
4
+ <version>1.4.2</version>
5
  <stability>stable</stability>
6
  <license>GNU General Public License (GPL)</license>
7
  <channel>community</channel>
16
  Export to Google, Shopping.com, Nextag, kelkoo, PriceCheck, Shopmania, Fruugo and more!&#xD;
17
  &#xD;
18
  To set up your ShoppingFeeder account and install this extension seamlessly, create an account at: &lt;a href="http://www.shoppingfeeder.com/register"&gt;http://www.shoppingfeeder.com/register&lt;/a&gt;</description>
19
+ <notes>Bugfix for category listing in Facebook Audience Pixel Tracking</notes>
 
 
20
  <authors><author><name>ShoppingFeeder</name><user>shoppingfeeder</user><email>support@shoppingfeeder.com</email></author></authors>
21
+ <date>2015-10-22</date>
22
+ <time>14:42:03</time>
23
+ <contents><target name="mageetc"><dir name="modules"><file name="ShoppingFeeder_Service.xml" hash="90b374109c2d1281ddf527f24fa7d914"/></dir></target><target name="magecommunity"><dir name="ShoppingFeeder"><dir name="Fbtrack"><dir name="Block"><dir name="Adminhtml"><file name="Service.php" hash="2c0bb6d0c7f965c9583cfaae4890d053"/></dir><file name="Service.php" hash="56cd6921b7bda27e2ed66b80af1d927f"/><dir name="Tracking"><file name="Fb.php" hash="1926b36b1d6092b7566e2688559fa895"/></dir></dir><dir name="Helper"><file name="Data.php" hash="87df6b00fcfb2008697cf46d6d18cf75"/></dir><dir name="Model"><file name="Observer.php" hash="e327e00067f86ad8331e2ae41aad375a"/></dir><dir name="etc"><file name="config.xml" hash="2cbb1a1b1f6f9ecc77bf0eb406941a17"/><file name="system.xml" hash="227c0ffc63ff10b814d42cd9a8f8bad4"/></dir></dir><dir name="Service"><dir name="Block"><dir name="Adminhtml"><file name="Service.php" hash="8feb1712d6aa6a6897be8f80ba5d3f0b"/></dir><file name="Service.php" hash="48874f0e80ce70686b81eb5380e9f498"/><dir name="Tracking"><file name="Fb.php" hash="060687f842c896df73feb233b68b069b"/></dir></dir><dir name="Controller"><file name="FrontAuth.php" hash="28ed32e1bf3250362911a26869f0e6d7"/></dir><dir name="Helper"><file name="Data.php" hash="17589bd08352e497806bef9884972300"/></dir><dir name="Model"><file name="Auth.php" hash="2cff17b0750ff70695b32524627b2aaf"/><file name="Observer.php" hash="ceeaa90402718db395967ac5aaa1bb63"/><file name="Offers.php" hash="e387d6b513a9e6c1611f9ef74aa3782a"/><file name="Orders.php" hash="cc3c9f38ae41c11ab7dda0bcb8dd001f"/></dir><dir name="controllers"><file name="AttributesController.php" hash="e937c492f770bc8381a003a080cf878b"/><file name="FeedController.php" hash="92b70af3a048ece99d262480c51aa862"/><file name="OrdersController.php" hash="e0dcf407e15ca212b43ee0015c918675"/><file name="StoresController.php" hash="a29fa0e97299ce764fd66360cbf6632a"/><file name="TestController.php" hash="5138a844cb7cbc8e792df664057bdf9b"/><file name="VersionController.php" hash="673595d6eb21cce4db9aa1b072b468a3"/></dir><dir name="data"><file name="cacert.pem" hash="380df856e8f789c1af97d0da9a243769"/></dir><dir name="etc"><file name="config.xml" hash="8f70e5eb9970ca8a53f26ddaca509346"/><file name="system.xml" hash="e358d831424ccacdd393dfac49b8a994"/></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="shoppingfeeder_service.xml" hash="4f3a5b5018c0328da4f9490d4c6042fd"/></dir><dir name="template"><dir name="shoppingfeeder"><file name="fbtrack.phtml" hash="a7d90e8f55037c9c5bdab515151db364"/><file name="fbtrack_standalone.phtml" hash="a7d90e8f55037c9c5bdab515151db364"/></dir></dir></dir></dir></dir></target></contents>
24
  <compatible/>
25
  <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
26
  </package>