开发者

Nextag ROI Code in Magento

开发者 https://www.devze.com 2023-04-13 04:34 出处:网络
I need to put the nextag code to track sales in my seller dashboard. I have the example here, but I dont know how to replace the variables in success.phtml

I need to put the nextag code to track sales in my seller dashboard. I have the example here, but I dont know how to replace the variables in success.phtml

<script type="text/javascript">
<!--
    /* NexTag ROI Optimizer Data */
    var id = '3551264';
    var rev = '<REVENUE>';
    var order = '开发者_StackOverflow社区<ORDER ID>';
    var cats = '<CATEGORY1|CATEGORY2|CATEGORY3|...>';
    var prods = '<PRODUCT1|PRODUCT2|PRODUCT3|...>';
    var units = '<UNITS1|UNITS2|UNITS3|...>';
//-->
</script>
<script type="text/javascript" src="https://imgsrv.nextag.com/imagefiles/includes/roitrack.js"></script>


Since you need to do this after the the order is placed you are going add some code at checkout to set all the variables you need in the magento session.

Is not really complicated:

#Setting some session values
Mage::getSingleton('core/session')->setCategories('Cat1|Cat2|Cat3');

#Some code to help you get the hang of it 
$categories = '';
$products = '';
$cart = Mage::helper('checkout/cart')->getCart()
$items = $cart->getItems();

foreach($items as $item){
  $catIds = $item->getProduct()->getCategoryIds();
  foreach($catIds as $catId){
    $cat = Mage::getModel('catalog/category')->getCollection()->load($catId);
    $categories .= $cat->getName();
  }  
}
Mage::getSingleton('core/session')->setCategories($categories);

Then in your JS you only have to call your variables using php, when Magento calls success.phtml all the php code will be replaced, same way any template works, a lot of people don't know that you can use this inside your JS

Javascript is a client-side language so you can place php code inside it. Like this:

<script type="text/javascript">
<!--
/* NexTag ROI Optimizer Data */
var id = '3551264';
var rev = '<REVENUE>';
var order = '<ORDER ID>';
var cats = <?php echo Mage::getSingleton('core/session')->getCategories(); ?>;
var prods = '<PRODUCT1|PRODUCT2|PRODUCT3|...>';
var units = '<UNITS1|UNITS2|UNITS3|...>';
//-->
</script>

That code is not intended to be the complete solution but something to get you on the right path.

Let me know if you have further questions or if you need more help with the code.

Ok So you need more help with the code

Put the following on your review.phtml

<div class="order-review" id="checkout-review-load">
    <?php echo $this->getChildHtml('info') ?>
</div>
<?php 
    #Some code to help you get the hang of it
    $categories = '<';
    $products = '<';
    $units = '<';
    $cart = Mage::helper('checkout/cart')->getCart();
    $items = $cart->getItems();

    foreach($items as $item){
      $units .= $item->getQty() . '|';
      $products .= $item->getProduct()->getName() . '|';

      $catIds = $item->getProduct()->getCategoryIds();
      foreach($catIds as $catId){
        $cat = Mage::getModel('catalog/category')->load($catId);
        $categories .= $cat->getName() . '|';


      }
    }

    $products = substr($products, 0, -1);
    $products .= '>';

    $categories = substr($categories, 0, -1);
    $categories .= '>'; 

    $units = substr($units, 0, -1);
    $units .= '>';

    $totals = Mage::getSingleton('checkout/cart')->getQuote()->getTotals();
    $subtotal = $totals["subtotal"]->getValue();

    Mage::getSingleton('core/session')->setScriptCats($categories);
    Mage::getSingleton('core/session')->setScriptProds($products);
    Mage::getSingleton('core/session')->setScriptRevenue($subtotal);
    Mage::getSingleton('core/session')->setScriptUnits($units);

?>

And the following at the end of your success.phtml, but I still need to know what Units are

<script type="text/javascript">
<!--
/* NexTag ROI Optimizer Data */
var id = '3551264';
var rev = '<<?php echo Mage::getSingleton('core/session')->getScriptRevenue(); ?>>';
var order = '<<?php echo $this->getOrderId(); ?>>';
var cats = '<?php echo Mage::getSingleton('core/session')->getScriptCats(); ?>';
var prods = '<?php echo Mage::getSingleton('core/session')->getScriptProds(); ?>';
var units = '<?php echo Mage::getSingleton('core/session')->getScriptUnits(); ?>';
//-->
</script>
<script type="text/javascript" src="https://imgsrv.nextag.com/imagefiles/includes/roitrack.js"></script>

And I'm pretty sure it works, here is the result of my test environment:

    <script type="text/javascript">
    <!--
    /* NexTag ROI Optimizer Data */
    var id = '3551264';
    var rev = '<150.99>';
    var order = '<10000034>';
    var cats = '<Computers|RAM / Memory>';
    var prods = '<Crucial 1GB PC4200 DDR2 533MHz Memory>';
    var units = '<1>';
    //-->
    </script>

Cheers!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号