Created
May 11, 2010 20:16
-
-
Save fleeting/397807 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function cart() { | |
$aProducts = $_SESSION["cart"]; | |
$sSubTotal = 0; | |
foreach($_SESSION["cart"] as $aProduct) { | |
if (!empty($aProduct["sale_price"])) | |
$sSubTotal = $sSubTotal + $aProduct["sale_price"]; | |
else | |
$sSubTotal = $sSubTotal + $aProduct["price"]; | |
} | |
$this->tplAssign("aProducts", $aProducts); | |
$this->tplAssign("sSubTotal", money_format('%.2n', $sSubTotal)); | |
$this->tplDisplay("catalog/cart.tpl"); | |
} | |
function cart_add() { | |
$aProduct = $this->model->getProduct($this->_urlVars->dynamic["id"]); | |
if (array_key_exists($aProduct["id"], $_SESSION["cart"])) { | |
$_SESSION["cart"][$aProduct["id"]]["quantity"]++; | |
} else { | |
$aProduct["quantity"] = 1; | |
$_SESSION["cart"][$aProduct["id"]] = $aProduct; | |
} | |
$this->forward("/store/cart/?notice=".urlencode($aProduct["title"]." added to cart.")); | |
} | |
function cart_update() { | |
foreach($_POST as $sId => $sQuantity) { | |
if ($sQuantity == 0) | |
unset($_SESSION["cart"][$sId]); | |
else | |
$_SESSION["cart"][$sId]["quantity"] = $sQuantity; | |
} | |
$this->forward("/store/cart/?notice=".urlencode("Cart was successfully updated.")); | |
} | |
function cart_delete() { | |
unset($_SESSION["cart"][$this->_urlVars->dynamic["id"]]); | |
$this->forward("/store/cart/?notice=".urlencode("Product removed from cart.")); | |
} | |
function cart_empty() { | |
$_SESSION["cart"] = null; | |
$this->forward("/store/cart/"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment