厨卫小哥 發表於 2023-9-26 00:00:00

织梦Dedecms5.7整站调用购物车订单数量简单解决办法

<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        后来想想,其实也挺简单的,就是调用cookie数据,后来看了一下Dedecms的购物车类shopcar.class.php,有现成的函数cartCount可用,为了不影响模板调用,就自己写了个简单的文件,用javascript调用。</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        方法实现如下:</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        一、建立一个my_car_count.php文件,放在/plus/目录下面;</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        二、写上如下代码:</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
         </p>
<div class="msgheader" style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
        <div class="right">
                <span><u>复制代码</u></span>
</div>
        代码如下:</div>
<div class="msgborder" id="phpcode1" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
        <br>
        &lt;?php<br>
        /**<br>
        * my_car_count.php<br>
        * /plus<br>
        * 显示购物车的商品数量<br>
        * http://www.jb51.net/cms<br>
        * <u>QQ</u>: 834114969<br>
        */<br>
        require_once (dirname(__FILE__) . "/../include/common.inc.php");<br>
        define('_PLUS_TPL_', DEDEROOT.'/templets/plus');<br>
        require_once(DEDEINC.'/dedetemplate.class.php');<br>
        require_once DEDEINC.'/shopcar.class.php';<br>
        $cart = new MemberShops();&lt;/p&gt; &lt;p&gt;$car_count = 0;&lt;/p&gt; &lt;p&gt;if($cart-&gt;cartCount() &gt;= 1)<br>
        {<br>
        $car_count = $cart-&gt;cartCount();<br>
        }<br>
        echo ('document.write("' . $car_count . '"); ');<br>
        exit;<br>
        ?&gt;</div>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
         </p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        三、在你需要调用的地方写上调用代码,比如:购物车商品数 </p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        大功告,是不是非常简单啊!</p>
頁: [1]
查看完整版本: 织梦Dedecms5.7整站调用购物车订单数量简单解决办法