Commit 940eaa3e authored by Malcolm Blaney's avatar Malcolm Blaney

Add tabbed option for cart items.

parent edf08ef1
......@@ -94,6 +94,7 @@ class Cart extends Base {
public function Content($id) {
$content = '';
$items = '';
if (isset($_GET['payment']) && isset($_SESSION['cart-email'])) {
if ($_GET['payment'] === 'paypal') {
// TODO: There is no checking done on paypal return values,
......@@ -130,21 +131,42 @@ class Cart extends Base {
}
}
$content .= '<div id="cart-total"></div>'.
'<button id="cart-checkout">checkout</button><br>';
'<button id="cart-checkout">checkout</button><br>'.
'<form id="cart-form">';
$tabs = '';
$prev_tab = '';
$show_tabs = false;
if ($this->Substitute('cart-tabs') === 'true') {
$tabs .= '<div id="cart-tabs"><ul>';
$show_tabs = true;
}
$mysqli = connect_db();
$query = 'SELECT cart_items.name, image, short, full, price, variable, '.
'minimum, download FROM cart_items LEFT JOIN cart_item_page ON '.
'minimum, download, tab FROM cart_items LEFT JOIN cart_item_page ON '.
'cart_items.user = cart_item_page.user AND '.
'cart_items.name = cart_item_page.name WHERE '.
'cart_items.user = "'.$this->owner.'" AND available = 1 AND '.
'page = "'.$this->user->page.'" ORDER BY item_order';
$content .= '<form id="cart-form">';
'page = "'.$this->user->page.'" ORDER BY tab, item_order';
if ($result = $mysqli->query($query)) {
$price_text = $this->Substitute('cart-price-text');
$quantity_text = $this->Substitute('cart-quantity-text');
while ($cart_items = $result->fetch_assoc()) {
$content .= $this->FormatItem($cart_items, $price_text, $quantity_text);
if ($show_tabs) {
$tab_id = preg_replace('/[^a-z0-9_-]/', '-',
strtolower($cart_items['tab']));
if ($cart_items['tab'] !== $prev_tab) {
$tabs .= '<li><a href="#cart-tab-'.$tab_id.'">'.$cart_items['tab'].
'</a></li>';
if ($items !== '') {
// Close the previous tab before creating the next one.
$items .= '</div>';
}
$items .= '<div id="cart-tab-'.$tab_id.'">';
$prev_tab = $cart_items['tab'];
}
}
$items .= $this->FormatItem($cart_items, $price_text, $quantity_text);
}
$result->close();
}
......@@ -161,7 +183,12 @@ class Cart extends Base {
'<label for="customer-detail-description">'.$label.'</label>'.$input.
'</div>';
}
$content .= '</form>'.
if ($show_tabs) {
$tabs .= '</ul>';
// The first closing tag is for the last tab, the second is for #cart-tabs
$items .= '</div></div>';
}
$content .= $tabs.$items.'</form>'.
'<div id="cart-item-dialog"></div>'.
'<div id="cart-checkout-dialog" class="hidden">'.
'<div id="cart-summary"></div>'.
......@@ -293,6 +320,7 @@ class Cart extends Base {
'name VARCHAR(100) NOT NULL,'.
'page VARCHAR(200),'.
'available TINYINT(1),'.
'tab VARCHAR(100),'.
'item_order INT UNSIGNED,'.
'PRIMARY KEY(user, name, page)'.
') ENGINE=MyISAM';
......@@ -424,8 +452,17 @@ class Cart extends Base {
}
public function Update() {
// This is called when the version of the module is updated,
// to provide a way to update or modify tables etc..
$mysqli = connect_db();
$query = 'ALTER TABLE cart_item_page ADD COLUMN tab VARCHAR(100) AFTER '.
'available';
if (!$mysqli->query($query)) {
$this->Log('Cart->Update 1: '.$mysqli->error);
}
$query = 'UPDATE cart_item_page SET tab = ""';
if (!$mysqli->query($query)) {
$this->Log('Cart->Update 2: '.$mysqli->error);
}
$mysqli->close();
}
public function UpdateScript($path) {
......@@ -443,12 +480,13 @@ class Cart extends Base {
// Get the availability and item_order for the current page. This is done
// in two steps because the queries don't join well. Need everything from
// the cart_items table and only existing values from cart_item_page table.
$query = 'SELECT name, available, item_order FROM cart_item_page WHERE '.
'user = "'.$this->owner.'" AND page = "'.$this->user->page.'"';
$query = 'SELECT name, available, tab, item_order FROM cart_item_page '.
'WHERE user = "'.$this->owner.'" AND page = "'.$this->user->page.'"';
if ($result = $mysqli->query($query)) {
while ($cart_item_page = $result->fetch_assoc()) {
$current[$cart_item_page['name']] =
['available' => $cart_item_page['available'],
'tab' => $cart_item_page['tab'],
'item_order' => $cart_item_page['item_order']];
}
$result->close();
......@@ -464,10 +502,12 @@ class Cart extends Base {
$name = $cart_items['name'];
if (isset($current[$name])) {
$cart_items['available'] = $current[$name]['available'];
$cart_items['tab'] = $current[$name]['tab'];
$cart_items['item_order'] = $current[$name]['item_order'];
}
else {
$cart_items['available'] = '0';
$cart_items['tab'] = '';
$cart_items['item_order'] = '0';
}
// The item name and short description are stored in the database with
......@@ -1025,6 +1065,7 @@ class Cart extends Base {
$minimum = (float)$_POST['minimum'];
$minimum = number_format($minimum, 2, '.', '');
$download = $mysqli->escape_string($_POST['download']);
$item_tab = $mysqli->escape_string($_POST['itemTab']);
$item_order = (int)$_POST['itemOrder'];
$available = (int)$_POST['available'];
$query = 'INSERT INTO cart_items VALUES ("'.$this->owner.'", "'.$name.'", '.
......@@ -1037,9 +1078,9 @@ class Cart extends Base {
$this->Log('Cart->SaveItem 1: '.$mysqli->error);
}
$query = 'INSERT INTO cart_item_page VALUES ("'.$this->owner.'", '.
'"'.$name.'", "'.$this->user->page.'", '.$available.', '.$item_order.') '.
'ON DUPLICATE KEY UPDATE available = '.$available.', '.
'item_order = '.$item_order;
'"'.$name.'", "'.$this->user->page.'", '.$available.', "'.$item_tab.'", '.
$item_order.') ON DUPLICATE KEY UPDATE available = '.$available.', '.
'tab = "'.$item_tab.'", item_order = '.$item_order;
if (!$mysqli->query($query)) {
$this->Log('Cart->SaveItem 2: '.$mysqli->error);
}
......@@ -1305,7 +1346,7 @@ class Cart extends Base {
}
private function Settings() {
return '<div id="cart-tabs">'.
return '<div id="cart-settings-tabs">'.
'<ul>'.
'<li><a href="#cart-items-tab">Items</a></li>'.
'<li><a href="#cart-shipping-tab">Shipping</a></li>'.
......@@ -1345,10 +1386,13 @@ class Cart extends Base {
'<input type="checkbox" id="cart-item-available">'.
'</div>'.
'<i>Specify the position to display this item in the store.</i>'.
'<div class="form-spacing">'.
'<label for="cart-item-tab">Tab:</label>'.
'<input id="cart-item-tab" maxlength="100">'.
'</div>'.
'<div class="form-spacing">'.
'<label for="cart-item-order">Order:</label>'.
'<input id="cart-item-order" size="10" '.
'maxlength="10">'.
'<input id="cart-item-order" maxlength="10">'.
'</div>'.
'<i>You can allow the buyer to enter their own price for the '.
'item.</i>'.
......
This diff is collapsed.
......@@ -62,6 +62,7 @@ if (!this.dobrado.cart) {
spin: cartQuantity,
change: cartQuantity });
$("#cart-checkout").button({ disabled: true }).click(checkout);
$("#cart-tabs").tabs();
$("#cart-confirm-button").button().click(confirmPurchase);
$("#cart-continue-button").button().click(function() {
$("#cart-checkout-dialog").dialog("close");
......@@ -334,8 +335,8 @@ if (!this.dobrado.cart) {
function checkout() {
$("#cart-checkout-dialog").dialog("open");
$("#cart-summary").show().html("You have selected the following items:<br>"
+ cartTotal());
$("#cart-summary").show().
html("You have selected the following items:<br>" + cartTotal());
$("#cart-checkout-message").html("");
$("#cart-customer-details-form").hide();
$("#cart-confirm-button").show();
......@@ -438,7 +439,7 @@ if (!this.dobrado.cart) {
settings = JSON.parse(response);
$("#cart-editor").html(settings.content);
$("#cart-tabs").tabs();
$("#cart-settings-tabs").tabs();
$("#cart-editor").dialog("open");
editor = CKEDITOR.replace($("#cart-item-full").get(0),
{ allowedContent: true,
......@@ -553,6 +554,7 @@ if (!this.dobrado.cart) {
}
$("#cart-item-minimum").val(item.minimum);
$("#cart-item-download").val(item.download);
$("#cart-item-tab").val(item.tab);
$("#cart-item-order").val(item.item_order);
if (item.available === "1") {
$("#cart-item-available").prop("checked", true);
......@@ -594,6 +596,7 @@ if (!this.dobrado.cart) {
$("#cart-item-variable").prop("checked", false);
$("#cart-item-minimum").val("");
$("#cart-item-download").val("");
$("#cart-item-tab").val("");
$("#cart-item-order").val("");
$("#cart-item-available").prop("checked", false);
if (settings.items.length !== 0) {
......@@ -636,6 +639,7 @@ if (!this.dobrado.cart) {
var variable = $("#cart-item-variable:checked").length.toString();
var minimum = $("#cart-item-minimum").val();
var download = $("#cart-item-download").val();
var itemTab = $("#cart-item-tab").val();
var itemOrder = $("#cart-item-order").val();
var available = $("#cart-item-available:checked").length.toString();
......@@ -651,6 +655,7 @@ if (!this.dobrado.cart) {
variable: variable,
minimum: minimum,
download: download,
itemTab: itemTab,
itemOrder: itemOrder,
available: available,
url: location.href,
......@@ -669,7 +674,8 @@ if (!this.dobrado.cart) {
full: fullDescription, weight: weight,
price: price, variable: variable,
minimum: minimum, download: download,
item_order: itemOrder, available: available };
tab: itemTab, item_order: itemOrder,
available: available };
newItem = false;
return false;
}
......@@ -681,7 +687,8 @@ if (!this.dobrado.cart) {
full: fullDescription, weight: weight,
price: price, variable: variable,
minimum: minimum, download: download,
item_order: itemOrder, available: available });
tab: itemTab, item_order: itemOrder,
available: available });
updateItems();
}
clearItem();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment