网站加载代码

来源:互联网 发布:网络400电话价格 编辑:程序博客网 时间:2024/05/01 17:28

1.

footer.phtml页面底部加入:

<script type="text/javascript">var _maq = _maq || [];_maq.push(['_setAccount', 'onfancy']);(function() {var ma = document.createElement('script'); ma.type = 'text/javascript'; ma.async = true;ma.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'market.onfancy.com/trace.js?onfancy=2';var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ma, s);})();///////////////////////////////////////////////////////end</script>

2.

对于产品页面的统计,加入:

<script type="text/javascript">var _maq = _maq || [];_maq.push(["sku", "grxjy561725"]);</script>

design/frontend/breeze/default/template/catalog/product/view.phtml:

<script type="text/javascript">var _maq = _maq || [];_maq.push(["sku", "<?php echo  $_product->getSku(); ?>"]);</script>


3

对于购物车页面的统计,加入:

<script type="text/javascript">var _maq = _maq || [];_maq.push(['cart', '[{"id":"20682","sku":"grxjy561725","qty":1,"price":19.99}]']);</script>

magento代码:design/frontend/breeze/default/template/checkout/cart.phtml

<?php/////////////////////////////////////////////////////////////////////////////////////////////////得到购物车的信息,组成json格式数据$items = Mage::getSingleton('checkout/session')->getQuote()->getAllItems();$cart_arr = array();$cart_json = '';if($items && (is_array($items) || is_object($items))){ foreach($items as $item) {//echo 'ID: '.$item->getProductId().'<br />';//echo 'Name: '.$item->getName().'<br />';//echo 'Sku: '.$item->getSku().'<br />';//echo 'Quantity: '.$item->getQty().'<br />';//echo 'Price: '.$item->getPrice().'<br />';//echo "<br />"; $cart_arr[] = array("id"=>$item->getProductId(),"sku"=>$item->getSku(),"qty"=>$item->getQty(),"price"=>$item->getPrice(),);}$cart_json = json_encode($cart_arr);}?><script type="text/javascript">var _maq = _maq || [];<?phpif($cart_json){echo "_maq.push(['cart', '".$cart_json."']);";}?></script>



4

对于paypal standard的跳转页面加入:

<script type="text/javascript">var _maq = _maq || [];_maq.push(["order_style", "standard"]);_maq.push(["order_status", "pending"]);_maq.push(["order", "{\"invoice\":\"500005233\",\"currency_code\":\"USD\",\"item_name\":\"OnFancy\",\"amount\":\"19.99\",\"shipping\":\"0.00\",\"discount_amount\":\"0.00\",\"city\":\"fdsfds\",\"country\":\"US\",\"email\":\"zqy234@126.com\",\"first_name\":\"terry\",\"last_name\":\"water\",\"zip\":\"21321321\",\"state\":\"DE\",\"address1\":\"fdsafdsa\",\"address2\":\"fdsafds\",\"products\":{\"1\":{\"item_number\":\"grxjy561725\",\"item_name\":\"Sexy Backless Lace Chiffon Spliced Short Sleeve Dress\",\"quantity\":1,\"amount\":\"19.99\"}}}"]);_maq.push(["_setAccount", "onfancy"]);(function() {var ma = document.createElement("script"); ma.type = "text/javascript"; ma.async = true;ma.src = ("https:" == document.location.protocol ? "https://" : "http://") + "market.onfancy.com/trace.js";var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(ma, s);})();</script>


code/local/Mage/Paypal/Block/Standard/Redirect.php

protected function _toHtml()    {        $standard = Mage::getModel('paypal/standard');        $form = new Varien_Data_Form();        $form->setAction($standard->getConfig()->getPaypalUrl())            ->setId('paypal_standard_checkout')            ->setName('paypal_standard_checkout')            ->setMethod('POST')            ->setUseContainer(true);$this_order = array();$this_product = array();        foreach ($standard->getStandardCheckoutFormFields() as $field=>$value) {            $form->addField($field, 'hidden', array('name'=>$field, 'value'=>$value));//echo $field."=>".$value."<br/>";//$order[$field] = $value;if($field == "invoice" ||$field == "currency_code" ||$field == "item_name" ||$field == "amount" ||$field == "shipping" ||$field == "discount_amount" ||$field == "city" ||$field == "country" ||$field == "email" ||$field == "first_name" ||$field == "last_name" ||$field == "zip" ||$field == "state" ||$field == "address1" ||$field == "address2"){$this_order[$field] = $value;}else{if((strstr($field,"item_number_") ||strstr($field,"item_name_") ||strstr($field,"quantity_") ||strstr($field,"amount_")) && (!strstr($field,"discount_amount_"))){$str = strrev($field);$key = substr($str,0,1);$s_key = substr($str,2);$s_key = strrev($s_key);$this_product[$key][$s_key] = $value;}}        }$this_order['products'] = $this_product;//var_dump($this_order);exit;$json_order = json_encode($this_order);$json_order = str_replace('"','\"',$json_order);//var_dump($json_order);exit;$trace = '<script type="text/javascript">var _maq = _maq || [];_maq.push(["order_style", "standard"]);_maq.push(["order_status", "pending"]);_maq.push(["order", "'.$json_order.'"]);_maq.push(["_setAccount", "onfancy"]);(function() {var ma = document.createElement("script"); ma.type = "text/javascript"; ma.async = true;ma.src = ("https:" == document.location.protocol ? "https://" : "http://") + "market.onfancy.com/trace.js";var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(ma, s);})();</script>';        $idSuffix = Mage::helper('core')->uniqHash();        $submitButton = new Varien_Data_Form_Element_Submit(array(            'value'    => $this->__('Click here if you are not redirected within 10 seconds...'),        ));        $id = "submit_to_paypal_button_{$idSuffix}";        $submitButton->setId($id);        $form->addElement($submitButton);        $html = '<html><body>';$html .= $trace;        $html .= $this->__('You will be redirected to the PayPal website in a few seconds.<img src="https://www.onfancy.com/skin/frontend/breeze/default/images/loader.gif""  />');        $html .= $form->toHtml();        //$html.= '<script type="text/javascript">document.getElementById("paypal_standard_checkout").submit();</script>';        $html .= '<script type="text/javascript">function func(){document.getElementById("paypal_standard_checkout").submit();}window.onload=func;</script>';$html .= '</body></html>';        return $html;    }



5

paypal成功页面对应的代码

这里需要把standard的支付部分去掉,不然会造成重复。

design/frontend/base/default/template/checkout/success.phtml

<?php/////////////////////////$payment =  $order->getPayment();$payment_method = $payment->getData('method');if( $payment_method != 'paypal_standard'){//$orderId = "800016671"; //$order = Mage::getModel('sales/order')->loadByIncrementId($orderId); $subtotal = $order->getSubtotal(); $discount = $order->getDiscountAmount(); $shipping_address_id=$order->shipping_address_id;$address = Mage::getModel('sales/order_address')->load($shipping_address_id);$address1 = $address->getStreet(1);$address2 = $address->getStreet(2);$firstname = $address->getFirstname();$lastname = $address->getLastname();$telephone = $address->getTelephone();$email = $address->getEmail();$region = $address->getRegion();$country = $address->getCountry();$city = $address->getCity();$zip = $address->getPostcode();$ordered_items = $order->getAllItems();$products = array();foreach($ordered_items as $item){     $products[] = array("item_number"=>$item->getSku(),"item_name"=>$item->getName(),"quantity"=>$item->getQtyOrdered(),"amount"=>$item->getPrice(),);} $shipping = $order->getShippingAmount();$this_order['products'] = $products;$this_order['invoice'] = $orderId;$this_order['currency_code'] = $currencyCode;$this_order['currency_code'] = $currencyCode;$this_order['subtotal'] = $subtotal;$this_order['shipping'] = $shipping;$this_order['discount_amount'] = $discount;$this_order['city'] = $city;$this_order['country'] = $country;$this_order['email'] = $email;$this_order['first_name'] = $firstname;$this_order['last_name'] = $lastname;$this_order['zip'] = $zip;$this_order['state'] = $region;$this_order['address1'] = $address1;$this_order['address2'] = $address2;$json_order = json_encode($this_order);$json_order = str_replace('"','\"',$json_order);$trace = '<script type="text/javascript">var _maq = _maq || [];_maq.push(["order_style", "express"]);_maq.push(["order_status", "success"]);_maq.push(["order", "'.$json_order.'"]);</script>';echo $trace;}////////////////////////?>




















0 0