//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>
发表评论 取消回复