function test_function()
{
    $return = $_POST;
    add_to_cart(3235, 1);
    //Do what you need to do with the info. The following are some examples.
    //if ($return["favorite_beverage"] == ""){
    //  $return["favorite_beverage"] = "Coke";
    //}
    //$return["favorite_restaurant"] = "McDonald's";
    $return["json"] = json_encode($return);
    echo json_encode($return);
}
Exemple #2
0
 /**
  * Add an item to the cart (ajax)
  * @return The number of items in the user's cart (print whith JSON)
  */
 public function addAction()
 {
     $this->_helper->viewRenderer->setNoRender(TRUE);
     $dbname = $this->getParam('dbname');
     $item_id = $this->getParam('id');
     $data['result'] = false;
     if ($dbname && $item_id) {
         $data['result'] = add_to_cart($dbname, $item_id);
     }
     $this->getResponse()->setHeader('Content-Type', 'application/json');
     echo json_encode($data);
     // Print JSON like : {"result":3}, where 3 is the number of items in the cart
 }
Exemple #3
0
             $_GET["item_id"] = $item_id;
         }
     }
     $accessory_id = get_param("accessory_id" . $prefix);
     $sc_item_id = $accessory_id ? $accessory_id : $item_id;
     $sc_price = get_param("price" . $prefix);
     $sc_quantity = get_param("quantity" . $prefix);
     $type_param_value = get_param("type");
     if ($type_param_value) {
         $type = $type_param_value;
     } else {
         $type = "";
     }
     /* start of adding item to the cart */
     //$item_added = add_to_cart($sc_item_id, $sc_price, $sc_quantity, $type, $cart, $new_cart_id, $second_page_options, $sc_errors, $sc_message);
     $item_added = add_to_cart($sc_item_id, $sc_price, $sc_quantity, $type, $cart, $new_cart_id, $second_page_options, $sc_errors, $sc_message);
     /* end of adding item to the cart */
     // check if any coupons can be added or removed
     check_coupons();
     // check for next prefix
     $prefix = "";
     $next_prefix = $total_items + 1;
     foreach ($prefix_params as $param_name) {
         $param_value = get_param($param_name . $next_prefix);
         if (strlen($param_value)) {
             $prefix = $next_prefix;
             break;
         }
     }
 } while ($prefix);
 if ($item_added && $cart != "SHIPPING") {
    $productId = $productId;
    $_SESSION['out_cart'][$productId]['productId'] = $productId;
    $_SESSION['out_cart'][$productId]['quantity'] = $quantity;
    ob_clean();
    $url = "http://" . $_SERVER['HTTP_HOST'] . "/cart02/cart.php";
    header("Location: " . $url) or die("Didn't aa work");
}
// This bit calls the above function.
if (isset($_GET['prod_name']) && $_GET['prod_name'] != 1) {
    $name = $_GET['prod_name'];
    $productId = $_GET['item'];
    $quantity = $_GET['quantity'];
    $cart = $_SESSION['cart'];
    if ($_SESSION['sign_in'] == 1) {
        ob_clean();
        add_to_cart($productId, $quantity);
        $url = "http://" . $_SERVER['HTTP_HOST'] . "/cart02/cart.php";
        header("Location: " . $url) or die("Didn't work");
    } else {
        ob_clean();
        $url = "http://" . $_SERVER['HTTP_HOST'] . "/cart02/cart.php?signed=0";
        header("Location: " . $url) or die("Didn't work");
    }
}
function remove_from_cart($product)
{
    $item = $_POST['remove'];
    unset($_SESSION['out_cart'][$item]);
    $url = "http://" . $_SERVER['HTTP_HOST'] . "/cart02/cart.php?checkout=1";
    header("Location: " . $url) or die("Didn't work");
}
Exemple #5
0
     $slide = slides();
     break;
 case 'earings':
     $val = $_POST['val'];
     $cat = $_GET['id'];
     $products = get_cat_products($cat, $val);
     break;
 case 'product':
     $id = $_GET['id'];
     $product = get_product($id);
     break;
 case 'cart':
     break;
 case 'add_to_cart':
     $id = $_GET['id'];
     $add_item = add_to_cart($id);
     $_SESSION['total_items'] = total_items($_SESSION['cart']);
     $_SESSION['total_price'] = total_price($_SESSION['cart']);
     header('Location: index.php?view=product&id=' . $id);
     break;
 case 'update_cart':
     update_cart();
     $_SESSION['total_items'] = total_items($_SESSION['cart']);
     $_SESSION['total_price'] = total_price($_SESSION['cart']);
     header('Location: index.php?view=cart');
     break;
 case 'admin':
     break;
 case 'rings':
     $val = $_POST['val'];
     $cat = $_GET['id'];
Exemple #6
0
}
if (!isset($_SESSION["cart"])) {
    $_SESSION["cart"] = array();
    $_SESSION["cart"]["order_total"] = 0;
    $_SESSION["cart"]["products"] = array();
}
/**
 * Action handler
 */
if (isset($_GET["action"])) {
    $action = $_GET["action"];
    if ($action == "add") {
        if (isset($_GET["username"]) && isset($_GET["price"])) {
            $username = $_GET["username"];
            $price = $_GET["price"];
            add_to_cart($username, $price, $token);
            update_order_total();
        } else {
            echo json_encode(array("message" => "Error: missing username parameter."));
        }
    } else {
        if ($action == "remove") {
            if (isset($_GET["username"])) {
                remove_from_cart($_GET["username"]);
                update_order_total();
            } else {
                echo json_encode(array("message" => "Error: missing username parameter."));
            }
        } else {
            if ($action == "update") {
                if (isset($_GET["username"]) && isset($_GET["hours"])) {
Exemple #7
0
 /**
  * Function to add item to cart.
  *
  * @return tempcode		The UI
  */
 function add_item_to_cart()
 {
     if (is_guest()) {
         require_code('users_inactive_occasionals');
         set_session_id(get_session_id(), true);
         // Persist guest sessions longer
     }
     $title = get_page_title('SHOPPING');
     $product_details = get_product_details();
     add_to_cart($product_details);
     log_cart_actions('Added to cart');
     $cart_view = build_url(array('page' => '_SELF', 'type' => 'misc'), '_SELF');
     return redirect_screen($title, $cart_view, do_lang_tempcode('SUCCESS'));
 }
Exemple #8
0
                }
                $key = substr($k, 5, strlen($k));
                $attributes .= '[' . $key . ': ' . $v . '], ';
                unset($params[$k]);
            }
        }
    }
    if ($wrong_posting) {
        $attributes = '1';
    } else {
        $attributes = substr($attributes, 0, strLen($attributes) - 2);
        //this will eat the last ', '
    }
    $params['attributes'] = $attributes;
    if (isset($params['cart'])) {
        add_to_cart($app, $db, $params);
    } elseif (isset($params['wishlist'])) {
        add_to_wish_list($app, $db, $params);
    }
});
$app->get('/shop/checkout', $require_ssl, function () use($app, $db) {
    $app->view()->set_template('layouts/basic.php');
    $app->render('shop/checkout.php', array('page_title' => 'Checkout Options'));
});
$app->get('/shop/cccheckout', $require_ssl, function () use($app, $db) {
    $flash = $app->view()->getData('flash');
    if (!isset($flash['data'])) {
        $user = \Data\UserRepository::get_user_by_id($db, $_SESSION['user_id']);
        if ($user) {
            \Helpers\User::copy_user_to_flash($user);
        }
Exemple #9
0
<?php

session_start();
include $_SERVER['DOCUMENT_ROOT'] . '/cart.php';
add_to_cart($_POST['id']);
Exemple #10
0
    update_session();
} elseif (isset($_POST['delete'])) {
    update_session();
    if (isset($_POST['mark'])) {
        $marked = $_POST['mark'];
        foreach ($marked as $symb) {
            del_from_cart('cart', $symb);
        }
    }
} elseif (isset($_POST['watch'])) {
    update_session();
    if (isset($_POST['mark'])) {
        $marked = $_POST['mark'];
        foreach ($marked as $symb) {
            if (!is_in_cart('watch', $symb)) {
                if (add_to_cart('watch', $symb, $_POST["comment_{$symb}"], $_POST["volume_{$symb}"])) {
                    del_from_cart('cart', $symb);
                }
            }
        }
    }
} elseif (isset($_POST['buy'])) {
    update_session();
    if (isset($_POST['mark'])) {
        $marked = $_POST['mark'];
        foreach ($marked as $symb) {
            if (buy_stock($symb, $_POST["comment_{$symb}"], $_POST["volume_{$symb}"])) {
                del_from_cart('cart', $symb);
            }
        }
    }
Exemple #11
0
    print '<table border="1" cellpadding="5" cellspacing="0" align="center"><tr><td align="center">';
    $sql_input_form->display();
    print '</td></tr>';
    print '</table>';
    // add them to the shopping cart or watch list
    print '<table border="1" cellpadding="5" cellspacing="0" align="center"><tr><td align="center">';
    if (isset($_POST['buy'])) {
        $buy = $_POST['buy'];
        foreach ($buy as $symbol) {
            if (add_to_cart('cart', $symbol)) {
                print "<tr><td>Added {$symbol} to buy</td></td>";
            }
        }
    }
    print '</tr>';
    if (isset($_POST['watch'])) {
        $watch = $_POST['watch'];
        foreach ($watch as $symbol) {
            if (add_to_cart('watch', $symbol)) {
                print "<tr><td>Added {$symbol} to watch</td></td>";
            }
        }
    }
    print '</tr>';
    print '</table>';
} else {
    print '<table border="1" cellpadding="5" cellspacing="0" align="center"><tr><td align="center">';
    $sql_input_form->display();
    print '</td></tr>';
    print '</table>';
}
     $sql = " SELECT * FROM " . $table_prefix . "saved_items ";
     $sql .= " WHERE cart_item_id=" . $db->tosql($cart_item_id, INTEGER);
     $sql .= " AND user_id=" . $db->tosql($_COOKIE['wishlist_user_id'], INTEGER);
     $sql .= " ORDER BY cart_item_id ";
     $db->query($sql);
     if ($db->next_record()) {
         do {
             $sc_errors = "";
             $sc_message = "";
             $cart_item_id = $db->f("cart_item_id");
             $item_id = $db->f("item_id");
             $item_name = $db->f("item_name");
             $quantity = $db->f("quantity");
             $price = $db->f("price");
             // add to cart
             add_to_cart($item_id, $price, $quantity, "db", "ADD", $new_cart_id, $second_page_options, $sc_errors, $sc_message, $cart_item_id, $item_name);
         } while ($db->next_record());
     }
     // check if any coupons can be added or removed
     check_coupons();
     header("Location: " . get_custom_friendly_url("basket.php") . "?rp=" . urlencode(get_custom_friendly_url("user_wishlist.php")));
     exit;
 } else {
     if ($operation == "delete") {
         // delete an item
         $cart_item_id = get_param("cart_item_id");
         $sql = " DELETE FROM " . $table_prefix . "saved_items ";
         $sql .= " WHERE cart_item_id=" . $db->tosql($cart_item_id, INTEGER);
         $sql .= " AND user_id=" . $db->tosql($_COOKIE['wishlist_user_id'], INTEGER);
         $db->query($sql);
     }
<?php

require_once 'cart_functions.php';
//add item to cart
if (isset($_POST['pid']) && isset($_POST['qty'])) {
    $pid = $_POST['pid'];
    $qty = $_POST['qty'];
    if (isset($_POST['slct'])) {
        $selection = $_POST['slct'];
    } else {
        $selection = false;
    }
}
if (isset($pid)) {
    $item_id = check_product_in_cart($pid, false, $selection);
    if ($item_id) {
        update_cart($item_id, $qty);
    } else {
        add_to_cart($pid, $selection);
    }
    //adds one to the cart
}
$count = count_items();
echo json_encode(array("count" => "{$count}"));
        // this simply turns the update button with the product id of where it came from to "no"
    }
    if (isset($_POST['quantArr'])) {
        // if user has tried to change two quantities at once, after they've updated one the other will remain where they left it until they update that one.
        $quantarr = $_POST['quantArr'];
        //this is an array of all of the quantities in the cart sent by the form
    }
    if (isset($pID)) {
        $cID = check_product_in_cart($pID);
    }
    if ($cID && $qnty != 0) {
        update_cart($cID, $qnty);
        //$qnty is how many to add on to what is already in the cart
    } else {
        if ($qnty != 0 && isset($pID)) {
            add_to_cart($pID);
            //adds one to the cart
        } else {
            if ($qnty == 0 && $cID) {
                update_cart($cID, $qnty);
            }
        }
    }
}
$count = count_items();
$count_string = $count == 1 ? $count . ' item' : $count . ' items';
$shipping = 350;
/**********************************************************/
/* Start displaying the table in which the cart items sit */
/**********************************************************/
$table = '	<div id="cart-table"><table class ="cart-list">
?>
            <div class="vat-notice">
              (<?php 
echo __('incl. {tax_percent}% VAT', array('{tax_percent}' => $product->getTaxPercent(0)), 'timpany');
?>
)
            </div>
          </dd>
        </dl>
      </div>
      <div class="product-availability"><?php 
echo format_number_choice(__('[0] no items left |[1,1] only one item left |(1,10] only {number} items left |(10,Inf] available', null, 'timpany'), array('{number}' => $product->getInventory()), $product->getInventory());
?>
</div>
      <div class="product-name"><?php 
echo add_to_cart($product, __('add to cart', null, 'timpany'));
?>
</div>
      <div class="product-description"><?php 
echo $product->getDescription(0);
?>
</div>
      <form action="<?php 
echo url_for('@timpany_cart_add?product=' . $product->getSlug());
?>
" method="POST">
        <?php 
echo $form;
?>
        <input type="submit" value="<?php 
echo __('add to cart', null, 'timpany');