簡體   English   中英

Shopify / Liquid - 重命名錯誤“必需參數丟失或無效”

[英]Shopify / Liquid - rename the error "Required parameter missing or invalid"

在我的 shopify 網站(Debut 主題)上,當用戶在沒有選擇尺碼的情況下單擊“添加到購物車”按鈕時,它會顯示此消息:“必需參數丟失或無效:項目”。

我想將此消息改寫為更友好的措辭,例如“請選擇尺碼”。

我將如何實現這一目標? 我假設它是一個流動性問題,但不確定是否也可能與 javascript 相關。 謝謝。

打開assets/theme.js並搜索response.responseJSON.description 它應該與_addItemToCart方法一起使用。 添加以下內容.replace("Required parameter missing or invalid: items", "Please pick a size") 所以在這個改變之后整個方法應該如下所示:

_addItemToCart: function(data) {
  var params = {
    url: '/cart/add.js',
    data: $(data).serialize(),
    dataType: 'json'
  };

  $.post(params)
    .done(
      function(item) {
        this._hideErrorMessage();
        this._setupCartPopup(item);
      }.bind(this)
    )
    .fail(
      function(response) {
        this.$previouslyFocusedElement.focus();
        var errorMessage = response.responseJSON
          ? response.responseJSON.description.replace("Required parameter missing or invalid: items", "Please pick a size")
          : theme.strings.cartError;
        this._showErrorMessage(errorMessage);
        this._handleButtonLoadingState(false);
      }.bind(this)
    );
},

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM