Esempio n. 1
0
 public function actionAdd($serviceid)
 {
     if ($serviceid) {
         echo Cart::addToCart($serviceid);
     }
     return true;
 }
Esempio n. 2
0
 function addToCart()
 {
     $result = $this->Cart->Product->findById($this->p);
     if (empty($result)) {
         $this->Session->setFlash('This product was not found!');
         $this->redirect(array('action' => 'index'));
     } else {
         if ($result['Product']['pd_qty'] <= 0) {
             $this->Session->setFlash('The product you requested is out of stock!');
             $this->redirect(array('action' => 'index'));
         }
     }
     //ce je user loginan se uporablja userov ID
     if ($this->Auth->user()) {
         $sessionData = $this->Cart->getCart($this->p, $this->sid, $this->Session->read('Auth.User.id'));
         if (empty($sessionData)) {
             $this->Cart->addToCart($this->p, $this->sid, $this->Session->read('Auth.User.id'));
             $this->Session->setFlash('Product added to cart! -> through user ID / inserted');
         } else {
             $this->Cart->updateCart($this->p, $this->sid, $this->Session->read('Auth.User.id'));
             $this->Session->setFlash('Product added to cart! -> through session ID / updated');
         }
         //ce user ni prijavljen se uporablja sejni ID
     } else {
         $sessionData = $this->Cart->getCart($this->p, $this->sid);
         if (empty($sessionData)) {
             $this->Cart->addToCart($this->p, $this->sid);
             $this->Session->setFlash('Product added to cart! -> through session ID / inserted');
         } else {
             $this->Cart->updateCart($this->p, $this->sid);
             $this->Session->setFlash('Product added to cart! -> through session ID / updated');
         }
     }
     $this->Cart->cleanUp();
     $this->redirect(array('controller' => 'carts', 'action' => "index/c:{$this->c}/p:{$this->p}"));
 }
Esempio n. 3
0
<?php

require_once 'includes/config.php';
$female = "SELECT itemId FROM items WHERE gender='f'";
$resultf = $db->query($female);
while ($rowf = $resultf->fetch()) {
    $id = $rowf['itemId'];
    $sqlItem = "SELECT * FROM items WHERE itemId={$id}";
    $item = $db->query($sqlItem);
    $i = $item->fetch();
    Cart::addToCart($i['name'], $i['price'], $i['itemID'], $i['type'], 3);
}
Esempio n. 4
0
 public function login()
 {
     $username = $_POST['username'];
     $password = $_POST['password'];
     $user = new User($username, $password);
     /* Login call to user object - checking credentials */
     $boolean = $user->login('account');
     if ($boolean) {
         $database = new Database('localhost', 'pdo_ret', 'root', '');
         $sql = "select * from account natural join shipping_address\n            natural join address where username='******';";
         $result = $database->query($sql);
         $result = $result[0];
         $address = new Address($result[7], $result[8], $result[9], $result[10]);
         $account = new Account($username, $result[2], $password, (double) $result[4], $result[5], $result[6], $address);
         /* Check for existing payment method */
         $sql = "select * from account natural join account_payment \n            natural join address where username='******';";
         $result = $database->query($sql);
         if (count($result) > 0) {
             $result = $result[0];
             $paymentID = $result[6];
             $methods = array('bank_account', 'credit_card', 'paypal');
             $ids = array('acc_id', 'cc_number', 'email');
             for ($i = 0; $i < count($methods); $i++) {
                 $sql = "select * from " . $methods[$i] . " where " . $ids[$i] . "='{$paymentID}';";
                 $result = $database->query($sql);
                 if (count($result) > 0) {
                     $result = $result[0];
                     switch ($methods[$i]) {
                         case 'bank_account':
                             $sql = "select * from bank_account natural join ba_billing_address \n                                natural join address where acc_number='{$paymentID}';";
                             $result = $database->query($sql);
                             $result = $result[0];
                             $street = $result[5];
                             $city = $result[6];
                             $parish = $result[7];
                             $postal = $result[8];
                             $address = new Address($street, $city, $parish, $postal);
                             $payment = new BankAccount($result[4], $result[2], $result[3], $address);
                             $account->setPaymentMethod($payment);
                             $_SESSION['payment'] = 'yes';
                             $_SESSION['paymenttype'] = 'ba';
                             break;
                         case 'credit_card':
                             $sql = "select * from credit_card natural join cc_billing_address \n                                natural join address where cc_number='{$paymentID}';";
                             $result = $database->query($sql);
                             $result = $result[0];
                             $ccnumber = $result[1];
                             $cardholder = $result[2];
                             $street = $result[3];
                             $city = $result[4];
                             $parish = $result[5];
                             $postal = $result[6];
                             $address = new Address($street, $city, $parish, $postal);
                             $payment = new CreditCard($cardholder, $ccnumber, '', '', $address);
                             $account->setPaymentMethod($payment);
                             $_SESSION['payment'] = 'yes';
                             $_SESSION['paymenttype'] = 'cc';
                             break;
                         case 'paypal':
                             $sql = "select * from paypal where email='{$paymentID}';";
                             $result = $database->query($sql);
                             $result = $result[0];
                             $email = $result[0];
                             $password = $result[1];
                             $payment = new PayPal($email, $password);
                             $account->setPaymentMethod($payment);
                             $_SESSION['payment'] = 'yes';
                             $_SESSION['paymenttype'] = 'pp';
                             break;
                     }
                     break;
                 }
             }
         }
         /* Get cart and products in cart */
         $sql = "select cart_id from account_cart where username='******';";
         $result = $database->query($sql);
         $result = $result[0];
         $cartId = $result[0];
         $cart = new Cart();
         $cart->setCartId($cartId);
         $sql = "select * from cart_product where cart_id='{$cartId}';";
         $result = $database->query($sql);
         foreach ($result as $row) {
             $productId = $row[1];
             $quantity = $row[2];
             $sql = "select * from product where product_id='{$productId}';";
             $results = $database->query($sql);
             $results = $results[0];
             $name = $results[1];
             $price = $results[3];
             $product = new Product($productId, $name, $price);
             $cart->addToCart($product, $quantity);
         }
         /* Get orders */
         $products = array();
         $sql = "select order_id from account_order where username='******';";
         $result = $database->query($sql);
         foreach ($result as $row) {
             $orderId = $row[0];
             $sql = "select * from orders natural join order_product where order_id='{$orderId}';";
             $results = $database->query($sql);
             $row = $results[0];
             $orderId = $row[0];
             $orderDate = $row[1];
             $deliveryDate = $row[2];
             $orderStatus = $row[3];
             $orderTotal = $row[4];
             foreach ($results as $products_row) {
                 $product = new Product($products_row[5], $products_row[6], $products_row[8]);
                 $product->setQuantity($products_row[7]);
                 array_push($products, $product);
             }
             $order = new Order($orderTotal, $products);
             $order->setOrderId($orderId);
             $order->setOrderDate($orderDate);
             $order->setDeliveryDate($deliveryDate);
             $order->setOrderStatus($orderStatus);
             $account->updateOrders($order);
         }
         $account->setCart($cart);
         $_SESSION['account'] = $account;
         echo '<script>window.location.href = "?controller=pages&action=index";</script>';
     } else {
         /* Login call to user object - checking credentials */
         $boolean = $user->login('admin');
         if ($boolean) {
             $admin = new Admin($username, $password);
             $_SESSION['admin'] = $admin;
             $_SESSION['username'] = $admin->getUsername();
             echo '<script>window.location.href = "?controller=pages&action=index";</script>';
         } else {
             $_SESSION['incorrect'] = 'yes';
             echo '<script>window.location.href = "?controller=pages&action=login";</script>';
         }
     }
 }
Esempio n. 5
0
<?php

//include config
require_once 'includes/config.php';
if (!$user->is_logged_in()) {
    header('Location: index.php');
}
//the cart session
if (isset($_GET['itm']) && isset($_GET['quan'])) {
    $item = $_GET['itm'];
    $quantity = $_GET['quan'];
    $sql = "SELECT * FROM items WHERE itemID={$item}";
    $result = $db->query($sql);
    $i = $result->fetch();
    Cart::addToCart($i['name'], $i['price'], $i['itemID'], $i['type'], $quantity, $i['url']);
}
//sidebar
$female = "SELECT DISTINCT type FROM items WHERE gender='f'";
$resultf = $db->query($female);
$male = "SELECT DISTINCT type FROM items WHERE gender='m'";
$resultm = $db->query($male);
?>

<!DOCTYPE html>
<html lang="en">

<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">