<?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;
<?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;
<?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;