/** * Recupera o carrinho de compras. * @return Cart */ public function cart() { if ( $this->cart == null ) { $this->cart = Cart::getInstance(); } return $this->cart; }
public function action_add() { $goods_id = $this->getQuery('goods_id'); $cart = Cart::getInstance(); $cart->add($goods_id, 1); $this->request->redirect('/cart/list'); $this->auto_render = false; }
function buy() { if (isset($_POST['id']) & isset($_POST['count']) & isset($_POST['cost']) & Cart::getInstance()->IsCookie($_POST['id'])) { try { //header("Location: ".$_SERVER['PHP_SELF']); //решаем проблему повторной отправки данных формы $dbh = new PDO('mysql:host=localhost;dbname=iba', USER, PASS); $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $zapros = 'INSERT INTO purchases (id, id_good, id_user, data, count, cost) VALUES (null, :id_good, :id_user, :data, :count, :cost)'; $sth = $dbh->prepare($zapros); $data = array('id_good' => $_POST['id'], 'id_user' => $_SESSION['id_user'], 'data' => date("Y.n.j"), 'count' => $_POST['count'], 'cost' => $_POST['cost']); $sth->execute($data); $result = $dbh->lastInsertId(); $dbh = null; Cart::getInstance()->deleteCookie($_POST['id']); // или call_user_func(array('Cart', 'DeleteCookie')); return $result; } catch (PDOException $e) { echo "Error occurred! " . $e->getMessage(); } } }
$GLOBALS['seo']->getItem($_GET['seo_path']); } //Initialize SSL $GLOBALS['ssl'] = SSL::getInstance(); //Initialize GUI $GLOBALS['gui'] = GUI::getInstance(); //Initialize Taxes $GLOBALS['tax'] = Tax::getInstance(); //Initialize catalogue $GLOBALS['catalogue'] = Catalogue::getInstance(); //Initialize cubecart $GLOBALS['cubecart'] = Cubecart::getInstance(); //Initialize user $GLOBALS['user'] = User::getInstance(); //Initialize cart $GLOBALS['cart'] = Cart::getInstance(); // Set store timezone - default to UTC date_default_timezone_set($GLOBALS['config']->get('config', 'time_zone') ? $GLOBALS['config']->get('config', 'time_zone') : 'UTC'); if ($GLOBALS['config']->get('config', 'recaptcha') && !$GLOBALS['session']->get('confirmed', 'recaptcha')) { $recaptcha['error'] = null; $recaptcha['confirmed'] = false; if ($GLOBALS['config']->get('config', 'recaptcha') == 2 && isset($_POST['g-recaptcha-response'])) { if (empty($_POST['g-recaptcha-response'])) { $recaptcha['error'] = $GLOBALS['language']->form['verify_human_fail']; } else { $g_data = array('secret' => $GLOBALS['config']->get('config', 'recaptcha_secret_key'), 'response' => $_POST['g-recaptcha-response'], 'remoteip' => get_ip_address()); $json = file_get_contents('https://www.google.com/recaptcha/api/siteverify?' . http_build_query($g_data)); $g_result = json_decode($json); if ($g_result->success) { $recaptcha['confirmed'] = true; } else {
include_once "../models/goods.php"; include_once "../views/functions.php"; $GLOBALS['title'] = "Корзина"; include_once "header.php"; ?> <h2>Корзина</h2> <?php if (!isset($_SESSION['id_user'])) { echo "<p>*Требуется войти, чтобы совершить покупку</p>"; } ?> <div> <?php $cart_goods = Cart::getInstance()->getAllCookies(); if (!empty($cart_goods)) { echo "<a href='http://localhost/iba/cart/removeAll'>Очистить корзину</a><br><br>"; $good = new Goods(); foreach ($cart_goods as $key => $value) { $good->getGood($key); echo "<form action='" . PATHSITE . "/purchase/buy' method='post' oninput='cost.value=(price.valueAsNumber * count.valueAsNumber)'>"; echo "<a href='" . PATHSITE . "/good/" . $key . "'>" . $good->name . "</a> "; echo "<input name='id' type='number' hidden='true' value='{$key}'>"; echo "<input name='count' type='number' min='1' step='1' required='true' value={$value}> "; echo "<input name='price' type='number' hidden='true' value={$good->price}>"; echo "<input name='cost' type='number' min='1' readonly='true' required='true' value={$good->price}> "; if (isset($_SESSION['id_user'])) { echo "<input name='submitButton' type='submit' value='Купить'> "; } echo "<a href='" . PATHSITE . "/cart/remove?id={$key}'>Удалить</a><br>";
{ if (isset($_COOKIE['goods'])) { foreach ($_COOKIE['goods'] as $id => $value) { setcookie("goods[{$id}]", "", time() - 1, "/"); } } } function IsCookie($id) { if (isset($_COOKIE['goods'][$id])) { return TRUE; } else { return FALSE; } } } switch ($action) { case "add": Cart::getInstance()->putCookie(); break; case "remove": header("Location:" . PATHSITE . "/cart"); Cart::getInstance()->deleteCookie($_GET['id']); break; case "removeAll": header("Location:" . PATHSITE . "/cart"); Cart::getInstance()->deleteAllCookies(); break; default: break; }