1.
In the Magento website to pass shopping cart and order information, can go to the Magento plugin library to download a plugin, but this plugin to the order of information crawl, is in the order to pay the successful return page,
For some third-party payment success did not return to the site, will be missing the order, resulting in inaccurate, we need to crawl before jumping over
So:
Check the official information:
http://piwik.org/docs/ecommerce-analytics/
2. Method:
In Magento the Piwik plugin shopping cart has been implemented, we use this plugin
This plugin is used in the old version of the way, but the new Piwik still support
File path found: \app\design\frontend\default-mongo\default\template\piwikanalytics\piwik.phtml
The contents of the modification are:
<?php//echo $this->_getorderstrackingcode ()?> <?php//echo $this->_getproductpageview ()?> <? PHP//echo $this->_getcategorypageview ()?> <!--Piwik-to <script type= "Text/javascript" > var _paq = _paq | |
[];
<?php//Shopping CART information tracking $CURRENTURL = mage::helper (' Core/url ')->getcurrenturl (); if (Strstr ($CURRENTURL, "Http://www.tomtop.com/checkout/cart?") | | ($CurrentUrl = = "Http://www.tomtop.com/checkout/cart") | | Strstr ($CURRENTURL, "Http://www.tomtop.com:6081/checkout/cart?") | | ($CurrentUrl = = "Http://www.tomtop.com:6081/checkout/cart"))
{echo $this->_getecommercecartupdate ();
}?> _paq.push ([' Trackpageview ']);
_paq.push ([' enablelinktracking ']); (function () {var u= ("https:" = = Document.location.protocol)? "
HTTPS ":" http ") +"://piwik.tomtop.com/";
_paq.push ([' Settrackerurl ', u+ ' piwik.php ']);
_paq.push ([' Setsiteid ', 1]); var d=document, g=d.createelement (' script '), S=d.getelementsbytagname (' script ') [0]; G.Type= ' Text/javascript '; G.defer=true; G.async=true; g.src=u+ ' Piwik.js ';
S.parentnode.insertbefore (g,s);
})(); </script> <noscript><p></p></noscript> <!--End Piwik Code---
App\code\community\piwikmage\piwikanalytics\block\piwik.php's Getecommercecartupdate method is modified to read as follows:
protected function _getecommercecartupdate () {$cart = Mage::getmodel (' Checkout/cart ')->getquote ()->get
Allvisibleitems ();
foreach ($cart as $cartitem) {//get category name $product _id = $cartitem->product_id;
$_product = Mage::getmodel (' catalog/product ')->load ($product _id);
$cats = $_product->getcategoryids ();
$cate _str = "[";
if (Isset ($cats)) {foreach ($cats as $ca _id) {$cate = Mage::getmodel (' catalog/category ')->load ($ca _id);
$category _name = $cate->getname ();
$cate _str. = "'". $category _name. "',";
}} $cate _str = substr ($cate _str,0,strlen ($cate _str)-1);
$cate _str. = "]";
$nameofproduct = $cartitem->getname ();
$nameofproduct = Str_replace (' "'," ", $nameofproduct);
if ($cartitem->getprice () = = 0 | | $cartitem->getprice () < 0.00001): continue; endif echo "_paq.push ([' Addecommerceitem ', '".) $cartitem->getsku (). "', '". $nameofproduct. "',". $cate _str. ",". $ Cartitem->getprice (). ",".
$cartitem->getqty (). "]);";
echo "\ n";
}//total in Cart $grandTotal = Mage::getmodel (' Checkout/cart ')->getquote ()->getgrandtotal (); if ($grandTotal = = 0) echo ';
else echo "_paq.push ([' Trackecommercecartupdate ',". $grandTotal. "]);";
echo "\ n";
echo "_paq.push ([' Trackpageview ']);";
echo "\ n"; }
After the completion of the above, the shopping cart modification completed
Here is the change in the click to jump the time to grab the order number:
Re-checkout\controllers\onepagecontroller.php This method:
Modify the end code to:
$this->getonepage ()->getquote ()->save ();
/**
* When there was redirect to the third party, we don ' t want to save order yet.
* We'll save the order in return action.
*
/if (Isset ($REDIRECTURL)) {
$result [' redirect '] = $redirectUrl;
}
$lastOrderId = Mage::getsingleton (' checkout/session ')->getlastorderid ();
$order = Mage::getsingleton (' Sales/order ')->load ($lastOrderId);
$increment _id = $order->getincrementid ();
$result [' order_id '] = $increment _id; $orderId = Mage::getsingleton (' checkout/session ')->getlastrealorderid (); $result [' order_id '] = $orderId;
$result [' order '] = $this->getpiwikorderdata ($order);
$this->getresponse ()->setbody (Mage::helper (' core ')->jsonencode ($result));
}
To add a method:
Public Function Getpiwikorderdata ($order) {//$order = Mage::getmodel (' Sales/order ')->loadbyincrementid ($
ORDERID);
$order _product_info = Array (); foreach ($order->getallvisibleitems () as $item) {//get category name $product
_id = $item->product_id;
$_product = Mage::getmodel (' catalog/product ')->load ($product _id);
$cats = $_product->getcategoryids ();
$cate _str = "["; if (Isset ($cats)) {foreach ($cats as $ca _id) {$cate = Mage::getmodel (' catalog/category ')->load ($ca _id)
;
$category _name = $cate->getname ();
$category _name = Str_replace ("'", "", $category _name);
$category _name = str_replace (' "', ' ', $category _name); $cate _str. = "\" ". $category _name."
\",";
}} $cate _str = substr ($cate _str,0,strlen ($cate _str)-1); $cate_str. = "]";
if ($item->getqtyordered ()) {$qty = Number_format ($item->getqtyordered (), 0, '. ', ');
} else {$qty = ' 0 '; } $order _product_info[] = Array ("sku" = = $item->getsku (), "Produ Ct_name "= $item->getname (),//" category_name "+ $cate _str," category_name "=
> "", "Price" and "Price" $item->getbaseprice (), "qty" and "$qty"); } if ($order->getgrandtotal ()) {$subtotal = $order->getgrandt
Otal ()-$order->getshippingamount ()-$order->getshippingtaxamount ();
} else {$subtotal = ' 0.00 '; } $order _info = Array ("increment_id" = + $order->getincrementid (), "Base_gra Nd_total "=" $order->getbasegrandtotal (), "Subtotal" = $subtotal, "Base_tax_amount" and $order-&G
T;getbasetaxamount (), "base_shipping_amount" = $order->getbaseshippingamount ());
Return Array ("order_info" = $order _info, "order_product_info" = $order _product_info); }
Then find the JS file: skin\frontend\default-mongo\default\js\opcheckout.js
Found in 730 rows or so:
var Review = Class.create ();
Method of this JS object: Nextstep:function (transport) {
The changes are as follows:
Nextstep:function (transport) {if (transport && transport.responsetext) {try{
Response = eval (' (' + transport.responsetext + ') ');
} catch (e) {response = {};
} if (Response.Redirect) {location.href = Response.Redirect;
alert (response.order_id);
order = Response.order;
Order_info = Order.order_info;
Order_product_info = Order.order_product_info;
for (x in order_product_info) {x = order_product_info[x]; if (X.sku) {_paq.push ([' Addecommerceitem ', X.sku, X.product_name, X.category_name, parsefloat (
X.price), parseint (X.qty)]);
Alert (x.sku+ "# #" +x.product_name+ "# #" +x.category_name+ "# #" +parsefloat (X.price) + "# #" +parseint (X.qty)); }} _paq.push ([' Trackecommerceorder ', order_info.increment_id, parsefloat (order_info.b Ase_grand_total), PARsefloat (Order_info.subtotal), parsefloat (Order_info.base_tax_amount), parsefloat (Order_info.base_shipping_amoun
T)]); Alert (order_info.increment_id+ "# #" +parsefloat (order_info.base_grand_total) + "# #" +parsefloat (Order_
Info.subtotal) + "# #" +parsefloat (Order_info.base_tax_amount) + "# #" +parsefloat (Order_info.base_shipping_amount));
_paq.push ([' Trackpageview ']);
Return
} if (response.success) {this.issuccess = true;
Window.location=this.successurl;
} else{var msg = response.error_messages;
if (typeof (msg) = = ' object ') {msg = Msg.join ("\ n");
} alert (msg); } if (response.update_section) {$ (' checkout-' +response.update_section.name+ '-load '). Update (R
esponse.update_section.html);
Response.update_section.html.evalScripts (); } if (response.goto_section) {checkout.gotosection (response.goto_section);
Checkout.reloadprogressblock (); }
}
},
This is done and if the online site is using the varnish configuration, refresh the varnish cache
Then go to Piwik to see if the past order is passed, and if Cron processes the report, then the report is not immediate and needs to wait.
Then through the API, crawl Piwik log data, there is a complete order number information
Then in the API to check the order status, so that the marketing system on the flow of data perfect.