Ejemplo n.º 1
0
<?php

require_once '../../functions.php';
$data = $_POST;
$resp = new Ajax_Response($data['action'], true);
if (is_array($data) && !empty($data)) {
    $order_total = $data['order_total'];
    $user = new User($_SESSION['current_user']);
    $cart = new Cart($user->user_id);
    $order = new Order();
    $order_id = $order->create_order_record($user, $order_total);
    if (is_int($order_id)) {
        $result = $order->create_order_product_records($order_id, $data['cart_product']);
        if ($result) {
            //$cart->destroy_cart( $user );
            $resp->set_status(true);
            $resp->set_message('Thanks for buying ' . count($data['cart_product']) . ' items for ' . Text_Helper::format_string_as_price($data['order_total']) . ' ');
        } else {
            $resp->set_message('Could not create order product records. Whoops');
        }
    } else {
        $resp->set_message('Could not create order record. Try again.');
    }
} else {
    $resp->set_message('Could not process Order. Sorry.');
}
echo $resp->encode_response();
die;
Ejemplo n.º 2
0
<?php

require_once '../../functions.php';
$data = $_POST;
$resp = new Ajax_Response($data['action'], true);
if (!empty($data) && is_array($data)) {
    // $data['product_type']
    $ingredient_type = new Ingredient_Type($data['type']);
    $ingredient = new Ingredient();
    $options = $ingredient->get_ingredients_by_type($ingredient_type->ingredient_type_id);
    if (is_array($options) && !empty($options)) {
        $data['type'] = 'select';
        $data['name'] = 'ingredients[' . $ingredient_type->ingredient_type_slug . ']';
        $data['val'] = $options;
        $data['data_attr'] = '';
        $data['placeholder'] = 'Select an Ice Cream Flavor';
        $resp->set_status(true);
        $resp->set_data(array('field' => Form_Helper::build_field($data)));
    } else {
        $resp->set_message('Could not load field. Sorry, <a href="#" data-ajax-get data-action="add_field" data-extra-data="ice_cream">try again</a>?');
    }
}
echo $resp->encode_response();
die;
Ejemplo n.º 3
0
<?php

require_once '../../functions.php';
$data = $_POST;
$resp = new Ajax_Response($data['action'], true);
if (!empty($data) && is_array($data)) {
    $type = new Product_Type($data['product_type']);
    if ($type instanceof Product_Type) {
        $data['type_name'] = $type->product_type_slug;
        $data['action'] = 'add_to_cart';
        $data['fields'] = $type->get_product_form_fields($type);
        $resp->set_status(true);
        $resp->set_data(array('new_form' => Template_Helper::render_template(__TEMPLATE_PATH__, 'product_choice_form', $data)));
    } else {
        $resp->set_message('Could not load fields for ' . ucfirst($type_name) . '. Please try again.');
    }
}
echo $resp->encode_response();
die;
Ejemplo n.º 4
0
<?php

require_once '../../functions.php';
$data = $_POST;
$resp = new Ajax_Response($data['action'], true);
$flag = true;
global $ssdb;
if (is_array($data) && !empty($data)) {
    if ($data['honey_pot'] == null) {
        $user_name = htmlspecialchars(trim($data['user_name']));
        $password = htmlspecialchars(trim($data['password']));
        $pass_again = htmlspecialchars(trim($data['pass_again']));
        $user = new User($user_name);
        if ($user instanceof User) {
            $flag == false;
            $resp->set_message('User is already registered. <a href="/">Login?</a>');
        }
        if ($password == $pass_again && $flag) {
            $hashed_pass = password_hash($password, PASSWORD_BCRYPT);
            $stmt = $ssdb->prepare('INSERT INTO ' . TABLE_PREFIX . 'users ( user_name, user_pass ) VALUES ( :user_name, :user_password )');
            $stmt->bindParam(':user_name', $user_name, PDO::PARAM_STR);
            $stmt->bindParam(':user_password', $hashed_pass, PDO::PARAM_STR);
            if ($stmt->execute()) {
                $resp->set_status(true);
                $resp->set_message('You have successfully registered! <a href="/">Login?</a>');
            } else {
                $resp->set_message('Could not create user account. Try Again.');
            }
        } else {
            $resp->set_message('Passwords don\'t match. Try again.');
        }
Ejemplo n.º 5
0
<?php

require_once '../../functions.php';
error_reporting(0);
ini_set('display_errors', 'Off');
session_start();
$data = $_POST;
$resp = new Ajax_Response($data['action'], true);
if (is_array($data) && !empty($data)) {
    $user = new User($_SESSION['current_user']);
    $cart = new Cart();
    if (is_int($user->user_id)) {
        $product_type = new Product_Type((int) $data['product_type']);
        $product = new Product();
        $new_product_id = $product->create_product_record($product_type);
        if (is_int($new_product_id)) {
            // CREATE CONNECTIONS BETWEEN INGREDIENTS AND PRODUCT
            $product->create_product_ingredient_records($new_product_id, $data['ingredients']);
            $result = $cart->create_cart_product_record($user->user_id, $new_product_id);
            if (is_int($result)) {
                $resp->set_status(true);
                $resp->set_message('You successfully ordered a ' . $product_type->product_type_name . '!');
            } else {
                $resp->set_message('Could Not Save ' . $product_type->product_type_name . '. Please Try Again.');
            }
        }
    } else {
        $resp->set_message('Could not create cart session. Please try again.');
    }
} else {
    $resp->set_message('Couldn\'t find any data! <a href="/">Go back?</a>');
Ejemplo n.º 6
0
<?php

require_once '../../functions.php';
session_start();
$data = $_POST;
$resp = new Ajax_Response($data['action'], true);
if (is_array($data) && !empty($data)) {
    $coupon_code = htmlspecialchars(trim($data['coupon_code']));
    $user = new User($_SESSION['current_user']);
    $cart = new Cart($user->user_id);
    $coupon = new Coupon($coupon_code);
    if ($coupon->coupon_id != null) {
        $total = $cart->get_cart_total();
        $discounted_total = (double) $total - (double) $coupon->coupon_discount;
        $resp->set_status(true);
        $resp->set_data(array('discount_total' => $discounted_total, 'original_total' => $total, 'discount_html' => '<h1>' . Text_Helper::format_string_as_price($discounted_total) . '</h1>
                                                <small>' . Text_Helper::format_string_as_price($coupon->coupon_discount) . ' off</small>'));
        $resp->set_message(ucfirst($coupon_code) . ' successfully applied!');
    } else {
        $resp->set_message(ucfirst($coupon_code) . ' is not a valid coupon. Sorry.');
    }
} else {
    $resp->set_message('No Coupon code received. Try Again.');
}
echo $resp->encode_response();
die;
Ejemplo n.º 7
0
<?php

require_once '../../functions.php';
$data = $_POST;
$resp = new Ajax_Response($data['action'], true);
global $ssdb;
if (is_array($data) && !empty($data)) {
    if ($data['honey_pot'] == null) {
        $user_name = htmlspecialchars(trim($data['user_name']));
        $password = htmlspecialchars(trim($data['password']));
        if ($user_name != null) {
            $user = new User($user_name);
            $passwords_match = password_verify($password, $user->user_pass);
            if ($passwords_match) {
                session_start();
                $_SESSION['current_user'] = $user->user_name;
                $resp->set_status(true);
                $resp->set_message('Successfully logged in! Redirecting you now...');
            } else {
                $resp->set_message('Could not log you in with these credentials. Try again.');
            }
        } else {
            $resp->set_message('Please enter a valid username.');
        }
    } else {
        $resp->set_message('NO BOTS!!!');
    }
} else {
    $resp->set_message();
}
echo $resp->encode_response();