Ejemplo n.º 1
0
function product($idProduct = "")
{
    require_once '../../Model/ProductClass.php';
    global $viewLogin;
    if (!$viewLogin) {
        header('Location: ../Front/controller.php?f=index');
    }
    global $navegador;
    global $navegadorAdmin;
    $navegador = $navegadorAdmin;
    global $connection;
    $product = new ProductClass($connection);
    //    var_dump($_POST);
    if ($idProduct != '') {
        $product->fetch($idProduct);
        if ($product->imgs == '') {
            $product->imgs = array('not-found.png');
        }
        if (isset($_POST['button']) && $_POST['button'] == 'Save') {
            if (!is_numeric($_POST['price'])) {
                echo '<script>alert("Error : price It is not a numeric value")</script>';
            } else {
                $product->name = $_POST['name'];
                $product->description = $_POST['description'];
                $product->longDescription = $_POST['longDescription'];
                $product->price = $_POST['price'];
                $product->category = $_POST['category'];
                $product->insertProduct();
            }
        }
        if (isset($_POST['button']) && $_POST['button'] == 'Delete') {
            $product->deleteProduct();
            header('Location: ../Back/controller.php?f=productList');
        }
    } else {
        if (isset($_POST['button']) && $_POST['button'] == 'Save') {
            $product = new ProductClass($connection, $_POST['name'], $_POST['description'], $_POST['longDescription'], $_POST['price'], '', $_POST['category']);
            // cargarlo de categorias
            $idLastInsert = $product->insertProduct();
            //            var_dump($idLastInsert);
            if ($idLastInsert != 0) {
                product($idLastInsert);
            }
            //            $product->insertProduct();
        }
    }
    // cargarlo de categorias
    $options = array(array('value' => '1', 'string' => 'Book'), array('value' => '2', 'string' => 'Music'));
    $titulo = $product->name;
    $description = $product->description;
    $palabrasClaves = 'palabrasClaves';
    require_once '../../View/Back/product.php';
}
Ejemplo n.º 2
0
function cart()
{
    require_once '../../Model/ProductClass.php';
    global $navegador;
    global $connection;
    global $user;
    $titulo = 'David\'s SHOP -Cart';
    $description = 'description';
    $palabrasClaves = 'palabrasClaves';
    $totalPrice = 0;
    if (isset($_COOKIE['Products'])) {
        if ($_COOKIE['Products'] != '[]' || $_COOKIE['Products'] != NULL) {
            $productsCart = $_COOKIE['Products'];
            $productsCart = str_replace("[", "", $productsCart);
            $productsCart = str_replace("]", "", $productsCart);
            if ($productsCart != '') {
                $productsCart = explode(",", $productsCart);
                foreach ($productsCart as $key => $value) {
                    $product = new ProductClass($connection);
                    $product->fetch($value);
                    if (!isset($product->imgs[0]['name'])) {
                        $img = 'not-found.png';
                    } else {
                        $img = $product->imgs[0]['name'];
                    }
                    $listProductsCart[] = array('name' => $product->name, 'description' => $product->description, 'price' => $product->price, 'img' => $img, 'id' => $product->id);
                    $totalPrice = floatval($product->price) + $totalPrice;
                }
            }
        }
    }
    require_once '../../View/Front/cart.php';
}
Ejemplo n.º 3
0
<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
require_once '../app/config.php';
require_once 'ProductClass.php';
require_once '../app/connection/Connexion.php';
$connection = new Connexion($dbName, $host, $user, $pass);
//var_dump($_POST);
$product = new ProductClass($connection);
$product->fetch($_POST['id']);
echo json_encode($product->imgs);