dongtun1209 2011-10-14 11:10
浏览 25
已采纳

Magento的Nextag ROI代码

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 = '<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>
  • 写回答

1条回答 默认 最新

  • duanhe4155 2011-10-16 22:59
    关注

    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!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器