jQuery函数 - 左右抖动效果,用于提示

Wordpress博客后台登录输入错误的话登录窗口有左右抖动的效果。弄成jQuery函数方便调用(前提已载入jQuery包)

function shake(o){
    var $panel = $("#"+o);
    box_left = ($(window).width() -  $panel.width()) / 2;
    $panel.css({'left': box_left,'position':'absolute'});
    for(var i=1; 4>=i; i++){
        $panel.animate({left:box_left-(40-10*i)},50);
        $panel.animate({left:box_left+2*(40-10*i)},50);
    }
}

shake函数的参数o就是dom元素的ID,一般就是div的ID。shake('panel'); 简单这样调用就能实现左右抖动的效果。。我用来提示 挺好的

Magento错误-Call to undefined method Mage_Adminhtml_Block_Widget::getrowurl() in app\code\core\Mage\Adminhtml\Block\Widget\Grid.php on line 1607

Fatal error: Call to undefined method Mage_Adminhtml_Block_Widget::getrowurl() in [magentohome]/app/code/core/Mage/Adminhtml/Block/Widget/Grid.php on line 1607

从Magento 1.4.0.1导出产品csv文件后,要导入到Magento 1.4.2.0的时候,在上传csv文件,保存提交后报这错误。

解决办法:修改 app/code/core/Mage/Core/Block/Template.php 这个文件,在319行后面加入函数getRowUrl,如:

public function getRowUrl($row)
{
return $this->getUrl(’*/*/edit’, array(’instance_id’ => $row->getId()));
}


清缓存重新试,问题解决。

Magento报错:Call to a member function extend() on a non-object in app\code\core\Mage\Core\Model\Mysql4\Config.php on line 115

遇到报错:Fatal error: Call to a member function extend() on a non-object in \app\code\core\Mage\Core\Model\Mysql4\Config.php on line 115

错误原因及解决办法参见:

Magento错误 - Notice: Undefined index:***app\code\core\Mage\Core\Model\Mysql4\Config.php on line 92的解决办法

里的

SET FOREIGN_KEY_CHECKS=0;
update `core_store` set store_id = 0 where code='admin';
update `core_store_group` set group_id = 0 where name='Default';
update `core_website` set website_id = 0 where code='admin';
update `customer_group` set customer_group_id = 0 where customer_group_code='NOT LOGGED IN';
SET FOREIGN_KEY_CHECKS=1;

执行一遍清缓存就OK。

Magento Paypal支付接口无法传递运费

尽管Magento1.5已经出来了。。但现在大部分站还是继续1.4.0.1的。

Magento官方也公布了这个版本的多个BUG,其中一个是Magento1.4.0.1使用Paypal支付接口
的时候,如果客户先注册再放入购物车结算, 一切正常。 如果游客身份先放入购物车,然后再注册,去结算,就会在支付的时候 少算运费,后台的一切数值都正常,都是带运费的。但是就是Paypal收到的是不带运费的。

对着BUG修复文档处理了一下,问题可以解决。记录一下。。

app/code/core/Mage/Paypal/Helper/Data.php

         $shippingDescription = '';
-        if ($salesEntity instanceof Mage_Sales_Model_Order) {
-            $discountAmount = abs(1 * $salesEntity->getBaseDiscountAmount());
-            $shippingDescription = $salesEntity->getShippingDescription();
-            $totals = array(
-                'subtotal' => $salesEntity->getBaseSubtotal() - $discountAmount,
-                'tax'      => $salesEntity->getBaseTaxAmount(),
-                'shipping' => $salesEntity->getBaseShippingAmount(),
+        $discountAmount = abs(1 * $salesEntity->getBaseDiscountAmount());
+        $shippingDescription = $salesEntity->getShippingDescription();
+        $totals = array(
+            'subtotal' => $salesEntity->getBaseSubtotal() - $discountAmount,
+            'tax'      => $salesEntity->getBaseTaxAmount(),
+            'shipping' => $salesEntity->getBaseShippingAmount(),
+            'discount' => $discountAmount,
 //                'shipping_discount' => -1 * abs($salesEntity->getBaseShippingDiscountAmount()),
-            );
-        } else {
-            $address = $salesEntity->getIsVirtual() ? $salesEntity->getBillingAddress() : $salesEntity->getShippingAddress();
-            $discountAmount = abs(1 * $address->getBaseDiscountAmount());
-            $shippingDescription = $address->getShippingDescription();
-            $totals = array (
-                'subtotal' => $salesEntity->getBaseSubtotal() - $discountAmount,
-                'tax'      => $address->getBaseTaxAmount(),
-                'shipping' => $address->getBaseShippingAmount(),
-                'discount' => $discountAmount,
-//                'shipping_discount' => -1 * abs($address->getBaseShippingDiscountAmount()),
-            );
-        }
+        );

app/code/core/Mage/Paypal/Model/Standard.php

     public function getStandardCheckoutFormFields()
     {
+        $orderIncrementId = $this->getCheckout()->getLastRealOrderId();
+        $order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
         $api = Mage::getModel('paypal/api_standard')->setConfigObject($this->getConfig());
-        $quote = $this->getQuote();
-        $api->setOrderId($this->getCheckout()->getLastRealOrderId()) // TODO reserved order id
-            ->setCurrencyCode($quote->getBaseCurrencyCode())
+        $api->setOrderId($orderIncrementId)
+            ->setCurrencyCode($order->getBaseCurrencyCode())
             //->setPaymentAction()
             ->setNotifyUrl(Mage::getUrl('paypal/ipn/standard'))
             ->setReturnUrl(Mage::getUrl('paypal/standard/success'))
-            ->setCancelUrl(Mage::getUrl('paypal/standard/cancel'))
-        ;
+            ->setCancelUrl(Mage::getUrl('paypal/standard/cancel'));
 
         // export address
-        $isQuoteVirtual = $quote->getIsVirtual();
-        $address = $isQuoteVirtual ? $quote->getBillingAddress() : $quote->getShippingAddress();
-        if ($isQuoteVirtual) {
+        $isOrderVirtual = $order->getIsVirtual();
+        $address = $isOrderVirtual ? $order->getBillingAddress() : $order->getShippingAddress();
+        if ($isOrderVirtual) {
             $api->setNoShipping(true);
-        } elseif ($address->getEmail()) {
+        }
+        elseif ($address->getEmail()) {
             $api->setAddress($address);
         }
 
-        list($items, $totals, $discountAmount, $shippingAmount) = Mage::helper('paypal')->prepareLineItems($quote, false, true);
+        list($items, $totals, $discountAmount, $shippingAmount) = Mage::helper('paypal')->prepareLineItems($order, false, true);
         // prepare line items if required in config
         if ($this->_config->lineItemsEnabled) {
             $api->setLineItems($items)->setLineItemTotals($totals)->setDiscountAmount($discountAmount);
         }
         // or values specific for aggregated order
         else {
-            $grandTotal = $quote->getBaseGrandTotal();
-            if (!$isQuoteVirtual) {
+            $grandTotal = $order->getBaseGrandTotal();
+            if (!$isOrderVirtual) {
                 $api->setShippingAmount($shippingAmount);
                 $grandTotal -= $shippingAmount;
             }

app/code/core/Mage/Paypal/Model/Api/Standard.php

     protected $_exportToRequestFilters = array(
         'amount'   => '_filterAmount',
-        'shipping' => '_filterAmount',
+        'shipping' => '_filterAmount'
     );
         'amount' => 'amount_%d',
     );
 
+    protected $_lineItemExportItemsFilters = array(
+         'qty'      => '_filterQty'
+    );
+

app/code/core/Mage/Paypal/Model/Api/Abstract.php

     protected $_lineItemExportTotals = array();
     protected $_lineItemExportItemsFormat = array();
+    protected $_lineItemExportItemsFilters = array();


         foreach ($items as $item) {
             foreach ($this->_lineItemExportItemsFormat as $publicKey => $privateFormat) {
                 $value = $item->getDataUsingMethod($publicKey);
+                if (isset($this->_lineItemExportItemsFilters[$publicKey])) {
+                    $callback   = $this->_lineItemExportItemsFilters[$publicKey];
+                    $value = call_user_func(array($this, $callback), $value);
+                }
                 if (is_float($value)) {
                     $value = $this->_filterAmount($value);
                 }

     {
         return http_build_query($request);
     }
+
+    /**
+     * Filter qty in API calls
+     * Paypal note: The value for quantity must be a positive integer. Null, zero, or negative numbers are not allowed.
+     *
+     * @param float|string|int $value
+     * @return string
+     */
+    protected function _filterQty($value)
+    {
+        return intval($value);
+    }

乳此,Magento Paypal支付接口

又一枚iframe高度自适应代码 - (兼容FF,Opera,Safari多浏览器)

  1. <script type="text/javascript">
  2. function  SetCwinHeight(iframeObj){  
  3. if  (document.getElementById){   
  4.    if  (iframeObj){  
  5.      if  (iframeObj.contentDocument && iframeObj.contentDocument.body.offsetHeight){  
  6.       iframeObj.height = iframeObj.contentDocument.body.offsetHeight;  
  7.       }  else   if  (document.frames[iframeObj.name].document && document.frames
  8. [iframeObj.name].document.body.scrollHeight){  iframeObj.height = document.frames
  9. [iframeObj.name].document.body.scrollHeight;  
  10.       }  
  11.     }  
  12.   }  
  13. }  
  14. </script>
  1. <iframe name="frameContent" src="*" frameborder="0" width="100%" onload="SetCwinHeight
  2. (this)"></iframe>

注:标记*号的地方填入iframe页面的地址。需要注意的是,src地址必须是在同一网站下,否则会出现“权限被禁止”的错误。

php产生全球唯一标识符guid的算法一例

 

 

类库

<?php

// guid.php

class System {

  function currentTimeMillis() {

    list($usec, $sec) = explode(" ",microtime());

    return $sec.substr($usec, 2, 3);

  }

}

 

class NetAddress {

  var $name = 'localhost';

  var $ip   = '127.0.0.1';

  function getHost($coumputer_name, $ip) { // static

    $address = new NetAddress();

    $address->name = $coumputer_name;

    $address->ip   = $ip;

 

    return $address;

  }

 

  function toString() {

    return strtolower($this->name.'/'.$this->ip);

  }

}

 

class Random {

  function nextLong() {

    $tmp = rand(0,1)?'-':'';

    return $tmp.rand(1000, 9999).rand(1000, 9999).rand(1000, 9999).rand(100, 999).rand(100, 999);

  }

}

 

class Guid{

  var $valueBeforeMD5;

  var $valueAfterMD5;

  function Guid($computer_name, $ip){

    $this->getGuid($computer_name, $ip);

  }

 

  function getGuid($coumputer_name, $ip){

    $address = NetAddress::getHost($coumputer_name, $ip);

    $this->valueBeforeMD5 = $address->toString().':'.System::currentTimeMillis().':'.Random::nextLong();

    $this->valueAfterMD5 = md5($this->valueBeforeMD5);

  }

  

  function newGuid() {

   $Guid = new Guid();

   return $Guid;

  }

 

  function toString() {

   $raw = strtoupper($this->valueAfterMD5);

   return substr($raw,0,8).'-'.substr($raw,8,4).'-'.substr($raw,12,4).'-'.substr($raw,16,4).'-'.substr($raw,20);

  }

}

?>

 

调用

<?php

require_once('guid.php');

$computer_name = $_SERVER["SERVER_NAME"];

$ip            = $_SERVER["SERVER_ADDR"];

$guid = new Guid($computer_name, $ip);

print $guid->toString();

//调用产生的结果可能如: 3238D32E-807C-B1C4-01C4-FD1346D32110