Permalink
Browse files

First commit

  • Loading branch information...
0 parents commit 1bb4b9199121090d953317e993c9b8b4b484f70e @eristoddle committed Aug 7, 2012
@@ -0,0 +1,74 @@
+Name
+====
+Piwik Ecommerce for ZenCart version 1.3.9 and lower
+
+Version Date
+============
+v 1.0.0 08.07.2012
+
+Author
+======
+Stephan Miller http://www.StephanMiller.com
+
+Description
+============
+A plugin that adds Piwik ecommerce tracking to Zen Cart as well as access to Piwik reports in the ZenCart reports menu. This plugin was written by [Stephan Miller](http://www.stephanmiller.com) for [a book on Piwik Analytics](http://www.packtpub.com/piwik-web-analytics-essentials/book) published by Packt Publishing.
+
+Support forum
+=============
+Will be adding
+
+Affected files
+==============
+Changed files
+-------------
+tpl_footer.php in your current template
+
+New files
+---------
+- /includes/templates/YOUR_TEMPLATE/common/tpl_footer_piwik.php
+- /includes/templates/YOUR_TEMPLATE/templates/tpl_shopping_cart_default.php
+- /includes/templates/YOUR_TEMPLATE/templates/tpl_checkout_success_default.php
+- /functions/includes/PiwikEcommerce.php
+- /admin/includes/PiwikEcommerce.php
+- /admin/includes/boxes/extra_boxes/PiwikEcommerce_tools_dhtml.php
+- /admin/includes/extra_datafiles/PiwikEcommerce.php
+- /admin/includes/languages/english/extra_definitions/PiwikEcommerce.php
+
+Affects DB
+==========
+Yes (creates new records into configuration_group and configuration tables)
+
+DISCLAIMER
+==========
+Installation of this contribution is done at your own risk.
+Backup your ZenCart database and any and all applicable files before proceeding.
+
+Features:
+=========
+- supports e-commerce tracking
+- admin menu to enter Piwik details
+- admin|reports menu to view Piwik stats
+
+Install:
+============
+
+1. Go to Admin->Tools->Install SQL Patches and install install.sql by copy and pasting the contents of the file into the form there.
+
+2. Upload catalog/includes/functions/extra_functions/piwikecommerce.php to the /includes/functions/extra_functions/ folder of your ZenCart installation.
+
+3. Upload the contents of the catalog/admin folder to the admin folder of your ZenCart installation. Note that if you renamed your admin folder for security reasons, it will not be named "admin" now.
+
+4. If you are using a default footer file for your current template, you can upload catalog/includes/templates/YOUR_TEMPLATE/common/tpl_footer.php to the folder of your current template to replace the tpl_footer.php file in your template's common folder. If you are using a modified tpl_footer.php file in your template, you must copy the code between <!-- Piwik with E-Commerce Tracking--> and <!-- End Piwik with E-Commerce Tracking--> at the bottom of the catalog/includes/templates/YOUR_TEMPLATE/common/tpl_footer.php file to the bottom of your current tpl_footer.php file.
+
+5. If you are using a default tpl_shopping_cart_default.php template file for your current template, you can upload catalog/includes/templates/YOUR_TEMPLATE/templates/tpl_shopping_cart_default.php to the folder of your current template to replace the tpl_shopping_cart_default.php file in your template's common folder. If you are using a modified tpl_shopping_cart_default.php file in your template, you must copy the code between <!-- Piwik with E-Commerce Tracking--> and <!-- End Piwik with E-Commerce Tracking--> at the top of the catalog/includes/templates/YOUR_TEMPLATE/templates/tpl_shopping_cart_default.php file to the top of your current tpl_shopping_cart_default.php file, right after the set of comments at the top of the file.
+
+6. If you are using a default tpl_checkout_success_default.php template file for your current template, you can upload catalog/includes/templates/YOUR_TEMPLATE/templates/tpl_checkout_success_default.php to the folder of your current template to replace the tpl_checkout_success_default.php file in your template's common folder. If you are using a modified tpl_shopping_cart_default.php file in your template, you must copy the code between <!-- Piwik with E-Commerce Tracking--> and <!-- End Piwik with E-Commerce Tracking--> at the top of the catalog/includes/templates/YOUR_TEMPLATE/templates/checkout_success_default.php file to the top of your current tpl_shopping_cart_default.php file, right after the set of comments at the top of the file.
+
+7. Add your Piwik credentials at Admin->Configuration->Piwik Analytics Configuration
+
+8. View your Piwik reports dashboard at Admin->Reports->Piwik Analytics Reports
+
+Issues
+======
+Because of the embedded widget and cross domain issues, there may be two vertical scroll bars. I thought of creating a shim page to fix it, but this is still an ugly fix.
@@ -0,0 +1,74 @@
+Name
+====
+Piwik Ecommerce for ZenCart version 1.3.9 and lower
+
+Version Date
+============
+v 1.0.0 08.07.2012
+
+Author
+======
+Stephan Miller http://www.StephanMiller.com
+
+Description
+============
+A plugin that adds Piwik ecommerce tracking to Zen Cart as well as access to Piwik reports in the ZenCart reports menu. This plugin was written by [Stephan Miller](http://www.stephanmiller.com) for [a book on Piwik Analytics](http://www.packtpub.com/piwik-web-analytics-essentials/book) published by Packt Publishing.
+
+Support forum
+=============
+Will be adding
+
+Affected files
+==============
+Changed files
+-------------
+tpl_footer.php in your current template
+
+New files
+---------
+- /includes/templates/YOUR_TEMPLATE/common/tpl_footer_piwik.php
+- /includes/templates/YOUR_TEMPLATE/templates/tpl_shopping_cart_default.php
+- /includes/templates/YOUR_TEMPLATE/templates/tpl_checkout_success_default.php
+- /functions/includes/PiwikEcommerce.php
+- /admin/includes/PiwikEcommerce.php
+- /admin/includes/boxes/extra_boxes/PiwikEcommerce_tools_dhtml.php
+- /admin/includes/extra_datafiles/PiwikEcommerce.php
+- /admin/includes/languages/english/extra_definitions/PiwikEcommerce.php
+
+Affects DB
+==========
+Yes (creates new records into configuration_group and configuration tables)
+
+DISCLAIMER
+==========
+Installation of this contribution is done at your own risk.
+Backup your ZenCart database and any and all applicable files before proceeding.
+
+Features:
+=========
+- supports e-commerce tracking
+- admin menu to enter Piwik details
+- admin|reports menu to view Piwik stats
+
+Install:
+============
+
+1. Go to Admin->Tools->Install SQL Patches and install install.sql by copy and pasting the contents of the file into the form there.
+
+2. Upload catalog/includes/functions/extra_functions/piwikecommerce.php to the /includes/functions/extra_functions/ folder of your ZenCart installation.
+
+3. Upload the contents of the catalog/admin folder to the admin folder of your ZenCart installation. Note that if you renamed your admin folder for security reasons, it will not be named "admin" now.
+
+4. If you are using a default footer file for your current template, you can upload catalog/includes/templates/YOUR_TEMPLATE/common/tpl_footer.php to the folder of your current template to replace the tpl_footer.php file in your template's common folder. If you are using a modified tpl_footer.php file in your template, you must copy the code between <!-- Piwik with E-Commerce Tracking--> and <!-- End Piwik with E-Commerce Tracking--> at the bottom of the catalog/includes/templates/YOUR_TEMPLATE/common/tpl_footer.php file to the bottom of your current tpl_footer.php file.
+
+5. If you are using a default tpl_shopping_cart_default.php template file for your current template, you can upload catalog/includes/templates/YOUR_TEMPLATE/templates/tpl_shopping_cart_default.php to the folder of your current template to replace the tpl_shopping_cart_default.php file in your template's common folder. If you are using a modified tpl_shopping_cart_default.php file in your template, you must copy the code between <!-- Piwik with E-Commerce Tracking--> and <!-- End Piwik with E-Commerce Tracking--> at the top of the catalog/includes/templates/YOUR_TEMPLATE/templates/tpl_shopping_cart_default.php file to the top of your current tpl_shopping_cart_default.php file, right after the set of comments at the top of the file.
+
+6. If you are using a default tpl_checkout_success_default.php template file for your current template, you can upload catalog/includes/templates/YOUR_TEMPLATE/templates/tpl_checkout_success_default.php to the folder of your current template to replace the tpl_checkout_success_default.php file in your template's common folder. If you are using a modified tpl_shopping_cart_default.php file in your template, you must copy the code between <!-- Piwik with E-Commerce Tracking--> and <!-- End Piwik with E-Commerce Tracking--> at the top of the catalog/includes/templates/YOUR_TEMPLATE/templates/checkout_success_default.php file to the top of your current tpl_shopping_cart_default.php file, right after the set of comments at the top of the file.
+
+7. Add your Piwik credentials at Admin->Configuration->Piwik Analytics Configuration
+
+8. View your Piwik reports dashboard at Admin->Reports->Piwik Analytics Reports
+
+Issues
+======
+Because of the embedded widget and cross domain issues, there may be two vertical scroll bars. I thought of creating a shim page to fix it, but this is still an ugly fix.
@@ -0,0 +1,15 @@
+<?php
+/**
+ * @package piwik ecommerce
+ * @copyright Copyright 2003-2007 Zen Cart Development Team
+ * @copyright Portions Copyright 2003 osCommerce
+ * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
+ * @version $Id: piwikecommerce_reports_dhtml.php eristoddle $
+ */
+
+if (!defined('IS_ADMIN_FLAG')) {
+ die('Illegal Access');
+}
+
+$za_contents[] = array('text' => BOX_REPORTS_PIWIKECOMMERCE, 'link' => zen_href_link(FILENAME_PIWIKECOMMERCE, '', 'NONSSL'));
+?>
@@ -0,0 +1,11 @@
+<?php
+/**
+ * @package piwik ecommerce
+ * @copyright Copyright 2003-2007 Zen Cart Development Team
+ * @copyright Portions Copyright 2003 osCommerce
+ * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
+ * @version $Id: piwikecommerce.php eristoddle $
+ */
+
+define('FILENAME_PIWIKECOMMERCE', 'piwikecommerce');
+?>
@@ -0,0 +1,13 @@
+<?php
+/**
+ * @package piwik ecommerce
+ * @copyright Copyright 2003-2007 Zen Cart Development Team
+ * @copyright Portions Copyright 2003 osCommerce
+ * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
+ * @version $Id: piwikecommerce.php eristoddle $
+ */
+
+define('BOX_REPORTS_PIWIKECOMMERCE', 'Piwik Analytics Reports');
+define('HEADING_TITLE_PIWIKECOMMERCE', 'Piwik Analytics Reports');
+define('FILENAME_PIWIKECOMMERCE', 'piwikecommerce');
+?>
@@ -0,0 +1,91 @@
+<?php
+/**
+ * @package piwik ecommerce
+ * @copyright Copyright 2003-2007 Zen Cart Development Team
+ * @copyright Portions Copyright 2003 osCommerce
+ * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
+ * @version $Id: piwikecommerce.php eristoddle $
+ */
+
+ require('includes/application_top.php');
+
+?>
+<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html <?php echo HTML_PARAMS; ?>>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
+<title><?php echo TITLE; ?></title>
+<link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
+<link rel="stylesheet" type="text/css" href="includes/cssjsmenuhover.css" media="all" id="hoverJS">
+<style type="text/css">
+ html, body {
+ margin: 0;
+ padding: 0;
+ height: 100%;
+ }
+ iframe {
+ position: absolute;
+ height: 100%;
+ width: 99%;
+ border: none;
+ box-sizing: border-box;
+ -moz-box-sizing: border-box;
+ -webkit-box-sizing: border-box;
+ }
+</style>
+<script language="javascript" src="includes/menu.js"></script>
+<script language="javascript" src="includes/general.js"></script>
+<?php if ($action == 'edit' || $action == 'update') { ?>
+<script language="javascript"><!--
+function check_form() {
+ var error = 0;
+ var error_message = "<?php echo JS_ERROR; ?>";
+
+ if (error == 1) {
+ alert(error_message);
+ return false;
+ } else {
+ return true;
+ }
+}
+//--></script>
+<?php } ?>
+
+<script type="text/javascript">
+ <!--
+ function init()
+ {
+ cssjsmenu('navbar');
+ if (document.getElementById)
+ {
+ var kill = document.getElementById('hoverJS');
+ kill.disabled = true;
+ }
+ }
+ // -->
+</script>
+</head>
+<body onLoad="init()">
+<!-- header //-->
+<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
+<!-- header_eof //-->
+
+<!-- body //-->
+<table border="0" width="99%" cellspacing="2" cellpadding="2">
+ <tr>
+ <td colspan="7">
+ <h1><?php echo HEADING_TITLE_PIWIKECOMMERCE; ?></h1>
+ </td>
+ </tr>
+ <tr>
+ <td><iframe src="<?php echo PIWIK_URL; ?>index.php?module=Widgetize&action=iframe&moduleToWidgetize=Dashboard&actionToWidgetize=index&idSite=<?php echo PIWIK_ID; ?>&period=<?php echo PIWIK_REPORT_PERIOD; ?>&date=<?php echo PIWIK_REPORT_DATE; ?>&token_auth=<?php echo PIWIK_TOKEN_AUTH; ?>" frameborder="0" marginheight="0" marginwidth="0" width="100%" height="100%"></iframe></td>
+ </tr>
+</table>
+<!-- body_eof //-->
+<!-- footer //-->
+<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
+<!-- footer_eof //-->
+<br>
+</body>
+</html>
+<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>
@@ -0,0 +1,93 @@
+<?php
+
+/*
+ zenpiwik.php
+ @author Stephan Miller <stephanmil@gmail.com>
+ @link http://www.stephanmiller.com
+
+ Zen Cart - The Art of Ecommerce
+ http://www.zen-cart.com/
+
+ Copyright (c) 2012 Zen Cart
+
+ Released under the GNU General Public License
+
+*/
+
+ function log_category($categories_id,$language_id) {
+ global $db;
+
+ $categories_query = "select categories_name from " . TABLE_CATEGORIES_DESCRIPTION . " where categories_id = " . (int)$categories_id . " and language_id = " . (int)$language_id;
+ $categories = $db->Execute($categories_query);
+
+ if ($categories->RecordCount() > 0) {
+ return 'piwikTracker.setEcommerceView(productSku = false,productName = false,category = "'.$categories->fields['categories_name'].'");' . "\n";
+ }
+
+ }
+
+ function log_product($products_id,$language_id) {
+ global $db;
+
+ $products_query = "select p.products_model, pd.products_name, cd.categories_name from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, ". TABLE_CATEGORIES_DESCRIPTION ." cd WHERE p.products_id = pd.products_id and p2c.categories_id = cd.categories_id and p.products_id = " . (int)$products_id . " and pd.language_id =".(int)$language_id." and cd.language_id =".(int)$language_id;
+ $products = $db->Execute($products_query);
+
+ if ($products->RecordCount() > 0) {
+ return 'piwikTracker.setEcommerceView("'.$products->fields['products_model'].'","'.$products->fields['products_name'].'","'.$products->fields['categories_name'].'");' . "\n";
+ }
+
+ }
+
+ function log_cart($products,$total,$language_id) {
+ global $db;
+
+ for ($i=0, $n=sizeof($products); $i<$n; $i++) {
+
+ if (!is_null($products[$i]['model'])) {
+ $categories_query = "select cd.categories_name from " . TABLE_CATEGORIES_DESCRIPTION ." cd, ". TABLE_PRODUCTS_TO_CATEGORIES . " p2c WHERE cd.categories_id = p2c.categories_id and p2c.products_id = " . (int)$products[$i]['id'] . " and cd.language_id =".(int)$language_id;
+
+ $categories = $db->Execute($categories_query);
+ $string .= 'piwikTracker.addEcommerceItem("'.$products[$i]['model'].'","'.$products[$i]['name'].'","'.$categories->fields['categories_name'].'",'.$products[$i]['final_price'].','.$products[$i]['quantity'].');' . "\n";
+
+ }
+
+ }
+
+ $string .= 'piwikTracker.trackEcommerceCartUpdate('.$total.');' . "\n";
+
+ return $string;
+ }
+
+ function log_order($insert_id,$order,$products,$language_id) {
+ global $db;
+
+ foreach ($products as $p) {
+
+ if (!is_null($p['products_id'])) {
+ $categories_query = "select cd.categories_name from " . TABLE_CATEGORIES_DESCRIPTION ." cd, ". TABLE_PRODUCTS_TO_CATEGORIES . " p2c WHERE cd.categories_id = p2c.categories_id and p2c.products_id = " . (int)$p['products_id'] . " and cd.language_id =".(int)$language_id;
+ $categories = $db->Execute($categories_query);
+
+ $order_product_query = "select products_model, products_tax, products_quantity, final_price from " . TABLE_ORDERS_PRODUCTS . " where orders_id = " . (int)$insert_id . " and products_id = " . (int)$p['products_id'];
+ $order_product = $db->Execute($order_product_query);
+
+ $string .= 'piwikTracker.addEcommerceItem("'.$order_product->fields['products_model'].'","'.$p['products_name'].'","'.$categories->fields['categories_name'].'",'.(float)$order_product->fields['final_price'].','.$order_product->fields['products_quantity'].');' . "\n";
+ }
+
+ }
+
+ $st_result = $db->Execute("SELECT ROUND(value, 2) subtotal FROM ". TABLE_ORDERS_TOTAL ." WHERE class='ot_subtotal' AND orders_id = ". $order->fields['orders_id']);
+ $subtotal = $st_result->fields['subtotal'];
+ $shipping = (float)$order->fields['order_total'] - (float)$order->fields['order_tax'] - (float)$st_result->fields['subtotal'];
+
+ $string .= 'piwikTracker.trackEcommerceOrder("'.$insert_id.'",'.$order->fields['order_total'].','.$subtotal.','.$order->fields['order_tax'].','.$shipping.',false);' . "\n";
+
+ return $string;
+
+ }
+
+ function log_custom_variable($index,$key,$value) {
+
+ return 'piwikTracker.setCustomVariable('.$index.',"'.$key.'","'.$value.'","visit");' . "\n";
+
+ }
+?>
Oops, something went wrong.

0 comments on commit 1bb4b91

Please sign in to comment.