実践的なPHPショッピングカートプログラム、実践的なPHPショッピングカートプログラム_PHPチュートリアル

WBOY
リリース: 2016-07-13 10:15:45
オリジナル
688 人が閲覧しました

実践的なphpショッピングカートプログラム、実践的なphpショッピングカートプログラム

実践的なphpチュートリアルショッピングカートプログラム
以前使ったことがあるのですが、これも読んで気持ちが良かったので友達に紹介します参考に必要な方。

//インスタンスを呼び出す
require_once 'cart.class.php';
session_start();
if(!isset($_SESSION['cart'])) {
$_SESSION['cart'] =新しいカート;
}
$cart =& $_SESSION['カート'];

if( ($_SERVER['REQUEST_METHOD']=="POST")&&($_POST['action']=='add') ){
$p = $_POST['p'];
$items = $cart->add($p);
}
if( ($_GET['action']=='remove')&&($_GET['key']!="") ) {
$items = $cart->remove($_GET['key']);
}

if( ($_SERVER['REQUEST_METHOD']=="POST")&&($_POST['action']=='modi') ){
$key = $_POST['key'];
$value = $_POST['value'];
for($i=0;$i $items = $cart->modi($key[$i],$value[ $i]);
}
}

$items = $cart->getCart();
//Print
echo "

";
setlocale(LC_MONETARY, 'it_IT');
foreach($items as $item){
echo "";
echo "";
echo "
ID:".$item['ID']."";
echo "
製品:".$item['name'];
echo "
ユニット価格 :".$item['price'];
echo "
";
$sum = $item['count']*$item['price'];
echo "
Total:".round($sum,2);
echo "
";
}
echo " " ;
echo "
";


?>




ID:
商品名:
単価:
数量:


/**
* Cart
*
* ショッピングカートカテゴリ
*
* @author doodoo
* @package Cart
* @category Cart
* @license PHP License
* @access public
* @バージョン $リビジョン: 1.10 $
*/
クラスカート{

var $cart;
var $totalCount; //商品の合計数量
var $totalPrices; //商品の合計数量

/**
* Cart Constructor
*
* ショッピングカートを安定した初期化状態に保つためのクラスのコンストラクター
*
* @static
* @access public
* @return void 戻り値なし
* @param void パラメータなし
*/
function Cart(){
$this->totalCount = 0;
$this->totalPrice = 0;
$this->cart = array();
}

// }}}
// {{{ add($item)

/**
* 現在の買い物カゴに商品を追加します
*
* @access public
* @param array $item 商品情報(一次元配列:配列(商品ID、商品名、商品単価、商品数量))
* @ return array 現在のショッピングカート内のアイテムの配列を返します
*/
function add($item){
if(!is_array($item)||is_null($item)) return $this->cart;
if(!is_numeric(end( $item))||(!is_numeric(prev($item)))) {
echo "価格と数量は数値である必要があります";
return $this->cart;
}
restart($item); //この文が必要なのは、上記の判断により配列のインデックスが移動したためです
$key = current($item);
if($key=="") return $this->cart;
if($this- > ;_isExists($key)){ //製品はすでに存在しますか?
$this->cart[$key]['count'] = end($item);
return $this->cart;
}

$this->ca(www.111cn.net)rt[$key]['ID'] = $key;
$this->cart[$key]['name'] = next($item) ;
$this->カート[$key]['価格'] = next($item);
$this->カート[$key]['count'] = next($item);

$this->cart;
を返す }

// }}}
// {{{ add($item)

/**
* 現在のショッピング カートから一部またはすべての商品を削除します
* $key=="" の場合、現在のショッピング カートをクリアします
* $key!=""&&$count=="" の場合、現在のショッピング カートから商品を削除しますショッピングカート 商品ID番号$keyの商品を全てカートから取り出します
※$key!=""&&$count!=""の場合、現在の買い物から商品ID番号$keyの商品を$count個取り出しますカート
*
* @access public
* @param string $key product ID
* @returnmixed true または false、または現在のショッピング カート内のアイテムの配列を返します
*/
function Remove($key="",$count=""){
if($key=="") {
$this->cart = array();
return true;
}
if(!array_key_exists($key,$this->cart)) return false;
if($count==""){ //移去这一类商品
unset($this- >cart[$key]);
}else{ //移去$count个商品
$this->cart[$key]['count'] -= $count;
if($this->カート[$key]['count']<=0) unset($this->cart[$key]);
}
return $this->cart;
}

// }}}
// {{{ modi($key,$value)

/**
* ショッピングカート内の商品ID $key の商品の数量を $value に変更します
*
* @access public
* @param string $key product ID
* @param int $value productquantum
* @return arrayショッピング カート内の現在のアイテムの配列を返します;
*/
function modi($key,$value){
if(!$this->_isExists($key)) return $this->cart(); //この商品は存在しません、直接返されます
if($value<=0){ // 値は太小、全部删除
unset($this->cart[$key]);
return $this->cart ;
}
$this->cart[$key]['count'] = $value;
return $this->cart;
}


/**
* 現在のショッピング カート内のアイテムの配列を返します
*
* @access public
* @return array 現在のショッピング カート内のアイテムの配列を返します;
*/
function getCart(){
return $this->cart;
}

// }}}
// {{{ _isExists($key)

/**
* 現在のショッピングカートに製品 ID 番号 $key の製品があるかどうかを確認します
*
* @access private
* @param string $key product ID
* @return bool true または false;
*/
function _isExists($key)
{
if(isset($this->cart[$key])&&!empty($this->cart[$key])&&array_key_exists ($key,$this->cart))
true を返す;
false を返す;
}

// }}}
// {{{ isEmpty()

/**
* 現在のショッピング カートが空かどうか、つまり商品がないかどうかを判断します
*
* @access public
* @return bool true または false;
*/
function isEmpty(){
return !count($this->cart);
}

// }}}
// {{{ _stat()

/**
* 統計情報を取得します
*
* @access private
* @return bool true または false;
*/
function _stat(){
if($this->isEmpty()) return false;
foreach($this->cart as $item){
$this-> totalCount = @end($item);
$this->totalPrices = @prev($item);
}
return true;
}

// }}}
// {{{ totalPrices()

/**
* 現在のショッピングカート内の全商品の合計金額を取得します
*
* @access public
* @return float return amount;
*/
function totalPrices(){
if($this->_stat())
return $this->totalPrices;
return 0;
}

// }}}
// {{{ isEmpty()

/**
* 現在のショッピング カート内のすべてのアイテムの合計数量を取得し、
*
* @access public
* @return int ;
*/
function totalCount(){
if($this->_stat())
return $this->totalCount;
0 を返す;
}


}//End Class Cart
?>
from:http://www.111cn.net/phper/php-gj/39684.htm

怎用PHP编个购物车的程序?

MySQL は重要な点ではなく、これらの質問や入力の類の言葉ではなく、商品情報の順序付けを行った後、前の台 COOKIE を実行して保存する必要があるため、必要に応じて保存する必要があります。より良い如き页面無刷新实時対話操作的効果,要加上AJAX+JSON技术~~
楼主给的分数~~~只能给你个思路做参照啊~~
 

php怎调用购物车程序

これは php クラスであり、php 内でのみ呼び出すことができます。これはプログラムではなく、プログラムのプロセスのほんの数十分の 1 つです

www.bkjia.com本当http://www.bkjia.com/PHPjc/902438.html技術記事実践 php ショッピング カート プログラム、実践 php ショッピング カート プログラム、実践 php チュートリアル ショッピング カート プログラム、前にも使ったことがあるけどいい感じだったんですが、これを見たら気分が良くなったので、必要な方に紹介します…。
関連ラベル:
php
ソース:php.cn
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
最新の問題
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!