ecshop 默认第一个配送支付方式的选中

<!– {foreach from=$shipping_list key=shippingkey item=shipping} 循环配送方式 –>

<input name=”shipping” type=”radio” value=”{$shipping.shipping_id}” {if $order.shipping_id eq $shipping.shipping_id || $shippingkey eq 0 }checked=”true”{/if}   supportCod=”{$shipping.support_cod}” insure=”{$shipping.insure}” onclick=”selectShipping(this)” />

<!– {/foreach} 循环配送方式 –>

注意里面的   key=shippingkey item=shipping 和  $shippingkey eq 0 ,理解了php的数组key=>value 就明白了

 

paymentcheckdefault

ecshop 的部分sql缓存read_static_cache和write_static_cache

可以利用read_static_cache和write_static_cache 来缓存一些不经常变化的数据来缓存

$data_attr = read_static_cache(‘all_attr_list_’.md5($_SERVER[‘REQUEST_URI’]));

if ($data_attr === false)
{
// 获得$all_attr_list的sql逻辑
write_static_cache(‘all_attr_list_’.md5($_SERVER[‘REQUEST_URI’]), $all_attr_list);
}else{
// 来自缓存的数据
$all_attr_list = $data_attr;
}

这样可以在 temp/static_cache/下生成缓存数据

ecshop 属性筛选在category.php 页面显示顺序错误,调整和后台排序一致

在category.php 行 272处查找

$attr_list = $db->getAll($sql);
字样然后下面增加如下代码 
从phpsir_filter_code_start 到 phpsir_filter_code_end 中间部分
$attr_list = $db->getAll($sql);
//phpsir_filter_code_start
                $phpsir_tmp=$attr_list[0];
                $phpsir_sql= "select attr_values from " . $ecs->table('attribute') . " WHERE attr_id = '$phpsir_tmp[attr_id]' ";
                $phpsir_attribute = $db->getOne($phpsir_sql);  
                $phpsir_ga = explode("\n",$phpsir_attribute);
                $phpsir_new_attr_list = array();
                foreach($attr_list as $kk=>$vv)
                {
                    foreach($phpsir_ga as $kkk => $vvv){
                        if(trim($vv['attr_value']) == trim($vvv))
                        {
                            $phpsir_new_attr_list[$kkk] = $vv;
                        }
                    }
                }
                ksort($phpsir_new_attr_list);
                $attr_list = $phpsir_new_attr_list;
//phpsir_filter_code_end

前台显示例子如下

phpsir_filter_code1

 

代码在上面,或者如下图

phpsir_filter_code

 

 

ecshop 按订单金额发放红包 发放存在多发的问题

http://bbs.ecshop.com/viewthread.php?tid=159368

原始问题如上,截屏如下

ecshop_bonus

 

解决问题是看  includes\lib_order.php 的函数 get_total_bonus

原来代码是如下的

/* 按订单发的红包 */
$sql = “SELECT FLOOR(‘$amount’ / min_amount) * type_money ” .
“FROM ” . $GLOBALS[‘ecs’]->table(‘bonus_type’) .
” WHERE send_type = ‘” . SEND_BY_ORDER . “‘ ” .
” AND send_start_date <= ‘$today’ ” .
“AND send_end_date >= ‘$today’ ” .
“AND min_amount > 0 “;

很显然,凡是比较最低订单金额大的订单,都会导致商的个数的红包,我们其实只要发的是最大的红包那个就可以了,所以我们修改如下

/* 按订单发的红包 */
$sql = “SELECT FLOOR(‘$amount’ / min_amount) * type_money ” .
“FROM ” . $GLOBALS[‘ecs’]->table(‘bonus_type’) .
” WHERE send_type = ‘” . SEND_BY_ORDER . “‘ ” .
” AND send_start_date <= ‘$today’ ” .
“AND send_end_date >= ‘$today’ ” .
“AND min_amount > 0 and min_amount <= ‘$amount’ order by min_amount desc limit 1 “; 注意上面这行的条件增加了
and min_amount <= ‘$amount’ order by min_amount desc limit 1
就是说最接近订单额度的红包发放条件,取一个即可

ecshop的lib_payment.php的get_order_id_by_sn需要订正

get_order_id_by_sn 函数在通过order_id 在pay_log 表里查找支付记录的时候,不够严格,导致可能一个order_id 对应多个pay_log记录,需要找到的是最后也就是log_id 最大的那个。那么从这个角度看,这个代码就需要加一句 order by log_id  DESC 的字样

return $GLOBALS[‘db’]->getOne(“SELECT log_id FROM ” . $GLOBALS[‘ecs’]->table(‘pay_log’) . ” WHERE order_id=” . $order_sn . ‘ AND order_type=1’);

就需要修改为

return $GLOBALS[‘db’]->getOne(“SELECT log_id FROM ” . $GLOBALS[‘ecs’]->table(‘pay_log’) . ” WHERE order_id=” . $order_sn . ‘ AND order_type=1 order by log_id DESC ‘);

nginx的ecshop伪静态配置

nginx 配置 ecshop 伪静态
if (!-e $request_filename)
{
rewrite "^/index\.html" /index.php last;
rewrite "^/category$" /index.php last;
rewrite "^/feed-c([0-9]+)\.xml$" /feed.php?cat=$1 last;
rewrite "^/feed-b([0-9]+)\.xml$" /feed.php?brand=$1 last;
rewrite "^/feed\.xml$" /feed.php last;
rewrite "^/category-([0-9]+)-b([0-9]+)-min([0-9]+)-max([0-9]+)-attr([^-]*)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html$" /category.php?id=$1&brand=$2&price_min=$3&price_max=$4&filter_attr=$5&page=$6&sort=$7&order=$8 last;
rewrite "^/category-([0-9]+)-b([0-9]+)-min([0-9]+)-max([0-9]+)-attr([^-]*)(.*)\.html$" /category.php?id=$1&brand=$2&price_min=$3&price_max=$4&filter_attr=$5 last;
rewrite "^/category-([0-9]+)-b([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html$" /category.php?id=$1&brand=$2&page=$3&sort=$4&order=$5 last;
rewrite "^/category-([0-9]+)-b([0-9]+)-([0-9]+)(.*)\.html$" /category.php?id=$1&brand=$2&page=$3 last;
rewrite "^/category-([0-9]+)-b([0-9]+)(.*)\.html$" /category.php?id=$1&brand=$2 last;
rewrite "^/category-([0-9]+)(.*)\.html$" /category.php?id=$1 last;
rewrite "^/goods-([0-9]+)(.*)\.html" /goods.php?id=$1 last;
rewrite "^/article_cat-([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html$" /article_cat.php?id=$1&page=$2&sort=$3&order=$4 last;
rewrite "^/article_cat-([0-9]+)-([0-9]+)(.*)\.html$" /article_cat.php?id=$1&page=$2 last;
rewrite "^/article_cat-([0-9]+)(.*)\.html$" /article_cat.php?id=$1 last;
rewrite "^/article-([0-9]+)(.*)\.html$" /article.php?id=$1 last;
rewrite "^/brand-([0-9]+)-c([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)\.html" /brand.php?id=$1&cat=$2&page=$3&sort=$4&order=$5 last;
rewrite "^/brand-([0-9]+)-c([0-9]+)-([0-9]+)(.*)\.html" /brand.php?id=$1&cat=$2&page=$3 last;
rewrite "^/brand-([0-9]+)-c([0-9]+)(.*)\.html" /brand.php?id=$1&cat=$2 last;
rewrite "^/brand-([0-9]+)(.*)\.html" /brand.php?id=$1 last;
rewrite "^/tag-(.*)\.html" /search.php?keywords=$1 last;
rewrite "^/snatch-([0-9]+)\.html$" /snatch.php?id=$1 last;
rewrite "^/group_buy-([0-9]+)\.html$" /group_buy.php?act=view&id=$1 last;
rewrite "^/auction-([0-9]+)\.html$" /auction.php?act=view&id=$1 last;
rewrite "^/exchange-id([0-9]+)(.*)\.html$" /exchange.php?id=$1&act=view last;
rewrite "^/exchange-([0-9]+)-min([0-9]+)-max([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html$" /exchange.php?cat_id=$1&integral_min=$2&integral_max=$3&page=$4&sort=$5&order=$6 last;
rewrite ^/exchange-([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html$" /exchange.php?cat_id=$1&page=$2&sort=$3&order=$4 last;
rewrite "^/exchange-([0-9]+)-([0-9]+)(.*)\.html$" /exchange.php?cat_id=$1&page=$2 last;
rewrite "^/exchange-([0-9]+)(.*)\.html$" /exchange.php?cat_id=$1 last;
}

两个ecshop的同步,相同goods_sn的价格保持一致

假设 A库 同步到 B 库,就是说A库发生变化了,B库就要和A保持一致,相同goods_sn的商品价格也变化到和A相同,那么A 为sorce_table,B 为 target_table  ,相应的SQL为 :

update b.ecs_goods target_table  ,a.ecs_goods source_table set target_table.shop_price = source_table.shop_price where source_table.goods_sn = target_table.goods_sn;

ecshop 注册送红包

在user.php 的注册成功信息显示前面,大概是  show_message(sprintf($_LANG['register_success'].............前面加入
注意下下面的 $bonus_type_id = 1; 需要先在后台加入对应的红包的id

//phpsir 1111
$bonus_type_id=1;
$bonus = $db->getRow('SELECT * FROM ' . $ecs->table("bonus_type") . " WHERE send_type = 0 And type_id =  $bonus_type_id", true); 
if($bonus){ if(time()<($bonus['send_end_date']+28800)){
 $sql = "INSERT INTO " . $ecs->table('user_bonus') . "(bonus_type_id, bonus_sn, user_id, used_time, order_id, emailed) " . "VALUES ('$bonus[type_id]', 0, '$_SESSION[user_id]', 0, 0, 0)";
 $db->query($sql); } } 
//phpsir 1111_end

ecshop的paypal sandbox 测试支付,需要修改的部分

QQ截图20130503164129

QQ截图20130503163955

下面是代码,方便复制

get_code函数里面
 $def_url  = '<br /><form style="text-align:center;" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" target="_blank">' .   // 不能省略
respond 函数里面
// post back to PayPal system to validate
$header = "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "HOST: www.sandbox.paypal.com\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) ."\r\n\r\n";
$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);

再谈godaddy空间的ecshop程序reformat_image_name函数

还是那一点,因为godaddy空间可能限制某目录下过多文件,所以ecshop,甚至其他任何cms,shop 程序,试图在单一目录下存储大量图片或者小文件的,请考虑用目录分散避免,
在ecshop的 reformat_image_name 仅仅用 date(“Ym”) 来分布图片
也就是用年4位月两位来设计图片目录,建议可以简单更改为 date(“Ymd”) 按日期分布,就可以避免此类问题
当然你也可以设计为 年4位月两位+00-99 的随机目录,总之确认一点就是,Gd空间为了效率,对咱们做了限制,同时也对服务器管理员提了个醒,
要在系统设计之初就考虑到大量图片分布的问题,这类事情对于大电商也很重要,他们甚至专门有图片服务器,而且采用了分布话处理,启用单独无cookie域名来实现效率优化。

2012 12 29 phpsir 有感

ecshop 的 reformat_image_name 在godaddy 空间错误的纠错代码

问题描述:

在godaddy空间,出现ecshop相册无法生成,经调试发现是 function move_image_file 内部copy函数出错 ,纠结原因是目标目录内文件过多,修改 reformat_image_name 让再分出一个目录来安置图片

function reformat_image_name($type, $goods_id, $source_img, $position='')
{
    $rand_name = gmtime() . sprintf("%03d", mt_rand(1,999));
    $img_ext = substr($source_img, strrpos($source_img, '.'));
    $dir = 'images';
    if (defined('IMAGE_DIR'))
    {
        $dir = IMAGE_DIR;
    }
    $sub_dir = date('Ym', gmtime());
    if (!make_dir(ROOT_PATH.$dir.'/'.$sub_dir))
    {
        return false;
    }
    if (!make_dir(ROOT_PATH.$dir.'/'.$sub_dir.'/source_img'))
    {
        return false;
    }
    if (!make_dir(ROOT_PATH.$dir.'/'.$sub_dir.'/goods_img'))
    {
        return false;
    }
    if (!make_dir(ROOT_PATH.$dir.'/'.$sub_dir.'/goods_img_2'))
    {
        return false;
    }
    if (!make_dir(ROOT_PATH.$dir.'/'.$sub_dir.'/thumb_img'))
    {
        return false;
    }
    if (!make_dir(ROOT_PATH.$dir.'/'.$sub_dir.'/thumb_img_2'))
    {
        return false;
    }
    switch($type)
    {
        case 'goods':
            $img_name = $goods_id . '_G_' . $rand_name;
            break;
        case 'goods_thumb':
            $img_name = $goods_id . '_thumb_G_' . $rand_name;
            break;
        case 'gallery':
            $img_name = $goods_id . '_P_' . $rand_name;
            break;
        case 'gallery_thumb':
            $img_name = $goods_id . '_thumb_P_' . $rand_name;
            break;
    }
    if ($position == 'source')
    {
        if (move_image_file(ROOT_PATH.$source_img, ROOT_PATH.$dir.'/'.$sub_dir.'/source_img/'.$img_name.$img_ext))
        {
            return $dir.'/'.$sub_dir.'/source_img/'.$img_name.$img_ext;
        }
    }
    elseif ($position == 'thumb')
    {
        if (move_image_file(ROOT_PATH.$source_img, ROOT_PATH.$dir.'/'.$sub_dir.'/thumb_img/'.$img_name.$img_ext))
        {
            return $dir.'/'.$sub_dir.'/thumb_img/'.$img_name.$img_ext;
        }else{
           if (move_image_file(ROOT_PATH.$source_img, ROOT_PATH.$dir.'/'.$sub_dir.'/thumb_img_2/'.$img_name.$img_ext))
           {
            return $dir.'/'.$sub_dir.'/thumb_img_2/'.$img_name.$img_ext;
           }
        }
    }
    else
    {
        if (move_image_file(ROOT_PATH.$source_img, ROOT_PATH.$dir.'/'.$sub_dir.'/goods_img/'.$img_name.$img_ext))
        {
            return $dir.'/'.$sub_dir.'/goods_img/'.$img_name.$img_ext;
        }else{
            if (move_image_file(ROOT_PATH.$source_img, ROOT_PATH.$dir.'/'.$sub_dir.'/goods_img_2/'.$img_name.$img_ext))
            {
                return $dir.'/'.$sub_dir.'/goods_img_2/'.$img_name.$img_ext;
            }
        }
    }
    return false;
}

上面代码中 goods_img_2 和 thumb_img_2 就是转存目录

ecshop 管理员自动登出

故障原因:
ECSHOP的SESSION采用IP生成用户唯1码,这样的话,多线接入的用户在路由自动切换时就会造成IP变化,这样,SESSION也就丢失了,与SESSION相关的登陆、购物车也就失效。

下面是我的解决办法,也许是目前最快捷最有效的方法。

原理:
当用户第一次登陆时,将用户的首次登陆IP存入Cookie,其它功能依然使用ECSHOP的SESSION。

摘选自

http://bbs.ecshop.com/viewthread.php?tid=198499&from=favorites