function deleteItem($itemId) { $item = new Item($itemId); $cart = get_cart(); $cart->deleteItem($item); update_cart($cart); }
function updateData($userOrig = null) { global $errorMsg; $user = null; if ($userOrig == null) { $user = new User(); } else { $user = new User($userOrig->email, $userOrig->password); } $objectVars = array_keys(get_object_vars($user)); foreach ($_REQUEST as $key => $value) { if (NP_startsWith("user_", $key)) { $path = split("_", $key); $property = $path[1]; if (in_array($property, $objectVars)) { if (is_array($user->{$property})) { if (isset($_REQUEST['sameData']) && $_REQUEST['sameData'] == "true") { if ($property == "billingData") { $user->billingData = array_merge($user->billingData, array($path[2] => $value)); $user->shippingData = array_merge($user->shippingData, array($path[2] => $value)); } } else { $user->{$property} = array_merge($user->{$property}, array($path[2] => $value)); } } else { $user->{$property} = $value; } } } } if (isset($_REQUEST['user_password']) && isset($_REQUEST['newPassword1']) && isset($_REQUEST['newPassword2']) && $_REQUEST['newPassword1'] == $_REQUEST['newPassword2']) { if ($user->password == $userOrig->password) { $user->password = $_REQUEST['newPassword1']; $cart = get_cart(); $cart->user->update($user); update_cart($cart); } else { global $error; $errorMsg = _("El password antiguo no es correcto o los nuevos no coinciden."); return false; } } else { $cart = get_cart(); $cart->user->update($user); update_cart($cart); } /* $cart = get_cart(); print_r($cart->user); $cart->user->update(); */ // reload data from DDBB $cart->user = new User($cart->user->email, $cart->user->password); update_cart($cart); return true; }
public function testSumCart() { empty_cart(); $add_to_cart = array('content_id' => 1, 'qty' => 3, 'price' => 300); $cart_add = update_cart($add_to_cart); $cart_items = get_cart(); $sum = cart_sum(); $this->assertEquals($sum, 900); $this->assertEquals(isset($cart_add['success']), true); $this->assertEquals(!empty($cart_items), true); }
function ajax_modify_quanlity() { if (isset($_POST['productID'])) { $quanlity = $_POST['quanlity']; $productID = $_POST['productID']; //$sl = get_post_meta($productID, 'so_luong', true); $cart = get_cart_in_session(); if (!$cart) { echo 'Thời gian mua giữ giỏ hàng đã hết hoặc cookie đã xóa, vui lòng chọn lại sản phẩm!'; } else { $result = update_cart($cart, $productID, $quanlity); if ($result) { echo number_format($result['subtotal'], 0) . '-' . number_format($result['total'], 0); /// } die; } } }
if ($_SESSION['member'] == "") { header('location:?url=login'); } else { include "./content/chart.php"; } break; case 'check': if ($_SESSION['member'] == "") { header('location:?url=login'); } else { cek_stok(); } break; case 'update_cart': if (@$_GET['token'] == md5(@$_SESSION['member'])) { update_cart(@mysql_real_escape_string($_POST)); } else { echo "Legal Action"; } break; case 'delete_cart': if (@$_GET['token'] == md5(@$_SESSION['member'])) { delete_cart(@mysql_real_escape_string($_GET['id'])); } else { echo "Legal Action"; } break; case 'finish': if (@$_GET['token'] == md5(@$_SESSION['member'])) { finish_shop(is_array($_POST)); } else {
$action = "ok"; } } else { $action = "loginForm"; $errorMsg = _("Usuario o contraseña incorrectos."); } showSkin(basename(__FILE__), $action); } else { if ($_REQUEST['action'] == "register") { if ($_REQUEST['password1'] == $_REQUEST['password2'] && trim($_REQUEST['password1']) != "") { $cart = get_cart(); $user = new User(); $user->email = $_REQUEST['email']; $user->password = $_REQUEST['password1']; $cart->user = $user; update_cart($cart); $referrer = $_REQUEST["referrer"]; redirect(APP_ROOT . "/flows/personalData.php?referrer=" . $referrer); } else { $action = "loginForm"; $errorMsg = _("Passwords no coinciden o son vacíos."); } showSkin(basename(__FILE__), $action); } } } else { $action = "loginForm"; $referrer = get_referer(); if (isset($referrer)) { if ($referrer == "cart.php") { $referrer = "confirmCart.php";
break; case 'product': $id = $_GET['id']; $product = get_product($id); break; case 'cart': break; case 'add_to_cart': $id = $_GET['id']; $add_item = add_to_cart($id); $_SESSION['total_items'] = total_items($_SESSION['cart']); $_SESSION['total_price'] = total_price($_SESSION['cart']); header('Location: index.php?view=product&id=' . $id); break; case 'update_cart': update_cart(); $_SESSION['total_items'] = total_items($_SESSION['cart']); $_SESSION['total_price'] = total_price($_SESSION['cart']); header('Location: index.php?view=cart'); break; case 'admin': break; case 'rings': $val = $_POST['val']; $cat = $_GET['id']; $products = get_cat_products($cat, $val); break; case 'news': $news = news(); break; case 'save_goods':
function remove_from_cart($product_id) { unset($_SESSION['products'][$product_id]); update_cart(); }
/** * Function to Update cart * * @return tempcode The UI */ function update_cart() { $title = get_page_title('SHOPPING'); $p_ids = post_param('product_ids'); $pids = explode(",", $p_ids); $product_to_remove = array(); $product_details = array(); if (count($pids) > 0) { foreach ($pids as $pid) { $qty = post_param_integer('quantity_' . $pid); $object = find_product($pid); if (method_exists($object, 'get_available_quantity')) { $available_qty = $object->get_available_quantity($pid); if (!is_null($available_qty) && $available_qty <= $qty) { $qty = $available_qty; attach_message(do_lang_tempcode('PRODUCT_QUANTITY_CHANGED', strval($pid)), 'warn'); } } $product_details[] = array('product_id' => $pid, 'Quantity' => $qty); $remove = post_param_integer('remove_' . $pid, 0); if ($remove == 1) { $product_to_remove[] = $pid; } } } update_cart($product_details); log_cart_actions('Updated cart'); if (count($product_to_remove) > 0) { remove_from_cart($product_to_remove); } $cart_view = build_url(array('page' => '_SELF', 'type' => 'misc'), '_SELF'); return redirect_screen($title, $cart_view, do_lang_tempcode('CART_UPDATED')); }
} print "</tr>\n"; } if (isset($_SESSION['chart'])) { print "<tr><td><table><tr><td><input type=\"checkbox\" name=\"chart\" value=\"chart\" checked>Draw Charts\n</td></tr><td> " . chart_select() . "</td></tr></table></td>\n"; } else { print "<tr><td><table><tr><td><input type=\"checkbox\" name=\"chart\" value=\"chart\">Draw Charts\n</td></tr><td> " . chart_select() . "</td></tr></table></td>\n"; } print '<td colspan="10"><input name="recalc" value="Update" type="submit"/></td></tr>'; print '<tr><td colspan="10"><input name="delete" value="Delete" type="submit"/></td></tr>'; print '<tr><td colspan="10"><input name="watch" value="Move to Watch list" type="submit"/></td></tr>'; print '<tr><td colspan="10"><input name="buy" value="Buy" type="submit"/></td></tr>'; print '</table>'; print '</form>'; } update_cart('cart', $portfolio); function update_session() { if (isset($_POST['chart'])) { $_SESSION['chart'] = 1; } else { unset($_SESSION['chart']); } if (isset($_POST['chart_period'])) { $_SESSION['chart_period'] = $_POST['chart_period']; } else { unset($_SESSION['chart_period']); } } if (isset($_POST['recalc'])) { update_session();
<?php include 'connection.php'; function update_cart($user, $item, $cost) { $query = @mysql_query("INSERT INTO Orders (User_Name, SKU, Price) \r\n\t\tVALUES ('{$user}', '{$item}', '{$cost}')") or die(@mysql_error()); return_cart(); } function return_cart() { header("Location: cart.php"); } if (isset($_POST['submit'])) { $result = @mysql_query("SELECT * FROM Inventory WHERE SKU = " . $_POST['chosen_product']) or die(@mysql_error()); //Testing purposes only. $user = $_POST['chosen_user']; while ($row = @mysql_fetch_array($result)) { update_cart($user, $row['SKU'], $row['Price']); } exit; } if (isset($_POST['remove_product'])) { $user = $_POST['chosen_user']; $sql = "DELETE FROM `Orders` WHERE `User_Name`='" . $user . "' AND `SKU`='" . $_POST['remove_product'] . "'"; $result = @mysql_query($sql) or die(@mysql_error()); //Testing purposes only. return_cart(); }
<?php session_start(); include 'connection.php'; include 'functions.php'; if (empty($_SESSION['prod_count'])) { $_SESSION['prod_count'] = 0; } if (isset($_POST['add_to_cart_button'])) { addtocart($_POST['product_id'], $_POST['price']); } if (isset($_POST['update'])) { update_cart($_POST['p_count'], $_POST['upd_id'], $_POST['in_cart']); } if (isset($_POST['delete'])) { remove_from_cart($_POST['del_id']); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <title>Test shop</title> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <body> <div class="header">
print "<td><img SRC=\"/cgi-bin/chartstock.php?TickerSymbol={$symb}&TimeRange={$chart_period}&working_date={$pf_working_date}&exch={$pf_exch}&ref_date={$date}&ChartSize=S&Volume=1&VGrid=1&HGrid=1&LogScale=0&ChartType=OHLC&Band=None&avgType1=SMA&movAvg1=10&avgType2=SMA&movAvg2=25&Indicator1=RSI&Indicator2=MACD&Indicator3=WilliamR&Indicator4=TRIX&Button1=Update%20Chart\" ALIGN=\"bottom\" BORDER=\"0\"></td>"; } print "</tr>\n"; } if (isset($_SESSION['chart'])) { print "<tr><td><table><tr><td><input type=\"checkbox\" name=\"chart\" value=\"chart\" checked>Draw Charts\n</td></tr><td> " . chart_select() . "</td></tr></table></td>\n"; } else { print "<tr><td><table><tr><td><input type=\"checkbox\" name=\"chart\" value=\"chart\">Draw Charts\n</td></tr><td> " . chart_select() . "</td></tr></table></td>\n"; } print '<td colspan="10"><input name="recalc" value="Update" type="submit"/></td></tr>'; print '<tr><td colspan="10"><input name="delete" value="Delete" type="submit"/></td></tr>'; print '<tr><td colspan="10"><input name="cart" value="Move to Shopping cart" type="submit"/></td></tr>'; print '</table>'; print '</form>'; } update_cart('watch', $portfolio); function update_session() { if (isset($_POST['chart'])) { $_SESSION['chart'] = 1; } else { unset($_SESSION['chart']); } if (isset($_POST['chart_period'])) { $_SESSION['chart_period'] = $_POST['chart_period']; } else { unset($_SESSION['chart_period']); } } if (isset($_POST['recalc'])) { update_session();
<?php require_once 'cart_functions.php'; //add item to cart if (isset($_POST['pid']) && isset($_POST['qty'])) { $pid = $_POST['pid']; $qty = $_POST['qty']; if (isset($_POST['slct'])) { $selection = $_POST['slct']; } else { $selection = false; } } if (isset($pid)) { $item_id = check_product_in_cart($pid, false, $selection); if ($item_id) { update_cart($item_id, $qty); } else { add_to_cart($pid, $selection); } //adds one to the cart } $count = count_items(); echo json_encode(array("count" => "{$count}"));
$quantarr = $_POST['quantArr']; //this is an array of all of the quantities in the cart sent by the form } if (isset($pID)) { $cID = check_product_in_cart($pID); } if ($cID && $qnty != 0) { update_cart($cID, $qnty); //$qnty is how many to add on to what is already in the cart } else { if ($qnty != 0 && isset($pID)) { add_to_cart($pID); //adds one to the cart } else { if ($qnty == 0 && $cID) { update_cart($cID, $qnty); } } } } $count = count_items(); $count_string = $count == 1 ? $count . ' item' : $count . ' items'; $shipping = 350; /**********************************************************/ /* Start displaying the table in which the cart items sit */ /**********************************************************/ $table = ' <div id="cart-table"><table class ="cart-list"> <tr class="table-header"> <th>Product Name</th> <th>Quantity</th> <th>Price</th>
function changeStatus($status, $tpvData = null, $sendMail = true) { global $ddbb, $npshop; // status changes history if ($this->orderStatus != $status) { $this->orderStatus = $status; if ($this->statusHistory == null || trim($this->statusHistory == "")) { $this->statusHistory = ""; } else { $this->statusHistory .= " @ "; } $this->statusHistory .= "[" . date("d/m/Y H:i:s") . " : " . $this->orderStatus . "]"; } if ($tpvData != null && trim($tpvData) != "") { $tpvData = "[" . trim($tpvData) . "]"; if (isset($this->tpvData) && $this->tpvData != null) { $tpvData = $this->tpvData . " @ " . $tpvData; } $this->tpvData = $tpvData; } /*$sql = "UPDATE ".$ddbb->getTable("Cart"). " SET ".$ddbb->getMapping('Cart','orderStatus')."=".NP_DDBB::encodeSQLValue($status, $ddbb->getType('Cart','orderStatus')).", ". $ddbb->getMapping('Cart','statusHistory')."=".NP_DDBB::encodeSQLValue($this->statusHistory, $ddbb->getType('Cart','statusHistory')).", ". $ddbb->getMapping('Cart','date')."=".NP_DDBB::encodeSQLValue($this->date, $ddbb->getType('Cart','date')); if ($tpvData != null) { $this->tpvData = $tpvData; update_cart($this); $sql.= ", ".$ddbb->getMapping('Cart','tpvData')."=".NP_DDBB::encodeSQLValue($tpvData, $ddbb->getType('Cart','tpvData')); } $sql.= " WHERE ".$ddbb->getMapping('Cart','orderId')."=".NP_DDBB::encodeSQLValue($this->orderId, $ddbb->getType('Cart','orderId')); $ddbb->executeInsertUpdateQuery($sql);*/ $ddbb->updateObject($this); if ($status == $npshop['constants']['ORDER_STATUS']['PAYMENT_OK'] || $status == $npshop["constants"]["ORDER_STATUS"]["PAYMENT_TRANSFER"] || $status == $npshop["constants"]["ORDER_STATUS"]["PENDING_SENT_ONDELIVERY"]) { foreach ($this->items as $item) { $item->addToStock(-1 * $item->quantity); } } update_cart($this); if ($sendMail) { $user = new User(); $user->_dbLoad($this->user->id); $statusKey = array_search($status, $npshop['constants']['ORDER_STATUS']); $mailContent = $this->_buildMail(); if ($statusKey == "PAYMENT_OK" || $statusKey == "PAYMENT_TRANSFER" || $statusKey == "PENDING_SENT_ONDELIVERY") { sendHTMLMail($npshop['constants']['EMAIL_FROM'], $user->email, $npshop['constants']['EMAIL_SUBJECT'] . $this->orderId, $mailContent); sendHTMLMail($npshop['constants']['EMAIL_FROM'], $npshop['constants']['EMAIL_NOTIFICATION'], $npshop['constants']['EMAIL_SUBJECT'] . $this->orderId, $mailContent); } sendHTMLMail($npshop['constants']['EMAIL_FROM'], $npshop['constants']['EMAIL_DEBUG'], "DEBUG (DavidBenavente): " . $npshop['constants']['EMAIL_SUBJECT'] . $this->orderId, $mailContent); } }