开发者

simpleCart - Modal window form and sending the shopping cart in a multidimensional array to php

I'm using the js cart simpleCart but am having a simple issue..

I have a modal pop up when the customer presses "checkout" and they have to fill in their contact details and what I have working is that the modal form on submit emails me with the filled information using the code (at the link below), however I can't figure out how to include in the same data array the shopping cart information (which I can expand on via PHP and make it look nice in their the email I receive).

Any ideas, I'm trying to get this dang thing finished asap? All and any help is apprec开发者_JAVA百科iated!

http://jsfiddle.net/uDS7A/

Cart I'm using is https://github.com/wojodesign/simplecart-js or simplecartjs.com


If you want an easy option, serialize simpleCart.items as JSON and submit that to the server. If you want to be cross-browser friendly, include the json2.js library in your page to support JSON.stringify() in older browsers. The implementation might look like this:

// redefine the emailCheckout method
simpleCart.emailCheckout = function() {
    $.post(
        // url
        "core/orderSubmission.php",
        // data, serialized as JSON
        { items: JSON.stringify(simpleCart.items) },
        // success function
        function(msg) {
            // do some stuff on success
        }
    )
};

(Note that we're declaring the method on the simpleCart instance, so you can keep this code out of the simplecart.js library. Don't ever edit library code if you can help it - it makes it super-difficult to manage library updates.)

Then in PHP you can use something like

$items = json_decode($_POST['items']);

to decode the data into an array you can format.

This all assumes that simpleCart is correctly bound to your form and will be automatically updated as the user selects items for the cart - I think that's the way it's supposed to work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜