Redirect 购物车页面上的Bigcommerce重定向

Redirect 购物车页面上的Bigcommerce重定向,redirect,cart,bigcommerce,Redirect,Cart,Bigcommerce,在bigcommerce中将自定义脚本添加到my cart.html文件中,以包含一个脚本,该脚本将在持卡人单击“签出”时将其重定向到google.com(目前仅在测试脚本时转到google) 加载脚本时,我在控制台中看到以下错误(self.checkoutatton.on不是函数) 这是脚本+文件 cart: true <script> document.addEventListener("DOMContentLoaded", function () {

在bigcommerce中将自定义脚本添加到my cart.html文件中,以包含一个脚本,该脚本将在持卡人单击“签出”时将其重定向到google.com(目前仅在测试脚本时转到google)

加载脚本时,我在控制台中看到以下错误(self.checkoutatton.on不是函数)

这是脚本+文件

cart: true
<script>
  document.addEventListener("DOMContentLoaded", function () {

    var debug = true ? console.log.bind(console, '[DEBUG][Cart]') : function () {};

    debug('Script loaded');

    window.Cart = function (options) {


      var self = {}
      function init() {
        self.options = Object.assign({
          checkoutButtonSelector: document.getElementById("checkout"),
          checkoutUrl: 'https://google.com',
        }, options);

        self.checkoutButton = (self.options.checkoutButtonSelector);

        debug('Initialized with options', self.options);
        
        
     
            inject();
       
      }


      function inject() {
        debug('Inject');
        self.checkoutButton.on('click', checkout);
      }


      function checkout(event) {
        var checkoutUrl = getCheckoutURL(self.options.products);
        debug('Checkout ->', checkoutUrl);
        event.preventDefault();
        window.location.href = checkoutUrl;
      }
      
      function getCartCookie(name) {
       var match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)'));
        if (match){ 
          return match[2];
          }
      }

      function getCheckoutURL(products) {
         cookie = getCartCookie('cart');
        var urlLineItems = Object.keys(products).reduce(function (output, productId) {
          var quantity = products[productId];
          return output.concat([ productId + ':' + quantity ]);
        }, []).join(';');

        return self.options.checkoutUrl + '?products=' + urlLineItems + '&cartId='+cookie;
      }



      init();

      return self;

    };

    var instance = new Cart();

  });

</script>








<div class="page">

    <main class="page-content" data-cart>
        {{> components/common/breadcrumbs breadcrumbs=breadcrumbs}}

        {{> components/cart/page-title}}

        <div data-cart-status>
            {{> components/cart/status-messages}}
        </div>

        {{#if cart.items.length}}
            <div class="loadingOverlay"></div>

            <div data-cart-content class="cart-content-padding-right">
                {{> components/cart/content}}
            </div>

            <div data-cart-totals class="cart-content-padding-right">
                {{> components/cart/totals}}
            </div>

            {{#if cart.show_primary_checkout_button}}
                <div class="cart-actions cart-content-padding-right">
                    <a class="button button--primary" id='checkout' title="{{lang 'cart.checkout.title'}}">{{lang 'cart.checkout.button'}}</a>
                    {{#if cart.show_multiple_address_shipping}}
                        <a class="checkoutMultiple" href="{{urls.checkout.multiple_address}}">
                            {{lang 'cart.preview.checkout_multiple'}}
                        </a>
                    {{/if}}
                </div>
            {{else}}
                <div class="cart-actions cart-content-padding-right">
                    <a class="button" href="{{urls.home}}" title="{{lang 'cart.continue_shopping'}}">{{lang 'cart.continue_shopping'}}</a>
                </div>
            {{/if}}

            {{#if cart.additional_checkout_buttons}}
                <div class="cart-additionalCheckoutButtons cart-content-padding-right">
                    {{#each cart.additional_checkout_buttons}}
                        {{{this}}}
                    {{/each}}
                </div>
            {{/if}}
        {{else}}
            <h3 tabindex="0">{{lang 'cart.checkout.empty_cart'}}</h3>
        {{/if}}

    </main>
</div>
{{/partial}}
{{> layout/base}}
cart:true
document.addEventListener(“DOMContentLoaded”,函数(){
var debug=true?console.log.bind(控制台,“[debug][Cart]”):函数(){};
调试(“脚本加载”);
window.Cart=函数(选项){
var self={}
函数init(){
self.options=Object.assign({
checkOutletOnSelector:document.getElementById(“签出”),
签出URL:'https://google.com',
},选项);
self.checkExputton=(self.options.checkExputttonSelector);
调试(“使用选项初始化”,self.options);
注入();
}
函数注入(){
调试(‘注入’);
self.checkoutton.on('click',checkout');
}
函数签出(事件){
var checkoutUrl=getCheckoutURL(self.options.products);
调试('Checkout->',checkoutUrl);
event.preventDefault();
window.location.href=签出URL;
}
函数getCartCookie(名称){
var match=document.cookie.match(新的RegExp('(^ |)'+name+'=([^;]+));
如果(匹配){
返回匹配[2];
}
}
函数getCheckoutURL(产品){
cookie=getCartCookie(“购物车”);
var urlLineItems=Object.keys(products).reduce(函数(输出,productId){
var数量=产品[productId];
返回output.concat([productId+':'+quantity]);
},[])。连接(“;”);
返回self.options.checkoutUrl+'?products='+urlLineItems+'&cartId='+cookie;
}
init();
回归自我;
};
var实例=新购物车();
});
{{>components/common/breadcrumbs breadcrumbs=breadcrumbs}
{{>组件/购物车/页面标题}
{{>组件/购物车/状态消息}
{{{#if cart.items.length}
{{>components/cart/content}
{{>components/cart/totals}
{{{如果购物车.显示{u主要}结帐}
{{/if}
{{else}
{{/if}
{{{#如果购物车。附加的{结帐}
{{{每个购物车。附加的{结帐}
{{{{this}}}
{{/每个}}
{{/if}
{{else}
{{lang'cart.checkout.empty_cart'}
{{/if}
{{/部分}
{{>layout/base}

你知道我为什么会出现以下错误吗?提前感谢

您正在使用上的,这是一个JQuery函数。您没有使用JQuery包装选择器,而是使用了普通的JS getElementById。您需要使用一个普通的JS函数来添加事件,例如addEventListener