tags:

views:

330

answers:

2

I use simplecartjs to make a shopping cart on my website where you can select element and send it to your cart... next step, will be the checkout process, but for business reason, no checkout process will append, and a simple form with name and email and date for order pickup will be ask. Now the order must be send to an email address (at the company) that will fullfill the order.

The question : how to send the content of the cart to an email body or as attachement ?

+1  A: 

You should add new checkout method to simplecartjs:

me.emailCheckout = function() {    

    itemsString = "";
    for( var current in me.items ){ 
        var item = me.items[current];
        itemsString += item.name + " " + item.quantity + " " + item.price + "\n";
    }   

    var form = document.createElement("form");
    form.style.display = "none";
    form.method = "POST";
    form.action = "sendjs.php";
    form.acceptCharset = "utf-8";
    form.appendChild(me.createHiddenElement("jcitems", itemsString));
    form.appendChild(me.createHiddenElement("jctotal", me.total));
    document.body.appendChild(form);
    form.submit();
    document.body.removeChild(form);
}

This will create new form element and submit cart data to sendjs.php. Enable this checkout method by setting me.checkoutTo = 'Email' in simplecart options.

Now create a new sendjs.php file:

<?php
    $to      = '[email protected]';
    $subject = 'the subject';
    $jcitems = $_POST['jcitems'];
    $headers = 'From: [email protected]' . "\r\n" .
               'Reply-To: [email protected]' . "\r\n" .
               'X-Mailer: PHP/' . phpversion();
    mail($to, $subject, $jcitems, $headers);
    Header('Location: thankyou.html');
?>

This will send the email message and redirect to thankyou.html page you should also create.

Goran Rakic
A: 

Goran,

Probao sam iskoristiti ovo sta si postirao ovde ali sa obzirom na tome da nisam bas naj naj u te stvare, nisam uspeo da ga upotrebim...Bio bi ti zahvalan ako mi malo detaljnie objasnis gde da dodadem ovo:

me.emailCheckout = function() {

itemsString = "";
for( var current in me.items ){ 
    var item = me.items[current];
    itemsString += item.name + " " + item.quantity + " " + item.price + "\n";
}   

var form = document.createElement("form");
form.style.display = "none";
form.method = "POST";
form.action = "sendjs.php";
form.acceptCharset = "utf-8";
form.appendChild(me.createHiddenElement("jcitems", itemsString));
form.appendChild(me.createHiddenElement("jctotal", me.total));
document.body.appendChild(form);
form.submit();
document.body.removeChild(form);

}

Dali trebam izbrisati nesto od ili trebam samo dodati???

Molimte posalji email na [email protected] ili hit me on skype: darko.nedelkovski

Pozdrav i puno ti hvala.

Puno ti hvala

Darko