写一个简单的php程序代码,一个简单的php+Ajax购物车程序代码(1/2)_PHP教程

cart_name = $name;

$this->items = $_SESSION[$this->cart_name];

}

/**

* setItemQuantity() – Set the quantity of an item.

*

* @param string $order_code The order code of the item.

* @param int $quantity The quantity.

*/

function setItemQuantity($order_code, $quantity) {

$this->items[$order_code] = $quantity;

}

/**

* getItemPrice() – Get the price of an item.

*

* @param string $order_code The order code of the item.

* @return int The price.

*/

function getItemPrice($order_code) {

// This is where the code taht retrieves prices

// goes. We’ll just say everything costs $9.99 for this tutorial.

return 9.99;

}

/**

* getItemName() – Get the name of an item.

*

* @param string $order_code The order code of the item.

*/

function getItemName($order_code) {

// This is where the code that retrieves product names

// goes. We’ll just return something generic for this tutorial.

return ‘My Product (‘ . $order_code . ‘)’;

}

/**

* getItems() – Get all items.

*

* @return array The items.

*/

function getItems() {

return $this->items;

}

/**

* hasItems() – Checks to see if there are items in the cart.

*

* @return bool True if there are items.

*/

function hasItems() {

return (bool) $this->items;

}

/**

* getItemQuantity() – Get the quantity of an item in the cart.

*

* @param string $order_code The order code.

* @return int The quantity.

*/

function getItemQuantity($order_code) {

return (int) $this->items[$order_code];

}

/**

* clean() – Cleanup the cart contents. If any items have a

* quantity less than one, remove them.

*/

function clean() {

foreach ( $this->items as $order_code=>$quantity ) {

if ( $quantity items[$order_code]);

}

}

/**

* save() – Saves the cart to a session variable.

*/

function save() {

$this->clean();

$_SESSION[$this->cart_name] = $this->items;

}

}

?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值