Commit 74108d47 authored by Malcolm Blaney's avatar Malcolm Blaney

Add an optional input to the Cart checkout form to provide custom

information to the site owner.
parent 2c019841
......@@ -159,6 +159,14 @@ class Cart extends Base {
}
$mysqli->close();
$description = "";
$label = $this->Substitute("cart-description-label");
$input = $this->Substitute("cart-description-input");
if ($label !== "" && $input !== "") {
$description = '<div class="form-spacing">'.
'<label for="customer-detail-description">'.$label.'</label>'.$input.
'</div>';
}
$content .= '</form>'.
'<div id="cart-item-dialog"></div>'.
'<div id="cart-checkout-dialog" class="hidden">'.
......@@ -198,6 +206,7 @@ class Cart extends Base {
'<label for="customer-detail-country">Country:</label>'.
'<input id="customer-detail-country" size="20" maxlength="50">'.
'</div>'.
$description.
'<div class="form-spacing">'.
$this->PaymentMethods().
'</div>'.
......@@ -224,7 +233,7 @@ class Cart extends Base {
public function Factory($fn, $p = NULL) {
if (is_array($p)) {
if ($fn == "Payment" && count($p) == 10) {
if ($fn == "Payment" && count($p) == 11) {
$items = $p[0];
$amount = $p[1];
$first = $p[2];
......@@ -235,8 +244,9 @@ class Cart extends Base {
$postcode = $p[7];
$state = $p[8];
$country = $p[9];
return $this->Payment($items, $amount, $first, $last, $email,
$address, $city, $postcode, $state, $country);
$description = $p[10];
return $this->Payment($items, $amount, $first, $last, $email, $address,
$city, $postcode, $state, $country, $description);
}
if ($fn == "PaymentMethods" && count($p) == 2) {
$display_cash = $p[0];
......@@ -418,27 +428,6 @@ 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_items DROP COLUMN available';
if (!$mysqli->query($query)) {
$this->Log('Cart->Update 1: '.$mysqli->error);
}
$query = 'ALTER TABLE cart_items DROP COLUMN item_order';
if (!$mysqli->query($query)) {
$this->Log('Cart->Update 2: '.$mysqli->error);
}
$query = 'CREATE TABLE IF NOT EXISTS cart_item_page ('.
'user VARCHAR(50) NOT NULL,'.
'name VARCHAR(100) NOT NULL,'.
'page VARCHAR(200),'.
'available TINYINT(1),'.
'item_order INT UNSIGNED,'.
'PRIMARY KEY(user, name, page)'.
') ENGINE=MyISAM';
if (!$mysqli->query($query)) {
$this->Log('Cart->Update 3: '.$mysqli->error);
}
$mysqli->close();
}
public function UpdateScript($path) {
......@@ -511,6 +500,8 @@ class Cart extends Base {
$postcode = $mysqli->escape_string(htmlspecialchars($_POST["postcode"]));
$state = $mysqli->escape_string(htmlspecialchars($_POST["state"]));
$country = $mysqli->escape_string(htmlspecialchars($_POST["country"]));
$description =
$mysqli->escape_string(htmlspecialchars($_POST["description"]));
// Look for shipping rules that match the given locations.
$rules = $this->ShippingRules($city, $state, $country);
......@@ -549,7 +540,7 @@ class Cart extends Base {
$object["processing"] = $processing;
// TODO: Need to run a sanitizer when reflecting back inputs.
$patterns = array("/!first/", "/!last/", "/!address/", "/!postcode/",
"/!city/", "/!state/", "/!country/");
"/!city/", "/!state/", "/!country/", "/!description/");
$replacements = array($first, $last, $address, $postcode, $city,
$state, $country);
$object["content"] = $this->Substitute("cart-checkout", $patterns,
......@@ -557,7 +548,8 @@ class Cart extends Base {
$object["content"] .= $this->Payment($item_names, $total_price +
$shipping + $processing, $first,
$last, $email, $address, $city,
$postcode, $state, $country);
$postcode, $state, $country,
$description);
}
else {
$object["shipping"] = 0;
......@@ -795,8 +787,8 @@ class Cart extends Base {
}
}
private function Payment($items, $amount, $first, $last, $email,
$address, $city, $postcode, $state, $country) {
private function Payment($items, $amount, $first, $last, $email, $address,
$city, $postcode, $state, $country, $description) {
$business = "";
$currency = "";
$method = "";
......@@ -847,10 +839,10 @@ class Cart extends Base {
// it's not sent until return from payment processing.
$patterns = array("/!host/", "/!items/", "/!amount/", "/!first/", "/!last/",
"/!email/", "/!address/", "/!postcode/", "/!city/",
"/!state/", "/!country/");
"/!state/", "/!country/", "/!description/");
$replacements = array($this->user->config->ServerName(), $items, $amount,
$first, $last, $email, $address, $postcode, $city,
$state, $country);
$state, $country, $description);
$_SESSION["cart-email"] = $this->Substitute("cart-email", $patterns,
$replacements);
......
......@@ -327,11 +327,14 @@ class Sell extends Base {
" processing fee.";
}
$object["content"] .= "<br><br>";
// TODO: description is not currently used by Sell module.
$description = "";
$object["content"] .= $cart->Factory("Payment",
array($items, $total + $processing,
$first, $last, $email,
$address, $city, $postcode,
$state, $country));
$state, $country,
$description));
}
else {
$object["content"] .= "Cannot process payment. Cart module must be ".
......
......@@ -75,7 +75,7 @@ if($("#customer-detail-postcode").val()===""){$("#cart-checkout-info").html("Ple
if($("#customer-detail-city").val()===""){$("#cart-checkout-info").html("Please enter your city.");return false;}
if($("#customer-detail-state").val()===""){$("#cart-checkout-info").html("Please enter your state.");return false;}
if($("#customer-detail-country").val()===""){$("#cart-checkout-info").html("Please enter your country.");return false;}
$("#cart-checkout-info").html("Processing... please wait.");$.post("/php/request.php",{request:"cart",action:"checkout",cart:JSON.stringify(cart),first:$("#customer-detail-first").val(),last:$("#customer-detail-last").val(),email:$("#customer-detail-email").val(),address:$("#customer-detail-address").val(),city:$("#customer-detail-city").val(),state:$("#customer-detail-state").val(),country:$("#customer-detail-country").val(),postcode:$("#customer-detail-postcode").val(),method:$("#customer-detail-method").val(),url:location.href,token:dobrado.token},function(response){if(dobrado.checkResponseError(response,"cart checkout")){return;}
$("#cart-checkout-info").html("Processing... please wait.");$.post("/php/request.php",{request:"cart",action:"checkout",cart:JSON.stringify(cart),first:$("#customer-detail-first").val(),last:$("#customer-detail-last").val(),email:$("#customer-detail-email").val(),address:$("#customer-detail-address").val(),city:$("#customer-detail-city").val(),state:$("#customer-detail-state").val(),country:$("#customer-detail-country").val(),postcode:$("#customer-detail-postcode").val(),description:$("#customer-detail-description").val(),method:$("#customer-detail-method").val(),url:location.href,token:dobrado.token},function(response){if(dobrado.checkResponseError(response,"cart checkout")){return;}
var checkout=JSON.parse(response);$("#cart-checkout-info").html("");$("#cart-customer-details-form").hide();$("#cart-summary").html("You have selected the following items:<br>"+
cartTotal(checkout.shipping,checkout.processing));$("#cart-checkout-message").html(checkout.content);$("#cart-payment").button().click(clearCart);});return false;}
function close(){if(editor){editor.destroy();}}
......
......@@ -374,6 +374,7 @@ if (!this.dobrado.cart) {
state: $("#customer-detail-state").val(),
country: $("#customer-detail-country").val(),
postcode: $("#customer-detail-postcode").val(),
description: $("#customer-detail-description").val(),
method: $("#customer-detail-method").val(),
url: location.href,
token: dobrado.token },
......
......@@ -372,6 +372,8 @@ $us_description =
"purchase-check-quota" => "The string 'true' or 'false', can be used ".
"with invoice-remove-orders to only remove orders that haven't ".
"reached quota.",
"purchase-show-grower" => "Show grower information rather than the ".
"supplier name in orders and invoices.",
"payment-surcharge-type" => "The name of the custom surcharge ".
"type used, options are: 'sliding-scale-capped', ".
"'zero-one-two-fifty. If left blank the surcharge value is taken ".
......@@ -529,6 +531,8 @@ $us_description =
"from the new-user-sender.",
"new-user-sender-bcc" => "The bcc address to use when an email is ".
"sent from the new-user-sender.",
"new-user-moderator" => "An email address to send the new user ".
"confirmation link to, rather than the new user.",
"post-format" => "The template for a blog post, substitutes: !title, ".
"!description, !author, !category, !media and !date.",
"reader-item-count" => "The number of items to return when more are ".
......@@ -565,12 +569,20 @@ $us_description =
"cart-title" => "The text for the title above the cart items.",
"cart-checkout" => "The text to display at checkout, will substitute ".
"the following to show where items will be sent: !first, !last, ".
"!address, !postcode, !city, !state, !country.",
"!address, !postcode, !city, !state, !country, !description.",
"cart-email" => "The full text of the email that will be sent to the ".
"site owner when a purchase has been processed. Substitutes: !host, ".
"!items, !amount, !first, !last, !email, !address, !postcode, ".
"!city, !state, !country.",
"backup-path" => "The file system path for storing backups.");
"!city, !state, !country, !description.",
"cart-description-label" => "A label for the input option set in ".
"the 'cart-description-input' template.",
"cart-description-input" => "A configurable input option added to ".
"cart-customer-details-form' to request custom details.",
"backup-path" => "The file system path for storing backups.",
"control-menu" => "A comma separated list of module names to display ".
"in the add menu for users who aren't in the admin group.",
"control-admin-menu" => "A comma separated list of module names to ".
"display in the add menu for users who are in the admin group.");
$description_query = "";
foreach ($us_description as $label => $description) {
if ($description_query !== "") $description_query .= ",";
......
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