修改過的PHP購物車類

2021-09-30 02:59:02 字數 1389 閱讀 7781

在使用smarty呼叫購物車的時候,發現不能加入成功顯示,研究了一天後,終於弄明白了。下面是修改後的購物車類

/*** cart

* * 購物車類

* * @author  doodoo<

[email protected]

>

* @package     cart

* @category    cart

* @license     php license

* @access      public

* @version     $revision: 1.20 $

* @date  2004-08-21

*/class cart

// }}}

// reset($item); //這一句是必須的,因為上面的判斷已經移動了陣列的指標

$key = current($item);

if($key=="")   return $this->_getarray($this->cart);

if($this->_i***ists($key))

$this->cart[$key]['id']  = $key;

$this->cart[$key]['name'] = next($item);

$this->cart[$key]['price'] = next($item);

$this->cart[$key]['count'] = next($item);

return $this->_getarray($this->cart);

}// }}}

// if(!array_key_exists($key,$this->cart)) return false;

if($count=="")else

return $this->_getarray($this->cart);

}// }}}

// $this->cart[$key]['count'] = $value;

return $this->_getarray($this->cart);

}/**

* 返回當前購物車內商品的陣列

** @access public

* @return array  返回當前購物車內商品的陣列;

*/ function getcart()

// }}}

// // }}}

// // }}}

// // }}}

// return true;

}// }}}

// // }}}

// }//end class cart

session_start();

if(!isset($_session['cart']))

?>

php購物車類 初步實現

class cart 禁止轉殖 final protected function clone 類內部例項化 static protected function getins return self ins 為了能使商品跨頁面儲存,把物件放入session裡 public static functio...

PHP 分析購物車

購物車的特性 全站唯一性 即 全站特性 唯一特性 購物車的基本功能 新增商品 刪除商品 修改商品數量 商品數量加1 減1 商品列表 計算總 計算商品種類 計算商品數量 清空購物車。思考 為什麼需要 購物車 先想象現實場景 我們每次去超市購物,有可能只買一件商品,也有可能同時買多件商品。在網上購物也一...

php新增購物車

水果代號 水果名稱 水果 水果產地 水果庫存 操作 session start include fengzhuang dbda.class.php db new dbda sql select from fruit arr db query sql foreach arr as v 加入購物車 va...