//js 清空
// function clear_history() {
//     layer.load()
//     $.post("/addons/shop/ajax/clearhistory",function(res){
//         layer.closeAll()
//         if(res.code==1){
//             setTimeout(function(){window.location.reload()},1000)
//             msg(res.msg)
//         }else{
//             alert(res.msg)
//         }

//     });
// }

// public function clearhistory(){
    //     cookie("historyid",null);
    //     $this->success("操作成功!");
    // }

//{:addHistory($__goods__.id)}
function addHistory($productId){  
    // 获取已存储在Cookie中的商品ID数组  
    $history = cookie('historyid') ?: [];  
    // 将新的商品ID添加到数组中  
    if(!in_array($productId,$history)){
        $history[] = $productId;  
        cookie('historyid', $history); 
    }
       
}  
//{assign name="HistoryList" value=":HistoryList()" /}
function HistoryList($limit=10){  
    return cookie("historyid") ? \addons\shop\model\Goods::where("id","in",cookie("historyid"))->limit($limit)->select() :[];
}

快捷键:liulanjilu

源:

sublime_text格式

<snippet>
    <content><![CDATA[
//js 清空
// function clear_history() {
//     layer.load()
//     \$.post("/addons/shop/ajax/clearhistory",function(res){
//         layer.closeAll()
//         if(res.code==1){
//             setTimeout(function(){window.location.reload()},1000)
//             msg(res.msg)
//         }else{
//             alert(res.msg)
//         }

//     });
// }

// public function clearhistory(){
    //     cookie("historyid",null);
    //     \$this->success("操作成功!");
    // }

//{:addHistory(\$__goods__.id)}
function addHistory(\$productId){  
    // 获取已存储在Cookie中的商品ID数组  
    \$history = cookie('historyid') ?: [];  
    // 将新的商品ID添加到数组中  
    if(!in_array(\$productId,\$history)){
        \$history[] = \$productId;  
        cookie('historyid', \$history); 
    }
       
}  
//{assign name="HistoryList" value=":HistoryList()" /}
function HistoryList(\$limit=10){  
    return cookie("historyid") ? \addons\shop\model\Goods::where("id","in",cookie("historyid"))->limit(\$limit)->select() :[];
}
]]></content>
   <tabTrigger>liulanjilu(浏览记录 历史)</tabTrigger>
   <scope></scope>
</snippet>
点赞(0)

评论列表 共有 0 条评论

暂无评论
立即
投稿
发表
评论
返回
顶部