Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to register a new user using Shopify mobile buy sdk ?

    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 655
    Comment on it

    In previous blog we learn how to login in shopify from android app, now we already have sample application class to maintain buy client session so in this blog we learn how to create a new user account in your shop.

    xml layout file for registration :

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:orientation="vertical"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context="com.android.allvino.Activities.RegistrationActivity">
    
        <LinearLayout
            android:id="@+id/registration_layout"
            android:layout_width="300dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:gravity="center"
            android:orientation="vertical"
            android:visibility="visible">
    
            <android.support.design.widget.TextInputLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="@dimen/spacing_6dp">
    
                <EditText
                    android:id="@+id/etRegEmail"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="@string/hint_email"
                    android:inputType="textEmailAddress"
                    android:singleLine="true"/>
    
            </android.support.design.widget.TextInputLayout>
    
            <android.support.design.widget.TextInputLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="@dimen/spacing_6dp"
                android:layout_marginTop="@dimen/spacing_6dp">
    
                <EditText
                    android:id="@+id/etRegPswdl"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="@string/hint_pswd"
                    android:inputType="textPassword"
                    android:singleLine="true"/>
    
            </android.support.design.widget.TextInputLayout>
    
            <android.support.design.widget.TextInputLayout
                android:id="@+id/registration_first_name_input_layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="@dimen/spacing_6dp"
                android:layout_marginTop="@dimen/spacing_6dp">
    
                <EditText
                    android:id="@+id/etRegFname"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="@string/hint_fname"
                    android:inputType="text|textCapWords|textNoSuggestions"
                    android:singleLine="true"/>
    
            </android.support.design.widget.TextInputLayout>
    
            <android.support.design.widget.TextInputLayout
                android:id="@+id/registration_last_name_input_layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="@dimen/spacing_6dp"
                android:layout_marginTop="@dimen/spacing_6dp">
    
                <EditText
                    android:id="@+id/etRegLname"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="@string/hint_lname"
                    android:inputType="text|textCapWords|textNoSuggestions"
                    android:singleLine="true"/>
    
            </android.support.design.widget.TextInputLayout>
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal"
                android:orientation="horizontal">
    
                <Button
                    android:id="@+id/btnCancel"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/text_cancel"/>
    
                <Button
                    android:id="@+id/btnSignup"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/text_signup"/>
    
            </LinearLayout>
        </LinearLayout>
    </LinearLayout>
    

    Now in our registration activity we will have to create account credentials like we did in login activity like this :

    after entering first name, last name, email and password we will perform following task on signup button click :

    mCredentials = new AccountCredentials(etRegEmail.getText().toString(), etRegPswdl.getText().toString(),etRegFname.getText().toString(),etRegLname.getText().toString());
    
    createCustomerTask =  SampleApplication.getBuyClient().createCustomer(mCredentials, new Callback<Customer>() {
        @Override
        public void success(Customer customer) {
            Log.e("customer reg :", customer.toJsonString());
            SampleApplication.setCustomer(customer);
            Log.e("customer reg token :", SampleApplication.getBuyClient().getCustomerToken().getAccessToken().toString());
            Log.e("customer reg id :", SampleApplication.getBuyClient().getCustomerToken().getCustomerId().toString());
            Toast.makeText(RegistrationActivity.this, "Sucess",Toast.LENGTH_LONG).show();
    
        }
        @Override
        public void failure(BuyClientError error) {
            Log.e("login error:", error.getRetrofitErrorBody());
            hideProgress();
            Toast.makeText(RegistrationActivity.this, AppConstant.sRegFailed, Toast.LENGTH_LONG).show();
        }
    });

    So this is the way user can create a new account on shopify.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: