Example #1
0
 /**
  * Render information about specified orders and their items
  *
  * @link http://code.google.com/apis/analytics/docs/gaJS/gaJSApiEcommerce.html#_gat.GA_Tracker_._addTrans
  * @param bool $accountId2
  * @return string
  */
 protected function _getOrdersTrackingCode($accountId2 = false)
 {
     if (Mage::helper('googleanalyticsplus')->getGoogleanalyticsplusStoreConfig('convertcurrencyenabled')) {
         $orderIds = $this->getOrderIds();
         if (empty($orderIds) || !is_array($orderIds)) {
             return;
         }
         $collection = Mage::getResourceModel('sales/order_collection')->addFieldToFilter('entity_id', array('in' => $orderIds));
         $result = array();
         foreach ($collection as $order) {
             if ($order->getIsVirtual()) {
                 $address = $order->getBillingAddress();
             } else {
                 $address = $order->getShippingAddress();
             }
             $result[] = sprintf("_gaq.push(['_addTrans', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s']);", $order->getIncrementId(), Mage::app()->getStore()->getFrontendName(), Mage::helper('googleanalyticsplus')->convert($order, 'getBaseGrandTotal'), Mage::helper('googleanalyticsplus')->convert($order, 'getBaseTaxAmount'), Mage::helper('googleanalyticsplus')->convert($order, 'getBaseShippingAmount'), $this->jsQuoteEscape($address->getCity()), $this->jsQuoteEscape($address->getRegion()), $this->jsQuoteEscape($address->getCountry()));
             foreach ($order->getAllVisibleItems() as $item) {
                 $result[] = sprintf("_gaq.push(['_addItem', '%s', '%s', '%s', '%s', '%s', '%s']);", $order->getIncrementId(), $this->jsQuoteEscape($item->getSku()), $this->jsQuoteEscape($item->getName()), null, Mage::helper('googleanalyticsplus')->convert($order, 'getBasePrice', $item), $item->getQtyOrdered());
             }
             $result[] = "_gaq.push(['_trackTrans']);";
             $html = implode("\n", $result);
         }
     } else {
         $html = "\n" . parent::_getOrdersTrackingCode();
     }
     if ($accountId2) {
         $html .= str_replace('_gaq.push([\'_', '_gaq.push([\'t2._', $html);
     }
     return $html;
 }
Example #2
0
 /**
  *  Transaction on Mage 1.4.2 +
  *  duplicate for secondary tracker
  */
 protected function _getOrdersTrackingCode($accountId2 = false)
 {
     $html = "\n" . parent::_getOrdersTrackingCode();
     if ($accountId2) {
         $html .= str_replace('_gaq.push([\'_', '_gaq.push([\'t2._', $html);
     }
     return $html;
 }