-1

我的 Shopify 客户注册流程有一个问题,我无法解决,我希望这里的人能对这个问题有所了解。

当客户在我们的 Shopify 网站上成功注册时,他们会被重定向到根/主页,这在一段时间内正是我们客户想要的。客户现在希望新注册的用户在成功注册后被带到帐户页面。

根据我的阅读,默认行为是将用户重定向到帐户页面,但由于某种原因,这对我们来说并没有发生。

查看标题似乎用户被发送到帐户页面,然后立即 302'd 到根。鉴于这不是默认行为,我想知道这是否是定制的,如果是定制的,在哪里?

我在我们的主题、代码、js 中找不到任何这样做的东西。

我完全糊涂了。

[编辑] shopify 中的注册表单

{% form 'create_customer' %}
    {{ form.errors | default_errors }}


    <div class="input-wrapper">
        <label for="FirstName" class="label-hidden">
            {{ 'customer.register.first_name' | t }}
        </label>
        <input type="text"
            name="customer[first_name]"
            id="FirstName"
            placeholder="{{ 'customer.register.first_name' | t }}"
            autofocus
            {% if form.first_name %}value="{{ form.first_name }}"{% endif %}>
    </div>

    <div class="input-wrapper">
        <label for="LastName" class="label-hidden">
            {{ 'customer.register.last_name' | t }}
        </label>
        <input type="text"
            name="customer[last_name]"
            id="LastName"
            placeholder="{{ 'customer.register.last_name' | t }}"
            {% if form.last_name %}value="{{ form.last_name }}"{% endif %}>
    </div>

    <div class="input-wrapper">
        <label for="Email" class="label-hidden">
            {{ 'customer.register.email' | t }}
        </label>
        <input type="email"
            name="customer[email]"
            id="Email"
            class="{% if form.errors contains 'email' %}input-error{% endif %}"
            placeholder="{{ 'customer.register.email' | t }}"
            value="{% if form.email %}{{ form.email }}{% endif %}"
            spellcheck="false"
            autocomplete="off"
            autocapitalize="off">
    </div>

    <div class="input-wrapper">
        <label for="CreatePassword" class="label-hidden">
            {{ 'customer.register.password' | t }}
        </label>
        <input type="password"
            name="customer[password]"
            id="CreatePassword"
            class="{% if form.errors contains 'password' %}input-error{% endif %}"
            placeholder="{{ 'customer.register.password' | t }}">
    </div>


    <div class="input-wrapper">
        <label for="PrivacyPolicy" class="label-hidden">
            <input type="checkbox"
            name="customer[note][Privacy Policy]"
            id="PrivacyPolicy"
            value="Accepted on {{ "now" | date: "%Y-%m-%d" }}" />
            I have read, understood and agree to the <a href="/pages/privacy-policy" target="_blank">Privacy Policy</a>.
        </label>
    </div>

    <div class="input-wrapper">
        <button disabled type="submit" class="button--primary" id="create_customer__submit">{{ 'customer.register.submit' | t }}</button>
    </div>

    <a href="{{ shop.url }}">{{ 'customer.register.cancel' | t }}</a>
{% endform %}

我已经看到建议添加以下内容作为可能的解决方法,但在我的情况下没有任何区别。

<input type="hidden" name="checkout_url" value="/account">

我可以通过检查员看到表单被发布到“/account”,然后重定向(302)到“/”

上面的表格呈现为

<form method="post" action="/account" id="create_customer" accept-charset="UTF-8">
    <input type="hidden" name="form_type" value="create_customer" />
    ....
    ....
    <div class="input-wrapper">
        <button disabled type="submit" class="button--primary" id="create_customer__submit">Create</button>
    </div>
</form>
4

3 回答 3

1

您可以使用 Ajax 发布表单,然后在成功时重定向到帐户页面。

下面给出的示例:

    $('form#create_customer').on('submit', function(event){
        //debugger;
        event.preventDefault();
        var postUrl = $(this).attr('action');
        var postData = $(this).serialize();

        //console.log(postData); check what your form posts

        $.ajax({
            type: "POST",
            url: postUrl,
            data: postData,
            dataType: "json",
            success: function(data) {
                console.log('Account created')
                 //redirect to somewhere
                 window.location.replace("/some-url");
            },
            error: function() {
                console.log('error handling here');
            }
        });
    });
于 2018-11-27T17:27:03.500 回答
0

我最终用 jquery 处理表单提交。我在 Shopify 网站上看到了一些示例,尤其是这个https://ecommerce.shopify.com/c/ecommerce-design/t/redirect-after-customer-registration-370825并对其进行了修改少量。我将以下内容放在注册帐户页面的底部,这是一种享受。

异步对我来说不是一个选项,但可能是某些人的答案。

(function() {
  'use strict';

  function handleSumission(event) {
    event.preventDefault();

    var data = $(this).serialize();

    $.post('/account', data)
      .done(function(data) {
        var errorsLog = $(data).find('.errors').text();

        // Show any errors that there may be
        if(errorsLog != "" && errorsLog  != 'undefined') {

          // Do error handling here

        } else {
          window.location.href = '/account';
        }
      })
        .fail(function() {
          // Tidy up if it fails
        });
  }

  function init() {
    $('#create_customer').on('submit', handleSumission);
  }

  window.addEventListener('load', init);

}());
于 2018-12-18T16:32:13.083 回答
0

这是我在注册后用于重定向用户的方法(有或没有验证码验证):

window.addEventListener("load", function (event) {
    var redirectInput = document.createElement('input'),
        registerSubmit = document.querySelector('#create_customer input[type="submit"]'),
        registerForm = document.querySelector('#create_customer'),
        captchaSubmit = document.querySelector('.shopify-challenge__container input[type="submit"]'),
        captchaForm = document.querySelector('#g-recaptcha');

    redirectInput.setAttribute('type', 'hidden');
    redirectInput.setAttribute('name', 'return_to');
    redirectInput.setAttribute('value', '/account'); //URL to redirect

    if (registerForm.length) {
        registerSubmit.insertAdjacentElement("beforebegin", redirectInput)
    } else if (captchaForm.length) {
        captchaSubmit.insertAdjacentElement("beforebegin", redirectInput)
    }

});
于 2020-06-05T00:31:16.133 回答