Commit b20fd401 authored by Malcolm Blaney's avatar Malcolm Blaney

Send order confirmation to customer as well as business.

parent 583bcd7b
Pipeline #4602833 failed with stage
in 1 minute and 35 seconds
......@@ -334,6 +334,7 @@ class Cart extends Base {
$query = 'CREATE TABLE IF NOT EXISTS cart_order ('.
'user VARCHAR(50) NOT NULL,'.
'id INT UNSIGNED NOT NULL AUTO_INCREMENT,'.
'email VARCHAR(200) NOT NULL,'.
'description TEXT,'.
'method ENUM("credit", "paypal", "pickup") NOT NULL,'.
'timestamp INT(10) UNSIGNED NOT NULL,'.
......@@ -345,14 +346,6 @@ class Cart extends Base {
}
$mysqli->close();
$cart_email = "An order was received at !host<br>\n".
"Please check that the transaction has completed, before processing.".
"<br><br>\n\n".
"Items: !items<br>\nTotal: $!amount<br><br>\n\n".
"Name: !first !last<br>\nEmail: !email<br>\n".
"Address:<br>\n!address<br>\n!city<br>\n!postcode<br>\n!state<br>\n".
"!country<br><br>\n\n";
$template = ['"cart-price-text","","Price:"',
'"cart-quantity-text","","Quantity:"',
'"cart-title","","Shopping Cart"',
......@@ -361,7 +354,11 @@ class Cart extends Base {
'!state<br>!country<br>"',
'"cart-display-item","","<h2>!name</h2><img src="!image">'.
'!description',
'"cart-email","","'.$cart_email.'"'];
'"cart-email","","To !first !last<br>Thank you for your '.
'order!The following is a confirmation of your order and'.
'contact details:<br><br>Items: !items<br>Total: $!amount'.
'<br><br>Email: !email<br>Address:<br>!address<br>!city<br>'.
'!postcode<br>!state<br>!country<br><br>"'];
$this->AddTemplate($template);
$site_style = ['"","#cart-summary","margin-bottom","40px"',
......@@ -446,27 +443,10 @@ class Cart extends Base {
public function Update() {
$mysqli = connect_db();
$query = 'ALTER TABLE cart_method MODIFY COLUMN name '.
'ENUM("credit", "paypal", "pickup") NOT NULL';
if (!$mysqli->query($query)) {
$this->Log('Cart->Update 1: '.$mysqli->error);
}
$query = 'ALTER TABLE cart_method MODIFY COLUMN gateway '.
'ENUM("eway", "migs")';
$query = 'ALTER TABLE cart_order ADD COLUMN email VARCHAR(200) NOT NULL '.
'AFTER id';
if (!$mysqli->query($query)) {
$this->Log('Cart->Update 2: '.$mysqli->error);
}
$query = 'CREATE TABLE IF NOT EXISTS cart_order ('.
'user VARCHAR(50) NOT NULL,'.
'id INT UNSIGNED NOT NULL AUTO_INCREMENT,'.
'description TEXT,'.
'method ENUM("credit", "paypal", "pickup") NOT NULL,'.
'timestamp INT(10) UNSIGNED NOT NULL,'.
'completed INT(10) UNSIGNED,'.
'PRIMARY KEY(user, id)'.
') ENGINE=MyISAM';
if (!$mysqli->query($query)) {
$this->Log('Cart->Update 3: '.$mysqli->error);
$this->Log('Cart->Update: '.$mysqli->error);
}
$mysqli->close();
}
......@@ -605,7 +585,7 @@ class Cart extends Base {
$patterns = ['/!first/', '/!last/', '/!address/', '/!postcode/',
'/!city/', '/!state/', '/!country/', '/!description/'];
$replacements = [$first, $last, $address, $postcode, $city, $state,
$country];
$country, $description];
$result['content'] = $this->Substitute('cart-checkout', $patterns,
$replacements);
$result['content'] .= $this->Payment($item_names, $total_price +
......@@ -630,13 +610,15 @@ class Cart extends Base {
}
$content = '';
$email = '';
$message = '';
$order_id = $_SESSION['cart-order-id'];
$mysqli = connect_db();
$query = 'SELECT description FROM cart_order WHERE user = '.
$query = 'SELECT email, description FROM cart_order WHERE user = '.
'"'.$this->owner.'" AND id = '.$order_id;
if ($result = $mysqli->query($query)) {
if ($cart_order = $result->fetch_assoc()) {
$email = $cart_order['email'];
$message = $cart_order['description'];
}
$result->close();
......@@ -651,17 +633,22 @@ class Cart extends Base {
'Thanks for your purchase!<br>'.
'For your reference, the order number is: '.$order_id.'<br><br>'.
'<button>dismiss</button></div>';
$message .= 'Payment made using PayPal.';
$this->SendEmail('Order number '.$order_id.' received', $message);
$this->SendEmail('Confirmation of order number '.$order_id,
$message.'Payment made using PayPal.', $email);
}
else if ($_GET['payment'] === 'credit') {
$gateway = $this->Gateway('credit');
if ($gateway === true) {
$this->SendEmail('Confirmation of order number '.$order_id,
$message.'Payment made using Credit Card.', $email);
$gateway = 'Thanks your payment has been processed.';
}
else {
$this->SendEmail('Error processing order number '.$order_id, $message);
}
$content = '<div class="cart-payment-message">'.$gateway.'<br>'.
'For your reference, the order number is: '.$order_id.'<br><br>'.
'<button>dismiss</button></div>';
$message .= "Payment made using Credit Card. Transaction status:<br>\n".
$gateway;
$this->SendEmail('Order number '.$order_id.' received', $message);
}
$query = 'UPDATE cart_order SET completed = '.time().' WHERE user = '.
'"'.$this->owner.'" AND id = '.$_SESSION['cart-order-id'];
......@@ -904,7 +891,7 @@ class Cart extends Base {
// If no data was provided, check the payment result.
if (isset($result['TransactionStatus']) &&
$result['TransactionStatus'] === true) {
return 'Thanks your payment has been processed.';
return true;
}
return '<div class="error ui-state-error ui-corner-all">'.
'There was a problem processing your payment.<br>'.
......@@ -948,7 +935,7 @@ class Cart extends Base {
// If no data was provided, check the payment result.
if (isset($_GET["vpc_TxnResponseCode"]) &&
$_GET['vpc_TxnResponseCode'] === '0') {
return 'Thanks your payment has been processed.';
return true;
}
return '<div class="error ui-state-error ui-corner-all">'.
'There was a problem processing your payment.<br>'.
......@@ -1004,18 +991,17 @@ class Cart extends Base {
}
// Store the details to send an email for the order in the session, but
// it's not sent until return from payment processing.
$patterns = ['/!host/', '/!items/', '/!amount/', '/!first/', '/!last/',
'/!email/', '/!address/', '/!postcode/', '/!city/',
'/!state/', '/!country/', '/!description/'];
$replacements = [$this->user->config->ServerName(), $items, $amount,
$first, $last, $email, $address, $postcode, $city,
$state, $country, $description];
$patterns = ['/!items/', '/!amount/', '/!first/', '/!last/', '/!email/',
'/!address/', '/!postcode/', '/!city/', '/!state/',
'/!country/'];
$replacements = [$items, $amount, $first, $last, $email, $address,
$postcode, $city, $state, $country];
$email_text =
$mysqli->escape_string($this->Substitute('cart-email', $patterns,
$replacements));
$query = 'INSERT INTO cart_order (user, description, method, timestamp) '.
'VALUES ("'.$this->owner.'", "'.$email_text.'", "'.$method.'", '.
time().')';
$query = 'INSERT INTO cart_order (user, email, description, method, '.
'timestamp) VALUES ("'.$this->owner.'", "'.$email.'", '.
'"'.$email_text.'", "'.$method.'", '.time().')';
if (!$mysqli->query($query)) {
$this->Log('Cart->Payment 3: '.$mysqli->error);
}
......@@ -1029,8 +1015,9 @@ class Cart extends Base {
if ($method === 'pickup') {
$order_id = $_SESSION['cart-order-id'];
$this->SendEmail('Order number '.$order_id.' received',
$email_text.'Note: Payment to be made on Pick up.');
$this->SendEmail('Confirmation of order number '.$order_id, $email_text.
'Your order will be available to pick up from: '.
$description, $email);
return $order_id;
}
if ($method === 'paypal') {
......@@ -1428,7 +1415,7 @@ class Cart extends Base {
return $shipping;
}
private function SendEmail($subject, $message) {
private function SendEmail($subject, $message, $email = NULL) {
$business = '';
$mysqli = connect_db();
$query = 'SELECT email FROM cart_checkout WHERE user = "'.$this->owner.'"';
......@@ -1443,8 +1430,8 @@ class Cart extends Base {
}
$mysqli->close();
$message = wordwrap("<html><head><title>Order Received</title></head>\n".
"<body>\n".$message."</body></html>");
$message = wordwrap('<html><head><title>Order Confirmation</title>'.
"</head>\n<body>\n".$message.'</body></html>');
$sender = $this->Substitute('system-sender', '/!host/',
$this->user->config->ServerName());
$sender_name = $this->Substitute('system-sender-name');
......@@ -1466,7 +1453,13 @@ class Cart extends Base {
if ($bcc !== '') {
$headers .= 'Bcc: '.$bcc."\r\n";
}
mail($business, $subject, $message, $headers, '-f '.$sender);
if ($email) {
$headers .= 'Bcc: '.$business."\r\n";
mail($email, $subject, $message, $headers, '-f '.$sender);
}
else {
mail($business, $subject, $message, $headers, '-f '.$sender);
}
}
private function VerifyItem($item, $price) {
......
......@@ -138,9 +138,9 @@ class Start extends Base {
if ($this->user->name === $this->owner && $this->user->page === 'index') {
// The first thing they should do is visit the stock page.
if (can_view_page('admin/stock') || can_edit_page('admin/stock')) {
return array('selector' => '#page-input',
'content' => 'To update your product list, type '.
'admin/stock here to go to the stock page.',
return array('selector' => '#page-select-button',
'content' => 'To update your product list, choose '.
'stock from the menu to go to the stock page.',
'arrow' => '250px');
}
// Otherwise let admin users know how to create accounts.
......
......@@ -255,7 +255,7 @@ class SimplePie_Content_Type_Sniffer
public function feed_or_html()
{
$len = strlen($this->file->body);
$pos = strspn($this->file->body, "\x09\x0A\x0D\x20");
$pos = strspn($this->file->body, "\x09\x0A\x0D\x20\xEF\xBB\xBF");
while ($pos < $len)
{
......
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