使用simplecartjs在结账前添加功能

时间:2016-12-06 06:39:37

标签: javascript jquery simplecart

我使用Simplecartjs,我发现他们有自定义来添加功能beforeCheckout。

<script>
//<![CDATA[
simpleCart({

    // array representing the format and columns of the cart, see 
    // the cart columns documentation
    cartColumns: [
        {view:"image" , attr:"thumb", label: false },
        { attr: "name" , label: "Name" },
        { attr: "price" , label: "Price", view: 'currency' },
        { view: "decrement" , label: false },
        { attr: "quantity" , label: "Qty" },
        { view: "increment" , label: false },
        { attr: "total" , label: "SubTotal", view: 'currency' },
        { view: "remove" , text: "Remove" , label: false }
    ],

    // "div" or "table" - builds the cart as a table or collection of divs
    cartStyle: "div", 

    // how simpleCart should checkout, see the checkout reference for more info 
    checkout: { 
        type: "PayPal" , 
        email: "you@hello.com" 
    },

    // set the currency, see the currency reference for more info
    currency: "USD",

    // collection of arbitrary data you may want to store with the cart, 
    // such as customer info
    data: {},

    // set the cart langauge (may be used for checkout)
    language: "english-us",

    // array of item fields that will not be sent to checkout
    excludeFromCheckout: [],

    // custom function to add shipping cost
    shippingCustom: null,

    // flat rate shipping option
    shippingFlatRate: 0,

    // added shipping based on this value multiplied by the cart quantity
    shippingQuantityRate: 0,

    // added shipping based on this value multiplied by the cart subtotal
    shippingTotalRate: 0,

    // tax rate applied to cart subtotal
    taxRate: 0,

    // true if tax should be applied to shipping
    taxShipping: false,

    // event callbacks 
    beforeAdd               : null,
    afterAdd                : null,
    load                    : null,
    beforeSave              : null,
    afterSave               : null,
    update                  : null,
    ready                   : null,
    checkoutSuccess             : null,
    checkoutFail                : null,
    beforeCheckout              : null
});
//]]>
</script>

但我不知道如何为它添加新功能。写新脚本?例如,添加功能以警告5s内容:“您正在重定向到PayPal”,然后重定向到Paypal。

非常感谢你。

1 个答案:

答案 0 :(得分:1)

包括这个

simpleCart.bind( 'beforeCheckout' , function( data ){
    alert('You are redirecting to Paypal');
});

with timeOut看起来像这样:

simpleCart.bind( 'beforeCheckout' , function( data ){
    setTimeout(function(){
        alert('You are redirecting to Paypal')
    }, 5000); // 5 seconds
});

在最后一个.js文件的末尾或创建一个新的.js文件,其中包含最后一个文件: