博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
网站加载代码
阅读量:4198 次
发布时间:2019-05-26

本文共 5008 字,大约阅读时间需要 16 分钟。

1.

footer.phtml页面底部加入:

2.

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

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

3

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

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

getQuote()->getAllItems();$cart_arr = array();$cart_json = '';if($items && (is_array($items) || is_object($items))){ foreach($items as $item) { //echo 'ID: '.$item->getProductId().'
'; //echo 'Name: '.$item->getName().'
'; //echo 'Sku: '.$item->getSku().'
'; //echo 'Quantity: '.$item->getQty().'
'; //echo 'Price: '.$item->getPrice().'
'; //echo "
"; $cart_arr[] = array( "id"=>$item->getProductId(), "sku"=>$item->getSku(), "qty"=>$item->getQty(), "price"=>$item->getPrice(), ); } $cart_json = json_encode($cart_arr);}?>

4

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

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."
"; //$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 = ''; $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 .= $trace; $html .= $this->__('You will be redirected to the PayPal website in a few seconds.'); $html .= $form->toHtml(); //$html.= ''; $html .= ''; $html .= ''; return $html; }

5

paypal成功页面对应的代码

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

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

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 = ''; echo $trace; } ?>

转载地址:http://xfdli.baihongyu.com/

你可能感兴趣的文章
【unix网络编程第三版】ubuntu端口占用问题
查看>>
【一天一道LeetCode】#120. Triangle
查看>>
【unix网络编程第三版】阅读笔记(三):基本套接字编程
查看>>
【一天一道LeetCode】#121. Best Time to Buy and Sell Stock
查看>>
【一天一道LeetCode】#125. Valid Palindrome
查看>>
【一天一道LeetCode】#231. Power of Two
查看>>
【一天一道LeetCode】#202. Happy Number
查看>>
带你深入理解STL之Vector容器
查看>>
带你深入理解STL之Deque容器
查看>>
带你深入理解STL之Stack和Queue
查看>>
带你深入理解STL之Set和Map
查看>>
Redis源码剖析--源码结构解析
查看>>
Redis源码剖析--动态字符串SDS
查看>>
Redis源码剖析--双端链表Sdlist
查看>>
Redis源码剖析--字典dict
查看>>
Redis源码剖析--跳跃表zskiplist
查看>>
Redis源码剖析--整数集合Intset
查看>>
Redis源码剖析--对象object
查看>>
Redis源码剖析--字符串t_string
查看>>
Redis源码剖析--快速列表quicklist
查看>>