zoukankan      html  css  js  c++  java
  • 购物车代码

    <?php
    /**
    * 购物车
    *
    * @copyright Copyright (c) 2006 - 2008 coderhome.net
    * @author 志凡 <dzjzmj@163.com>
    * @package Model
    * @version v0.1
    */

    class ModelCart extends Model {

    /**
    * 构造函数
    * @param Object $db 数据查询类
    * @access public
    * @return void
    */
    function __construct($query=null) {
    parent::__construct($query);
    session_start();
    }

    function add($productInfo) {
    $product = new ModelProduct();
    $productItem = $product->getInfo($productInfo['id']);
    $info = array(
    'id' => $productInfo['id'],
    'product_name' => $productInfo['product_name'],
    'attribute' => $productInfo['attribute'],
    'price' => $productInfo['price'],
    'sn' => $productItem['sn'],
    'photoUrl' => CFG_URL . 'data/product/'.$productItem['photo'],
    'number' => 1,
    );
    $_SESSION['cartInfo'][$productInfo['id'].'_'.$productInfo['attribute']] = $info;
    }

    function changeNumber($id,$number) {
    $_SESSION['cartInfo'][$id]['number'] = $number;
    }
    static function count() {
    session_start();
    return count($_SESSION['cartInfo']);
    }

    function getAll() {
    $items = $_SESSION['cartInfo'];
    $result = array();
    foreach ($items as $key => $item) {
    $attrs = explode('||',$item['attribute']);
    foreach ($attrs as $attr) {
    $i = explode('=',$attr);
    $n = explode(',',$i[1]);
    $item[$i[0]] = $n[1];
    $item[$i[0].'_id'] = $n[0];
    }
    $item['prices'] = $item['price']*$item['number'];
    $item['cart_id'] = urlencode($item['id'].'_'.$item['attribute']);
    $result[] = $item;
    }
    return $result;
    }
    function getCount() {
    $items = $this->getAll();
    $count = 0;
    foreach ($items as $key => $item) {
    $count += $item['prices'];
    }
    return $count;

    }
    function clear() {
    $_SESSION['cartInfo'] = array();
    }

    function delete($id) {
    unset($_SESSION['cartInfo'][$id]);
    }

    }
    ?>

    http://www.corange.cn/archives/2008/10/2054.html

  • 相关阅读:
    routine 程序;日常工作|日常的;例行的
    have great expectation of 寄予厚望
    数据库总结十完整性约束
    Spoken Language One
    Stature 身高,身材;(精神、道德等的)高度
    ultimate与estimate
    dramatically 从戏剧角度;戏剧性地,显著地
    predestined 注定的
    How to lists.
    endanger 危及;使遭到危险
  • 原文地址:https://www.cnblogs.com/zerogo/p/2209196.html
Copyright © 2011-2022 走看看