Closed coldes closed 11 years ago
Fellow send form straggler :) here's a basic code for the email.php that fits Simple Cart V3.
Struggled but got it work, at last :
<?php
$to = 'mail@someshop.com';
$subject = 'Simple Cart Order';
$content = $_POST;
$body = '';
for($i=1; $i < $content['itemCount'] + 1; $i++) {
$name = 'item_name_'.$i;
$quantity = 'item_quantity_'.$i;
$price = 'item_price_'.$i;
$total = $content[$quantity] * $content[$price];
$body .= $name.' '.$quantity.' '.$price;
$body .= <br>;
}
$headers = 'From: webmaster@example.com' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $body, $headers);
Header('Location: thankyou.php');
?>
It's up to you now to add a custom name to it, and hopefully share what you end up with for the sake of people like us.
http://www.adamedoe.com/2012/11/simplecartjs-v3-php-code-for-sendform.html
Hello Adamedoe, just a quick response to say a HUGE thank you, I'll let you know how it all goes implementing this with simplecartjs and YES will share any information once I have this all working. Regards, Col
On Thu, Nov 15, 2012 at 11:34 PM, adamedoe notifications@github.com wrote:
Fellow send form straggler :) here's a basic code for the email.php that fits Simple Cart V3.
Struggled but got it work, at last :
<?php $to = 'mail@someshop.com'; $subject = 'Simple Cart Order'; $content = $_POST; $body = ''; for($i=1; $i < $content['itemCount'] + 1; $i++) { $name = 'itemname'.$i; $quantity = 'itemquantity'.$i; $price = 'itemprice'.$i; $total = $content[$quantity] * $content[$price]; $body .= $name.' '.$quantity.' '.$price; $body .=
; } $headers = 'From: webmaster@example.com' . "\r\n" . 'Reply-To: webmaster@example.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $body, $headers); Header('Location: thankyou.php'); ?>It's up to you now to add a custom name to it, and hopefully share what you end up with for the sake of people like us.
http://www.adamedoe.com/2012/11/simplecartjs-v3-php-code-for-sendform.html
— Reply to this email directly or view it on GitHubhttps://github.com/wojodesign/simplecart-js/issues/317#issuecomment-10407074.
Hello - OK - no immediate success. Breaking it down, I have success with a basic email send
<?php $to = 'mail@someshop.com'; $subject = 'Simple Cart Order'; $content = $_POST; //body section removed// $headers = 'From: '.$email_from."\r\n". 'Reply-To: webmaster@example.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $body, $headers); Header('Location: success.html'); ?>
Including your body section:
$body = '';
for($i=1; $i < $content['itemCount'] + 1; $i++) {
$name = 'itemname'.$i;
$quantity = 'itemquantity'.$i;
$price = 'itemprice'.$i;
$total = $content[$quantity] * $content[$price];
$body .= $name.' '.$quantity.' '.$price;
$body .=
;
}
I receive a server error HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request.
simpleCart({ //Setting the Cart Columns for the sidebar cart display. cartColumns: [ //{ attr: "image", label: false, view: "image"}, //Name of the item { attr: "name" , label: "Item" }, //Quantity displayed as an input { attr: "quantity", label: "Qty", view: "input"},
//Built in view for a remove link
{ view:'remove', text: "X", label: "Del"},
//Price of item
{ attr: "price", label: "Price"},
//Subtotal of that row (quantity of that item * the price)
{ attr: "total" , label: "SubTot", view: "currency" }
], cartStyle: "table",
checkout: { type: "SendForm" , url: "sendcart.php" , method: "POST" , success: "success.html" , cancel: "cancel.php" }
Any thoughts?
regards, Col
First thought, I suspect the last part of what I gave you above
$body .=
;
should be
$body .= '<br/>';
I'm positive that it runs on Linux using LAMP server.
Is your server configured to send mails? This might be the cause!
For testing purposes, can you run this script instead of sending an email?
<?php
$content = $_POST;
$body = '';
for($i=1; $i < $content['itemCount'] + 1; $i++) {
$name = 'item_name_'.$i;
$quantity = 'item_quantity_'.$i;
$price = 'item_price_'.$i;
$total = $content[$quantity] * $content[$price];
$body .= $name.' '.$quantity.' '.$price;
$body .= <br>;
}
echo $body;
?>
That way, you'll know if Simple Cart's data is processed correctly. You should basically see lines with product name, quantity and price showing up, depending on how many you've got in your cart.
thanks for the super quick response - same server error message with trying the above, my server [mac snow leopard] is setup for emails, as I mentioned, removing the "body" section from sendcart.php produced a successful email send, however it could be a server setting problem?!?
I uploaded my test site to dropbox incase that might work, however all that does is display the php code.
Would be good to upload to a temporary server that handles php to try all of this.
Any thoughts... thanks
On Sat, Nov 17, 2012 at 10:18 AM, adamedoe notifications@github.com wrote:
I'm positive that it runs on Linux using LAMP server.
Is your server configured to send mails? This might be the cause!
For testing purposes, can you run this script instead of sending an email?
<?php $content = $_POST; $body = ''; for($i=1; $i < $content['itemCount'] + 1; $i++) { $name = 'itemname'.$i; $quantity = 'itemquantity'.$i; $price = 'itemprice'.$i; $total = $content[$quantity] * $content[$price]; $body .= $name.' '.$quantity.' '.$price; $body .=
; }echo $body; ?>
That way, you'll know if Simple Cart's data is processed correctly. You should basically see lines with product name, quantity and price showing up, depending on how many you've got in your cart.
— Reply to this email directly or view it on GitHubhttps://github.com/wojodesign/simplecart-js/issues/317#issuecomment-10466180.
My bad, had a couple of missed quotes.
I just tested this couplet :
simpleCart({
cartColumns: [
//Name of the item
{ attr: "name" , label: "Name" },
//Quantity displayed as an input
{ attr: "quantity", label: "Quantity", view: "input"},
//Built in view for a remove link
{ view:'remove', text: "Remove", label: false},
//Price of item
{ attr: "price", label: "Price"},
//Subtotal of that row (quantity of that item * the price)
{ attr: "total" , label: "Subtotal", view: "currency" },
],
cartStyle: "table"
});
simpleCart({
taxRate: 0.2
});
simpleCart({
checkout: {
type: "SendForm",
url: "testdump.php",
method: "POST"
}
});
<?php
$content = $_POST;
$body = '';
for($i=1; $i < $content['itemCount'] + 1; $i++) {
$name = 'item_name_'.$i;
$quantity = 'item_quantity_'.$i;
$price = 'item_price_'.$i;
$body .= 'item #'.$i.': ';
$body .= $content[$name].' '.$content[$quantity].' '.$content[$price];
$body .= '<br>';
}
echo $body;
?>
http://www.youtube.com/watch?v=V4agYhqHZx4
Should work fine with your server too.
OK - SUCCESS - thank you - now I will see about adding some form information, name, email, etc plus see how I can add some styling to the email
On Sat, Nov 17, 2012 at 11:32 AM, adamedoe notifications@github.com wrote:
My bad, had a couple of missed quotes.
I just tested this couplet :
simpleCart({ cartColumns: [ //Name of the item { attr: "name" , label: "Name" }, //Quantity displayed as an input { attr: "quantity", label: "Quantity", view: "input"}, //Built in view for a remove link { view:'remove', text: "Remove", label: false}, //Price of item { attr: "price", label: "Price"}, //Subtotal of that row (quantity of that item * the price) { attr: "total" , label: "Subtotal", view: "currency" }, ], cartStyle: "table" }); simpleCart({ taxRate: 0.2 }); simpleCart({ checkout: { type: "SendForm", url: "testdump.php", method: "POST" } });
<?php $content = $_POST; $body = ''; for($i=1; $i < $content['itemCount'] + 1; $i++) { $name = 'itemname'.$i; $quantity = 'itemquantity'.$i; $price = 'itemprice'.$i; $body .= 'item #'.$i.': '; $body .= $content[$name].' '.$content[$quantity].' '.$content[$price]; $body .= '
'; }echo $body; ?>
http://www.youtube.com/watch?v=V4agYhqHZx4
Should work fine with your server too.
— Reply to this email directly or view it on GitHubhttps://github.com/wojodesign/simplecart-js/issues/317#issuecomment-10468128.
Quick question, the break rule
works with echo $body; ie onscreen view, but with an email send display as text with the cart data - eg
Order #1: Menu Item 1 Qty 1 x $15
Order #2: Menu Item 2 Qty 2 x $11.5
Any thoughts? thanks, Col
OK - got it - remove
$body .= '
';
add ."\n" to end of the below example $body .= 'Order #'.$i.': '.$content[$name].' --- Qty x '.$content[$quantity].' --- Unit Price $'.$content[$price]."\n";
Question: My cart shows a subtotal price rather than a unit price, so how would this be written in the php $body?
say: $subtotal = 'xxxxxx'.$i; [and to include 2 decimal places as the cart shows
plus how to email the Grand Total?
Any answers will be appreciated
Anyway I'll keep plugging away this end
<?php $to = 'mail@someshop.com'; $subject = 'Simple Cart Order'; $content = $_POST;
$body = '';
for($i=1; $i < $content['itemCount'] + 1; $i++) {
$name = 'itemname'.$i;
$quantity = 'itemquantity'.$i;
$price = 'itemprice'.$i;
$body .= 'Order #'.$i.': '.$content[$name].' --- Qty x '.$content[$quantity].' --- Unit Price $'.$content[$price]."\n";
}
$headers = 'From: webmaster@example.com'."\r\n".
'Reply-To: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $body, $headers);
Header('Location: success.html');
?>
Reply-To: webmaster@example.com
X-Mailer: PHP/5.3.15 Message-Id: 20121118034855.C2E70E06F12@someshop.com Date: Sun, 18 Nov 2012 14:48:55 +1100 (EST)
Order #1: Menu Item 1 --- Qty x 1 --- Unit Price $15 Order #2: Menu Item 2 --- Qty x 2 --- Unit Price $11.5
NOW, how to add form data to simpla cart which github issue #305 was heading in the right direction but now stopped. http://playground.simplecartjs.org is no longer to at least look at the source code
My money is on "iamstevemckinney" - he is the demi-god with the answers
Steve, if you are able to help us mere mortals....
Dude, I don't even need custom fields, but it pains me seeing unanswered questions... and I believe that a lot of people need to understand how to use customs fields.
Anyway, here's how I got work!
simpleCart({
checkout: {
type: "SendForm",
url: "testdump.php",
method: "POST",
extra_data: {
customercode: document.getElementById("customercode").value,
cartid: "12321321"
}
}
});
simpleCart.bind( 'beforeCheckout' , function( data ){
data.customercode = document.getElementById("customercode").value;
});
testdump.php code
<?php
$content = $_POST;
$body = '';
$customer = 'customercode';
$body = $content[$customer];
$body .= ' just ordered: <br>';
for($i=1; $i < $content['itemCount'] + 1; $i++) {
$name = 'item_name_'.$i;
$quantity = 'item_quantity_'.$i;
$price = 'item_price_'.$i;
$body .= 'item #'.$i.': ';
$body .= $content[$name].' '.$content[$quantity].' '.$content[$price];
$body .= '<br>';
}
echo $body;
?>
The trick is, you need to put the simpleCart declaration code AFTER your input, because the method getElementById won't return a result unless the input field is already declared and has content on it. You need to put the declaration on the page's footer, right before the
Hello - I am after the ability to send cart data along with basic form details like customer name, etc.
I have looked at the comments in alexjong's post and at the source code in http://playground.simplecartjs.org.
All makes sense, however, what I need to fully test this is the actual source code of "email.php".
Can anyone help with this?
thanks in advance, Col