Version Notes
Added support for new Pinterest Tag javascript implementation, events supported: addToCart, checkout
Download this release
Release Info
Developer | Cadence Labs |
Extension | cadence_pinterest |
Version | 2.0.0 |
Comparing to | |
See all releases |
Code changes from version 1.0.0 to 2.0.0
- app/code/community/Cadence/Pinterest/Helper/Data.php +117 -4
- app/code/community/Cadence/Pinterest/Model/Observer.php +68 -0
- app/code/community/Cadence/Pinterest/Model/Session.php +42 -0
- app/code/community/Cadence/Pinterest/etc/config.xml +19 -1
- app/code/community/Cadence/Pinterest/etc/system.xml +25 -14
- app/design/frontend/base/default/layout/cadence_pinterest.xml +2 -6
- app/design/frontend/base/default/template/cadence/pinterest/conversion.phtml +17 -9
- app/design/frontend/base/default/template/cadence/pinterest/events.phtml +13 -0
- app/design/frontend/base/default/template/cadence/pinterest/visitor.phtml +13 -4
- package.xml +9 -8
app/code/community/Cadence/Pinterest/Helper/Data.php
CHANGED
@@ -4,6 +4,8 @@
|
|
4 |
*/
|
5 |
class Cadence_Pinterest_Helper_Data extends Mage_Core_Helper_Abstract
|
6 |
{
|
|
|
|
|
7 |
public function isVisitorPixelEnabled()
|
8 |
{
|
9 |
return Mage::getStoreConfig("cadence_pinterest/visitor/enabled");
|
@@ -14,13 +16,124 @@ class Cadence_Pinterest_Helper_Data extends Mage_Core_Helper_Abstract
|
|
14 |
return Mage::getStoreConfig("cadence_pinterest/conversion/enabled");
|
15 |
}
|
16 |
|
17 |
-
public function
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
{
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
}
|
21 |
|
22 |
-
|
23 |
{
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
}
|
26 |
}
|
4 |
*/
|
5 |
class Cadence_Pinterest_Helper_Data extends Mage_Core_Helper_Abstract
|
6 |
{
|
7 |
+
protected $_order;
|
8 |
+
|
9 |
public function isVisitorPixelEnabled()
|
10 |
{
|
11 |
return Mage::getStoreConfig("cadence_pinterest/visitor/enabled");
|
16 |
return Mage::getStoreConfig("cadence_pinterest/conversion/enabled");
|
17 |
}
|
18 |
|
19 |
+
public function isAddToCartPixelEnabled()
|
20 |
+
{
|
21 |
+
return Mage::getStoreConfig("cadence_pinterest/add_to_cart/enabled");
|
22 |
+
}
|
23 |
+
|
24 |
+
public function getTagId()
|
25 |
+
{
|
26 |
+
return Mage::getStoreConfig("cadence_pinterest/visitor/tag_id");
|
27 |
+
}
|
28 |
+
|
29 |
+
/**
|
30 |
+
* @param $event
|
31 |
+
* @param $data
|
32 |
+
* @return string
|
33 |
+
*/
|
34 |
+
public function getPixelHtml($event, $data = false)
|
35 |
+
{
|
36 |
+
$json = '';
|
37 |
+
if ($data) {
|
38 |
+
$json = ', ' . json_encode($data);
|
39 |
+
}
|
40 |
+
$html = <<<HTML
|
41 |
+
<!-- Begin Pinterest {$event} Pixel -->
|
42 |
+
<script type="text/javascript">
|
43 |
+
pintrk('track', '{$event}'{$json});
|
44 |
+
</script>
|
45 |
+
<!-- End Facebook {$event} Pixel -->
|
46 |
+
HTML;
|
47 |
+
return $html;
|
48 |
+
}
|
49 |
+
|
50 |
+
public function getOrderIDs()
|
51 |
{
|
52 |
+
$orderIDs = array();
|
53 |
+
|
54 |
+
foreach($this->_getOrder()->getAllVisibleItems() as $item){
|
55 |
+
$product = Mage::getModel('catalog/product')->load( $item->getProductId() );
|
56 |
+
$orderIDs = array_merge($orderIDs, $this->_getProductTrackID($product));
|
57 |
+
}
|
58 |
+
|
59 |
+
return json_encode($orderIDs);
|
60 |
+
}
|
61 |
+
|
62 |
+
protected function _getOrder(){
|
63 |
+
if(!$this->_order){
|
64 |
+
$orderId = Mage::getSingleton('checkout/type_onepage')->getCheckout()->getLastOrderId();
|
65 |
+
$this->_order = Mage::getModel('sales/order')->load($orderId);
|
66 |
+
}
|
67 |
+
|
68 |
+
return $this->_order;
|
69 |
+
}
|
70 |
+
|
71 |
+
protected function _getProductTrackID($product)
|
72 |
+
{
|
73 |
+
$productType = $product->getTypeID();
|
74 |
+
|
75 |
+
if($productType == "grouped") {
|
76 |
+
return $this->_getProductIDs($product);
|
77 |
+
} else {
|
78 |
+
return $this->_getProductID($product);
|
79 |
+
}
|
80 |
}
|
81 |
|
82 |
+
protected function _getProductIDs($product)
|
83 |
{
|
84 |
+
$group = Mage::getModel('catalog/product_type_grouped')->setProduct($product);
|
85 |
+
$group_collection = $group->getAssociatedProductCollection();
|
86 |
+
$ids = array();
|
87 |
+
|
88 |
+
foreach ($group_collection as $group_product) {
|
89 |
+
|
90 |
+
$ids[] = $this->_getProductID($group_product);
|
91 |
+
}
|
92 |
+
|
93 |
+
return $ids;
|
94 |
+
}
|
95 |
+
|
96 |
+
protected function _getProductID($product)
|
97 |
+
{
|
98 |
+
return array(
|
99 |
+
$product->getSku()
|
100 |
+
);
|
101 |
+
}
|
102 |
+
|
103 |
+
public function getOrderItemsQty()
|
104 |
+
{
|
105 |
+
$order = $this->_getOrder();
|
106 |
+
|
107 |
+
$qty = 0;
|
108 |
+
|
109 |
+
/** @var Mage_Sales_Model_Order_Item $item */
|
110 |
+
foreach($order->getAllVisibleItems() as $item) {
|
111 |
+
$qty += $item->getQtyOrdered();
|
112 |
+
}
|
113 |
+
|
114 |
+
return max(round($qty), 1);
|
115 |
+
}
|
116 |
+
|
117 |
+
/**
|
118 |
+
* @return string
|
119 |
+
*/
|
120 |
+
public function getOrderItemsJson()
|
121 |
+
{
|
122 |
+
$order = $this->_getOrder();
|
123 |
+
|
124 |
+
$itemData = array();
|
125 |
+
|
126 |
+
/** @var Mage_Sales_Model_Order_Item $item */
|
127 |
+
foreach($order->getAllVisibleItems() as $item) {
|
128 |
+
$qty = max(round($item->getQtyOrdered()), 1);
|
129 |
+
$itemData[] = [
|
130 |
+
"product_name" => $item->getName(),
|
131 |
+
"product_id" => $item->getSku(),
|
132 |
+
"product_price" => round($item->getPrice(),2),
|
133 |
+
"product_quantity" => $qty
|
134 |
+
];
|
135 |
+
}
|
136 |
+
|
137 |
+
return json_encode($itemData);
|
138 |
}
|
139 |
}
|
app/code/community/Cadence/Pinterest/Model/Observer.php
ADDED
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* @author Alan Barber <alan@cadence-labs.com>
|
4 |
+
*/
|
5 |
+
Class Cadence_Pinterest_Model_Observer
|
6 |
+
{
|
7 |
+
/**
|
8 |
+
* @param Varien_Event_Observer $obs
|
9 |
+
* @return $this
|
10 |
+
*/
|
11 |
+
public function onSalesQuoteProductAddAfter(Varien_Event_Observer $obs)
|
12 |
+
{
|
13 |
+
if (!$this->_helper()->isAddToCartPixelEnabled()) {
|
14 |
+
return $this;
|
15 |
+
}
|
16 |
+
|
17 |
+
$items = $obs->getItems();
|
18 |
+
|
19 |
+
$candidates = array_replace(array(
|
20 |
+
'value' => 0.00,
|
21 |
+
'order_quantity' => 0,
|
22 |
+
'line_items' => array()
|
23 |
+
), $this->_getSession()->getAddToCart() ?: array());
|
24 |
+
|
25 |
+
/** @var Mage_Sales_Model_Quote_Item $item */
|
26 |
+
foreach ($items as $item) {
|
27 |
+
if ($item->getParentItem()) {
|
28 |
+
continue;
|
29 |
+
}
|
30 |
+
$candidates['value'] += $item->getProduct()->getFinalPrice() * $item->getProduct()->getQty();
|
31 |
+
$candidates['order_quantity'] += $item->getProduct()->getQty();
|
32 |
+
$candidates['line_items'][] = [
|
33 |
+
"product_name" => $item->getName(),
|
34 |
+
"product_id" => $item->getSku(),
|
35 |
+
"product_price" => round($item->getProduct()->getFinalPrice(),2),
|
36 |
+
"product_quantity" => max(round($item->getProduct()->getQty()), 1)
|
37 |
+
];
|
38 |
+
}
|
39 |
+
|
40 |
+
// Ensure the quantity is a whole integer
|
41 |
+
$data = array(
|
42 |
+
'value' => round($candidates['value'],2),
|
43 |
+
'order_quantity' => max(round($candidates['order_quantity']), 1),
|
44 |
+
'currency' => Mage::app()->getStore()->getCurrentCurrencyCode(),
|
45 |
+
'line_items' => $candidates['line_items']
|
46 |
+
);
|
47 |
+
|
48 |
+
$this->_getSession()->setAddToCart($data);
|
49 |
+
|
50 |
+
return $this;
|
51 |
+
}
|
52 |
+
|
53 |
+
/**
|
54 |
+
* @return Cadence_Pinterest_Model_Session
|
55 |
+
*/
|
56 |
+
protected function _getSession()
|
57 |
+
{
|
58 |
+
return Mage::getSingleton('cadence_pinterest/session');
|
59 |
+
}
|
60 |
+
|
61 |
+
/**
|
62 |
+
* @return Cadence_Pinterest_Helper_Data
|
63 |
+
*/
|
64 |
+
protected function _helper()
|
65 |
+
{
|
66 |
+
return Mage::helper("cadence_pinterest");
|
67 |
+
}
|
68 |
+
}
|
app/code/community/Cadence/Pinterest/Model/Session.php
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* @author Alan Barber <alan@cadence-labs.com>
|
4 |
+
*/
|
5 |
+
Class Cadence_Pinterest_Model_Session extends Mage_Core_Model_Session_Abstract
|
6 |
+
{
|
7 |
+
public function __construct()
|
8 |
+
{
|
9 |
+
$this->init('cadence_pinterest');
|
10 |
+
}
|
11 |
+
|
12 |
+
/**
|
13 |
+
* @param $data
|
14 |
+
* @return $this
|
15 |
+
*/
|
16 |
+
public function setAddToCart($data)
|
17 |
+
{
|
18 |
+
$this->setData('add_to_cart', $data);
|
19 |
+
return $this;
|
20 |
+
}
|
21 |
+
|
22 |
+
/**
|
23 |
+
* @return mixed|null
|
24 |
+
*/
|
25 |
+
public function getAddToCart()
|
26 |
+
{
|
27 |
+
if ($this->hasAddToCart()) {
|
28 |
+
$data = $this->getData('add_to_cart');
|
29 |
+
$this->unsetData('add_to_cart');
|
30 |
+
return $data;
|
31 |
+
}
|
32 |
+
return null;
|
33 |
+
}
|
34 |
+
|
35 |
+
/**
|
36 |
+
* @return bool
|
37 |
+
*/
|
38 |
+
public function hasAddToCart()
|
39 |
+
{
|
40 |
+
return $this->hasData('add_to_cart');
|
41 |
+
}
|
42 |
+
}
|
app/code/community/Cadence/Pinterest/etc/config.xml
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
<config>
|
3 |
<modules>
|
4 |
<Cadence_Pinterest>
|
5 |
-
<version>0.
|
6 |
</Cadence_Pinterest>
|
7 |
</modules>
|
8 |
<global>
|
@@ -11,6 +11,11 @@
|
|
11 |
<class>Cadence_Pinterest_Helper</class>
|
12 |
</cadence_pinterest>
|
13 |
</helpers>
|
|
|
|
|
|
|
|
|
|
|
14 |
</global>
|
15 |
<frontend>
|
16 |
<layout>
|
@@ -20,6 +25,16 @@
|
|
20 |
</cadence_pinterest>
|
21 |
</updates>
|
22 |
</layout>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
</frontend>
|
24 |
<default>
|
25 |
<cadence_pinterest>
|
@@ -29,6 +44,9 @@
|
|
29 |
<conversion>
|
30 |
<enabled>0</enabled>
|
31 |
</conversion>
|
|
|
|
|
|
|
32 |
</cadence_pinterest>
|
33 |
</default>
|
34 |
</config>
|
2 |
<config>
|
3 |
<modules>
|
4 |
<Cadence_Pinterest>
|
5 |
+
<version>2.0.0</version>
|
6 |
</Cadence_Pinterest>
|
7 |
</modules>
|
8 |
<global>
|
11 |
<class>Cadence_Pinterest_Helper</class>
|
12 |
</cadence_pinterest>
|
13 |
</helpers>
|
14 |
+
<models>
|
15 |
+
<cadence_pinterest>
|
16 |
+
<class>Cadence_Pinterest_Model</class>
|
17 |
+
</cadence_pinterest>
|
18 |
+
</models>
|
19 |
</global>
|
20 |
<frontend>
|
21 |
<layout>
|
25 |
</cadence_pinterest>
|
26 |
</updates>
|
27 |
</layout>
|
28 |
+
<events>
|
29 |
+
<sales_quote_product_add_after>
|
30 |
+
<observers>
|
31 |
+
<cadence_pinterest_add_to_cart>
|
32 |
+
<class>Cadence_Pinterest_Model_Observer</class>
|
33 |
+
<method>onSalesQuoteProductAddAfter</method>
|
34 |
+
</cadence_pinterest_add_to_cart>
|
35 |
+
</observers>
|
36 |
+
</sales_quote_product_add_after>
|
37 |
+
</events>
|
38 |
</frontend>
|
39 |
<default>
|
40 |
<cadence_pinterest>
|
44 |
<conversion>
|
45 |
<enabled>0</enabled>
|
46 |
</conversion>
|
47 |
+
<add_to_cart>
|
48 |
+
<enabled>0</enabled>
|
49 |
+
</add_to_cart>
|
50 |
</cadence_pinterest>
|
51 |
</default>
|
52 |
</config>
|
app/code/community/Cadence/Pinterest/etc/system.xml
CHANGED
@@ -8,7 +8,7 @@
|
|
8 |
</tabs>
|
9 |
<sections>
|
10 |
<cadence_pinterest translate="label">
|
11 |
-
<label>Pinterest
|
12 |
<tab>cadence</tab>
|
13 |
<frontend_type>text</frontend_type>
|
14 |
<sort_order>100</sort_order>
|
@@ -17,7 +17,7 @@
|
|
17 |
<show_in_store>1</show_in_store>
|
18 |
<groups>
|
19 |
<visitor translate="label">
|
20 |
-
<label>
|
21 |
<show_in_default>1</show_in_default>
|
22 |
<show_in_website>1</show_in_website>
|
23 |
<show_in_store>1</show_in_store>
|
@@ -32,19 +32,19 @@
|
|
32 |
<show_in_website>1</show_in_website>
|
33 |
<show_in_store>1</show_in_store>
|
34 |
</enabled>
|
35 |
-
<
|
36 |
-
<label>
|
37 |
<frontend_type>text</frontend_type>
|
38 |
<sort_order>20</sort_order>
|
39 |
<show_in_default>1</show_in_default>
|
40 |
<show_in_website>1</show_in_website>
|
41 |
<show_in_store>1</show_in_store>
|
42 |
-
<comment>This is the
|
43 |
-
</
|
44 |
</fields>
|
45 |
</visitor>
|
46 |
<conversion translate="label">
|
47 |
-
<label>
|
48 |
<show_in_default>1</show_in_default>
|
49 |
<show_in_website>1</show_in_website>
|
50 |
<show_in_store>1</show_in_store>
|
@@ -58,18 +58,29 @@
|
|
58 |
<show_in_default>1</show_in_default>
|
59 |
<show_in_website>1</show_in_website>
|
60 |
<show_in_store>1</show_in_store>
|
|
|
61 |
</enabled>
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
<show_in_default>1</show_in_default>
|
67 |
<show_in_website>1</show_in_website>
|
68 |
<show_in_store>1</show_in_store>
|
69 |
-
<comment>
|
70 |
-
</
|
71 |
</fields>
|
72 |
-
</
|
73 |
</groups>
|
74 |
</cadence_pinterest>
|
75 |
</sections>
|
8 |
</tabs>
|
9 |
<sections>
|
10 |
<cadence_pinterest translate="label">
|
11 |
+
<label>Pinterest Tag</label>
|
12 |
<tab>cadence</tab>
|
13 |
<frontend_type>text</frontend_type>
|
14 |
<sort_order>100</sort_order>
|
17 |
<show_in_store>1</show_in_store>
|
18 |
<groups>
|
19 |
<visitor translate="label">
|
20 |
+
<label>Base Tag</label>
|
21 |
<show_in_default>1</show_in_default>
|
22 |
<show_in_website>1</show_in_website>
|
23 |
<show_in_store>1</show_in_store>
|
32 |
<show_in_website>1</show_in_website>
|
33 |
<show_in_store>1</show_in_store>
|
34 |
</enabled>
|
35 |
+
<tag_id translate="label">
|
36 |
+
<label>Tag Id (TID)</label>
|
37 |
<frontend_type>text</frontend_type>
|
38 |
<sort_order>20</sort_order>
|
39 |
<show_in_default>1</show_in_default>
|
40 |
<show_in_website>1</show_in_website>
|
41 |
<show_in_store>1</show_in_store>
|
42 |
+
<comment>This is the TID (tag id) for the Pinterest tag (see the install guide for instructions on where to find this).</comment>
|
43 |
+
</tag_id>
|
44 |
</fields>
|
45 |
</visitor>
|
46 |
<conversion translate="label">
|
47 |
+
<label>Conversion Event (Optional)</label>
|
48 |
<show_in_default>1</show_in_default>
|
49 |
<show_in_website>1</show_in_website>
|
50 |
<show_in_store>1</show_in_store>
|
58 |
<show_in_default>1</show_in_default>
|
59 |
<show_in_website>1</show_in_website>
|
60 |
<show_in_store>1</show_in_store>
|
61 |
+
<comment>The base tag must be enabled to track conversions. Includes parameters for grand total, quantity ordered, and currency.</comment>
|
62 |
</enabled>
|
63 |
+
</fields>
|
64 |
+
</conversion>
|
65 |
+
<add_to_cart translate="label">
|
66 |
+
<label>Add To Cart (Optional)</label>
|
67 |
+
<show_in_default>1</show_in_default>
|
68 |
+
<show_in_website>1</show_in_website>
|
69 |
+
<show_in_store>1</show_in_store>
|
70 |
+
<sort_order>3</sort_order>
|
71 |
+
<fields>
|
72 |
+
<enabled translate="label" module="cadence_pinterest">
|
73 |
+
<label>Enable</label>
|
74 |
+
<frontend_type>select</frontend_type>
|
75 |
+
<source_model>adminhtml/system_config_source_enabledisable</source_model>
|
76 |
+
<sort_order>10</sort_order>
|
77 |
<show_in_default>1</show_in_default>
|
78 |
<show_in_website>1</show_in_website>
|
79 |
<show_in_store>1</show_in_store>
|
80 |
+
<comment>The base tag must be enabled to track AddToCart. Includes parameters for product subtotal, quantity added, and currency.</comment>
|
81 |
+
</enabled>
|
82 |
</fields>
|
83 |
+
</add_to_cart>
|
84 |
</groups>
|
85 |
</cadence_pinterest>
|
86 |
</sections>
|
app/design/frontend/base/default/layout/cadence_pinterest.xml
CHANGED
@@ -2,7 +2,8 @@
|
|
2 |
<layout version="0.1.0">
|
3 |
<default>
|
4 |
<reference name="head">
|
5 |
-
<block type="core/template" template="cadence/pinterest/visitor.phtml" />
|
|
|
6 |
</reference>
|
7 |
</default>
|
8 |
<checkout_onepage_success translate="label">
|
@@ -10,9 +11,4 @@
|
|
10 |
<block type="core/template" template="cadence/pinterest/conversion.phtml" />
|
11 |
</reference>
|
12 |
</checkout_onepage_success>
|
13 |
-
<checkout_multishipping_success translate="label">
|
14 |
-
<reference name="after_body_start">
|
15 |
-
<block type="core/template" template="cadence/pinterest/conversion.phtml" />
|
16 |
-
</reference>
|
17 |
-
</checkout_multishipping_success>
|
18 |
</layout>
|
2 |
<layout version="0.1.0">
|
3 |
<default>
|
4 |
<reference name="head">
|
5 |
+
<block type="core/template" template="cadence/pinterest/visitor.phtml" name="cadence_pinterest_visitor" />
|
6 |
+
<block type="core/template" template="cadence/pinterest/events.phtml" name="cadence_pinterest_events" />
|
7 |
</reference>
|
8 |
</default>
|
9 |
<checkout_onepage_success translate="label">
|
11 |
<block type="core/template" template="cadence/pinterest/conversion.phtml" />
|
12 |
</reference>
|
13 |
</checkout_onepage_success>
|
|
|
|
|
|
|
|
|
|
|
14 |
</layout>
|
app/design/frontend/base/default/template/cadence/pinterest/conversion.phtml
CHANGED
@@ -4,7 +4,7 @@ $helper = Mage::helper("cadence_pinterest");
|
|
4 |
if (!$helper->isConversionPixelEnabled()) {
|
5 |
return;
|
6 |
}
|
7 |
-
$id = $helper->
|
8 |
?>
|
9 |
<?php
|
10 |
$order_id = Mage::getSingleton('checkout/session')->getLastOrderId();
|
@@ -16,12 +16,20 @@ if (!$order_id || intval($order_id) < 1) {
|
|
16 |
$order = Mage::getModel('sales/order')->load($order_id);
|
17 |
$grand_total = round($order->getGrandTotal(), 2);
|
18 |
$currency_code = Mage::app()->getStore()->getCurrentCurrencyCode();
|
19 |
-
$
|
20 |
-
|
21 |
-
foreach($order->getAllVisibleItems() as $item) {
|
22 |
-
$total_qty += $item->getQtyOrdered();
|
23 |
-
}
|
24 |
?>
|
25 |
-
<!-- Pinterest Conversion
|
26 |
-
<
|
27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
if (!$helper->isConversionPixelEnabled()) {
|
5 |
return;
|
6 |
}
|
7 |
+
$id = $helper->getTagId();
|
8 |
?>
|
9 |
<?php
|
10 |
$order_id = Mage::getSingleton('checkout/session')->getLastOrderId();
|
16 |
$order = Mage::getModel('sales/order')->load($order_id);
|
17 |
$grand_total = round($order->getGrandTotal(), 2);
|
18 |
$currency_code = Mage::app()->getStore()->getCurrentCurrencyCode();
|
19 |
+
$qtyOrdered = $helper->getOrderItemsQty();
|
20 |
+
$orderItemJson = $helper->getOrderItemsJson();
|
|
|
|
|
|
|
21 |
?>
|
22 |
+
<!-- Pinterest Conversion Code for Conversions -->
|
23 |
+
<script>
|
24 |
+
pintrk('track','checkout', {
|
25 |
+
value: <?php echo $grand_total ?>,
|
26 |
+
currency: '<?php echo $currency_code ?>',
|
27 |
+
order_quantity: <?php echo $qtyOrdered; ?>,
|
28 |
+
line_items: <?php echo $orderItemJson ?>
|
29 |
+
});
|
30 |
+
</script>
|
31 |
+
<noscript>
|
32 |
+
<img height="1" width="1" style="display:none;" alt=""
|
33 |
+
src="https://ct.pinterest.com/v3/?tid=<?php echo $id ?>&event=checkout&ed[value]=<?php echo $grand_total ?>&ed[order_quantity]=<?php echo $qtyOrdered
|
34 |
+
?>&ed[currency]=<?php echo $currency_code ?>&noscript=1"/>
|
35 |
+
</noscript>
|
app/design/frontend/base/default/template/cadence/pinterest/events.phtml
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* @author Cadence Labs <info@cadence-labs.com>
|
4 |
+
* @var Cadence_Pinterest_Helper_Data $helper
|
5 |
+
* @var Cadence_Pinterest_Model_Session $session
|
6 |
+
*/
|
7 |
+
|
8 |
+
$helper = Mage::helper("cadence_pinterest");
|
9 |
+
$session = Mage::getSingleton('cadence_pinterest/session');
|
10 |
+
|
11 |
+
if ($helper->isAddToCartPixelEnabled() && $session->hasAddToCart()) {
|
12 |
+
echo $helper->getPixelHtml('AddToCart', $session->getAddToCart());
|
13 |
+
}
|
app/design/frontend/base/default/template/cadence/pinterest/visitor.phtml
CHANGED
@@ -1,10 +1,19 @@
|
|
1 |
<?php
|
|
|
2 |
$helper = Mage::helper("cadence_pinterest");
|
3 |
if (!$helper->isVisitorPixelEnabled()) {
|
4 |
return;
|
5 |
}
|
6 |
-
$id = $helper->
|
7 |
?>
|
8 |
-
<!-- Pinterest
|
9 |
-
<
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
<?php
|
2 |
+
/** @var Cadence_Pinterest_Helper_Data $helper */
|
3 |
$helper = Mage::helper("cadence_pinterest");
|
4 |
if (!$helper->isVisitorPixelEnabled()) {
|
5 |
return;
|
6 |
}
|
7 |
+
$id = $helper->getTagId();
|
8 |
?>
|
9 |
+
<!-- Pinterest Pixel Base Code -->
|
10 |
+
<script type="text/javascript">
|
11 |
+
!function(e){if(!window.pintrk){window.pintrk=function(){window.pintrk.queue.push(Array.prototype.slice.call(arguments))};var n=window.pintrk;n.queue=[],n.version="3.0";var t=document.createElement("script");t.async=!0,t.src=e;var r=document.getElementsByTagName("script")[0];r.parentNode.insertBefore(t,r)}}("https://s.pinimg.com/ct/core.js");
|
12 |
+
pintrk('load', '<?php echo $id ?>');
|
13 |
+
pintrk('page');
|
14 |
+
</script>
|
15 |
+
<noscript>
|
16 |
+
<img height="1" width="1" style="display:none;" alt=""
|
17 |
+
src="https://ct.pinterest.com/v3/?tid=<?php echo $id ?>&noscript=1" />
|
18 |
+
</noscript>
|
19 |
+
<!-- End Pinterest Pixel Base Code --!>
|
package.xml
CHANGED
@@ -1,17 +1,18 @@
|
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>cadence_pinterest</name>
|
4 |
-
<version>
|
5 |
<stability>stable</stability>
|
6 |
<license>GNU GPL</license>
|
7 |
<channel>community</channel>
|
8 |
<extends/>
|
9 |
<summary>This extension allows you to quickly implement Pinterest conversion tracking and code on your Magento store. Supports Visit and Checkout conversion events. </summary>
|
10 |
-
<description><p>This Pinterest
|
11 |
-
<p>After setting your Pinterested TID (
|
12 |
<ul>
|
13 |
<li>Track Visit (code is displayed on every page)</li>
|
14 |
<li>Track Checkouts (code is displayed only upon successful checkout)</li>
|
|
|
15 |
</ul> 
|
16 |
<p> The extension works by attaching the relevant pixel code (for either Visits or Conversions) to your store's webpage, just after the start of the <strong>body</strong> tag. If you have the correct pixel id installed, Pinterest will do the rest.</p><p>Click here to view our <a href="https://www.cadence-labs.com/2016/05/free-pinterest-tracking-pixel-extension-magento/">Pinterest Tracking Pixel Install Guide</a>.</p>
|
17 |
<h2>Multistore; Tracks Grand Total and Quantity</h2>
|
@@ -19,11 +20,11 @@
|
|
19 |

|
20 |
<h2>About The Developer</h2>
|
21 |
<p><a href="http://www.cadence-labs.com/" title="Cadence Labs">Cadence Labs</a> is a digital design, software development, and Magento agency based in Boulder, Colorado. Our developers are Magento certified eCommerce geeks!</p></description>
|
22 |
-
<notes>
|
23 |
<authors><author><name>Cadence Labs</name><user>cadencelabs</user><email>alan@cadence-labs.com</email></author></authors>
|
24 |
-
<date>
|
25 |
-
<time>
|
26 |
-
<contents><target name="magecommunity"><dir name="Cadence"><dir name="Pinterest"><dir name="Helper"><file name="Data.php" hash="
|
27 |
<compatible/>
|
28 |
-
<dependencies><required><php><min>5.2.0</min><max>
|
29 |
</package>
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>cadence_pinterest</name>
|
4 |
+
<version>2.0.0</version>
|
5 |
<stability>stable</stability>
|
6 |
<license>GNU GPL</license>
|
7 |
<channel>community</channel>
|
8 |
<extends/>
|
9 |
<summary>This extension allows you to quickly implement Pinterest conversion tracking and code on your Magento store. Supports Visit and Checkout conversion events. </summary>
|
10 |
+
<description><p>This Pinterest Tag extension allows you to quickly implement visitor, add-to-cart, and checkout events through the Pinterest Conversion Pixel. <a href="https://www.cadence-labs.com/2016/05/free-pinterest-tracking-pixel-extension-magento/" title="User Manual"><strong>Learn how it works.</strong></a>. </p>
|
11 |
+
<p>After setting your Pinterested TID (Tag Id), you may:</p>
|
12 |
<ul>
|
13 |
<li>Track Visit (code is displayed on every page)</li>
|
14 |
<li>Track Checkouts (code is displayed only upon successful checkout)</li>
|
15 |
+
<li>Track AddToCart</li>
|
16 |
</ul> 
|
17 |
<p> The extension works by attaching the relevant pixel code (for either Visits or Conversions) to your store's webpage, just after the start of the <strong>body</strong> tag. If you have the correct pixel id installed, Pinterest will do the rest.</p><p>Click here to view our <a href="https://www.cadence-labs.com/2016/05/free-pinterest-tracking-pixel-extension-magento/">Pinterest Tracking Pixel Install Guide</a>.</p>
|
18 |
<h2>Multistore; Tracks Grand Total and Quantity</h2>
|
20 |

|
21 |
<h2>About The Developer</h2>
|
22 |
<p><a href="http://www.cadence-labs.com/" title="Cadence Labs">Cadence Labs</a> is a digital design, software development, and Magento agency based in Boulder, Colorado. Our developers are Magento certified eCommerce geeks!</p></description>
|
23 |
+
<notes>Added support for new Pinterest Tag javascript implementation, events supported: addToCart, checkout</notes>
|
24 |
<authors><author><name>Cadence Labs</name><user>cadencelabs</user><email>alan@cadence-labs.com</email></author></authors>
|
25 |
+
<date>2017-07-18</date>
|
26 |
+
<time>22:58:48</time>
|
27 |
+
<contents><target name="magecommunity"><dir name="Cadence"><dir name="Pinterest"><dir name="Helper"><file name="Data.php" hash="14d312759fcac6d8698d7b0896eba7d8"/></dir><dir name="Model"><file name="Observer.php" hash="67020552b997f0add7aad51a1c9424fe"/><file name="Session.php" hash="9d3ce8bb971fb9b7cfa375a7f45ed13a"/></dir><dir name="etc"><file name="adminhtml.xml" hash="8a6e311f8ef36556d905501eeff33480"/><file name="config.xml" hash="cf84bc50432330dd3b2569a3c6525c01"/><file name="system.xml" hash="2dda0b9ea42e5a044bc0dfa40885cbaa"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Cadence_Pinterest.xml" hash="9d220294781c37382bc941547b346618"/></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="cadence_pinterest.xml" hash="91c4c6dcfe4d40f48a41fa6611fc45ad"/></dir><dir name="template"><dir name="cadence"><dir name="pinterest"><file name="conversion.phtml" hash="5eb7d67a31c4b74ac48949cec0a450d0"/><file name="events.phtml" hash="bc90c17ba88b16bfc61bd10f245151a9"/><file name="visitor.phtml" hash="15ce51a2586ca1ae13e61585d669fce4"/></dir></dir></dir></dir></dir></dir></target></contents>
|
28 |
<compatible/>
|
29 |
+
<dependencies><required><php><min>5.2.0</min><max>7.1.9</max></php></required></dependencies>
|
30 |
</package>
|