列出所有購物車中的清單的程序

發表于:2007-07-14來源:作者:點擊數: 標簽:
這是我當時寫的一個列出所有購物車中的清單的程序,各位可自己根據需要改寫一下 ? php ob_start(); session_start(); /* $s=array(id = 6, name = 測試 a, price = 6, count =3); $t=array(id = 7, name = 測試b, price = 7, count =15); $u=array(id = 8, n
這是我當時寫的一個列出所有購物車中的清單的程序,各位可自己根據需要改寫一下
<?php
    ob_start();
    session_start()                 ;
/*
    $s=array("id" => 6, "name" => "測試a", "price" => "6", "count" =>3);
    $t=array("id" => 7, "name" => "測試b", "price" => "7", "count" =>15);
    $u=array("id" => 8, "name" => "測試c", "price" => "8", "count" =>21);
    $rst=array($s, $t, $u);

    */
    require_once("HTML/IT.php");
    $tpl    = new HTML_Template_IT("./");
    //讀取模板文件           
    $tpl->setRoot("./");
    $tpl->loadTemplatefile("listcart.html", true, true);
    require_once "../classes/cart.php" ;
    $cart = new cart   ;
//    $cart->addData($rst);
    $i=count($_POST[lines])    ;
    if($_POST["emptyAll"]==true)
    {
        //如果清空條件為真
        $cart->emptyAll()    ;
    }else{
        //如果用戶提交更新
        if( $i > 0)
        {
            //如果提交過來的數據大于一個商品
            $addData = $_POST[lines]    ;
            foreach($addData as $key=>$val)
            {
                if($val["del"]==true)
                {    
                    $cart->emptyOne($key)        ;
                    unset($addData[$key])            ;
                }
            }
            $cart->addData($addData)    ;
        }
    }
    $dat = $cart->getData();
    if(count($dat) > 0)
    {
        foreach($dat as $key=>$val)
        {        
            $tpl->setCurrentBlock("lines") ;
    //        $tpl->setVariable($lan) ;
            $tpl->setVariable("id", $key) ;        
            $tpl->setVariable("i" , $key) ;    
            $tpl->setVariable("totalCount" , $cart->getSortCount()) ;
            $tpl->setVariable("totalMoney" , $cart->getTotalCost()) ;
            $tpl->setVariable($val) ;    
            $tpl->parseCurrentBlock("lines") ;    
        }
    }
    //替換模板頁面中的標記
    $tpl->setCurrentBlock("page") ;
    if($key==false)$key=0;
    $tpl->setVariable("i" , $key) ;    
    $tpl->setVariable("mytitle", "我的購物籃") ;    
//    $tpl->setVariable($language->getLanUrl()) ;    
    $tpl->parseCurrentBlock("page") ;  

    //顯示頁面
    $tpl->show();

ob_end_flush();
?>

原文轉自:http://www.anti-gravitydesign.com

国产97人人超碰caoprom_尤物国产在线一区手机播放_精品国产一区二区三_色天使久久综合给合久久97