doulao5916 2011-07-13 01:48
浏览 57
已采纳

simpleCart - 模态窗口表单并将多维数组中的购物车发送到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 appreciated!

http://jsfiddle.net/uDS7A/

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

  • 写回答

1条回答 默认 最新

  • doumo0206 2011-07-13 03:38
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!