Monday, August 13, 2012

magento ecommerce google analytics



BELOW IS THE CODE THAT I USED IN MY PROJECT

File: success.phtml
path: app/design/frontend/default/mytheme/template/checkout



 <?php  
 $order1 = Mage::getModel('sales/order')->load(Mage::getSingleton('checkout/session')->getLastOrderId());   
 $subtotal = $order1->getSubtotal();  
 $order_id = $order1->getId(); //the id of the order  
 //$order->getIncrementId();//the increment id of the order  
 $gtotal = $order1->getGrandTotal();//grand total of the order   
 //echo "<pre />";  
 //print_r($order->getBillingAddress()->getData());  
 $address = $order1->getBillingAddress()->getData();  
 $city = $address['city'];  
 $state = $address['region'];  
 $country = $address['country_id'];  
 ?>  
 <script type="text/javascript">  
  var _gaq = _gaq || [];  
  _gaq.push(['_setAccount', 'UA-17916440-1']);  
  _gaq.push(['_trackPageview']);  
  _gaq.push(['_addTrans',  
   '<?php echo $order_id; ?>',      // order ID - required  
   'steigerhoutstunter.nl', // affiliation or store name  
   '<?php echo $gtotal;?>',     // total - required  
   '0',      // tax  
   '0',       // shipping  
   '<?php echo $city;?>',    // city  
   '<?php echo $state;?>',   // state or province  
   '<?php echo $country;?>'       // country  
  ]);  
 <?php  
 $order_items = $order1->getAllItems();  
 $itemcount=count($order_items);  
 $name=array();  
 $unitPrice=array();  
 $sku=array();  
 $ids=array();  
 $qty=array();  
 foreach ($order_items as $key => $item)  
 {?>  
  _gaq.push(['_addItem',  
   '<?php echo $order_id; ?>',      // order ID - required  
   '<?php echo $item->getSku(); ?>',      // SKU/code - required  
   '<?php echo $item->getName(); ?>',    // product name  
   'category name',  // category or variation  
   '<?php echo $item->getPrice(); ?>',     // unit price - required  
   '<?php echo $item->getQtyToInvoice(); ?>'        // quantity - required  
  ]);  
 <?php   
 }  
 ?>  
   _gaq.push(['_trackTrans']); //submits transaction to the Analytics servers  
   (function() {  
   var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;  
   ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';  
   var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);  
  })();  
 </script>  



Monday, July 30, 2012

magento sage pay error: SagePay Payment Has Failed, Please Reload Checkout Page And Try Again. Your Card Has Not Been Charged


  Actually at my setup sagepay wasn't working with  firecheckout.

you have to buy the paid latest version of firecheckout in order to make it work with sagepay. 

I had downloaded latest verision of sagepay and had to impelement it on magento 1.7.0.1 , I used simulation mode.




Don't forget to make simulator account  in sage pay in order to use it in simulator mode.

Monday, July 23, 2012

Magento error "You cannot define a correlation name more than once"

solution:

This is a layered navigation error.

In your catalog.xml search for
"layer_view" . If you find two  occurences for this, then remove one that you don't need.

I commented the second one that I didn't needed and fixed the error.

<reference name="right">
             <block type="catalog/layer_view" name="catalog.leftnav" after="currency" template="catalog/layer/view.phtml"/>
         </reference>

<!--        <reference name="left">
            <block type="catalog/layer_view" name="catalog.leftnav" after="currency" template="catalog/layer/view.phtml"/>
        </reference>-->

Thursday, July 5, 2012

Get payment code in event observer

 $paymentcode = $observer->getEvent()->getPayment()->getMethodInstance()->getCode();

Tuesday, July 3, 2012

magento get payment method in onepagecontroller.php

$params=$this->getRequest()->getParams();
$payment_method=$params['payment']['method'];

MAGENTO-REMOVE ALL ITEMS FROM THE CART

//THIS WORKED FINE FOR ME :)

$session= Mage::getSingleton('checkout/session');
$quote = $session->getQuote();
$cart = Mage::getModel('checkout/cart');
$cartItems = $cart->getItems();
foreach ($cartItems as $item)
{
   $quote->removeItem($item->getId())->save();
}

Get order id from page url

simple use this:

$orderId = (int) $this->getRequest()->getParam('order_id');