oc-mall-plugin icon indicating copy to clipboard operation
oc-mall-plugin copied to clipboard

Make required signup/checkout user data more customizable

Open X3-STUDIO opened this issue 5 years ago • 10 comments

Is it possible add more user info? For example birth date, telephone number, Vat number, etc, during the registration of that user? Thank you!

X3-STUDIO avatar Apr 01 '19 13:04 X3-STUDIO

You can extend the signup partials and add your fields. Then use the mall.customer.afterSignup event to add these fields to the database:

https://offline-gmbh.github.io/oc-mall-plugin/development/events.html#customer

tobias-kuendig avatar Apr 01 '19 14:04 tobias-kuendig

Hi,

could you add telephone as a default customer info? or could you point it out what would be the best use case for this to do it with the event system? i am new to octobercms that is the reason i am asking basic questions as well.

aftersignup does not look good to me, there is no real possibility to do the validtion checks. i use both before, after signup than it looks little bit better, but still i miss the main validation process.

maybe it would be good to add more basic fields which can be turned on of from config area? what do you think would it be worth creating that area?

papppeter avatar Jun 03 '19 21:06 papppeter

Hi!Personally I think that telephone number is an important field for an e-commerce.I would put it in registration form (required or optional) if possible. Than it could be edited in account info.I think that is possible make a validation extending aftersignup function, but I'm not really an expert in it.I can take a look in the next days, but i promise no solutions.Is telephone validation so essential? Theoretically the format can be correct, but number wrong the same. Il lunedì 3 giugno 2019, 23:08:52 CEST, Papp Péter [email protected] ha scritto:

Hi,

could you add telephone as a default customer info? or could you point it out what would be the best use case for this to do it with the event system? i am new to octobercms that is the reason i am asking basic questions as well.

aftersignup does not look good to me, there is no real possibility to do the validtion checks. i use both before, after signup than it looks little bit better, but still i miss the main validation process.

maybe it would be good to add more basic fields which can be turned on of from config area? what do you think would it be worth creating that area?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

X3-STUDIO avatar Jun 04 '19 13:06 X3-STUDIO

Adding unnecessary fields to the signup form may increase bounce rates and might lead to problems for users that have to be GDPR compliant. You essentially want to save as little information as possible in this case.

I do, however, see the need to have the option to have further fields available. I think the best implementation is to toggle them on/off via the backend and maybe provide some customer validation rules. This should cover more bases.

If further customization is needed the event system can be used.

tobias-kuendig avatar Jun 17 '19 15:06 tobias-kuendig

If User Address Form is customizable like Custom Fields from backend then it will be very good.

shahnawab avatar Nov 01 '19 12:11 shahnawab

I'm consolidating a few issues into this:

  • Validation during signup/signin needs to be easier to customize, without having to register a custom Signup/Signin handler implementation. (https://github.com/OFFLINE-GmbH/oc-mall-plugin/issues/283)
  • It should be possible to place an order without specifying unnecessary information like a shipping address if only virtual products are bought (https://github.com/OFFLINE-GmbH/oc-mall-plugin/issues/390)
  • There are shipping methods that don't require a shipping address (store pickup), enable this possibility (https://github.com/OFFLINE-GmbH/oc-mall-plugin/issues/54)
  • It should be possible to add additional fields during checkout, maybe a jsonable field is already enough for this (this issue)

tobias-kuendig avatar Jan 08 '20 09:01 tobias-kuendig

ADD SOME FIELDS TO MALL CUSTOMER PROFILE

Five steps to add some fields: Assuming that we want to add two fields (Telephone and VAT)

  1. Install Rainlab User Plus plugin

  2. Go to Plugin -> Rainlab -> userplus -> lang -> en -> lang.php Modify line 13: change "Mobile" to "TIN/VAT" (This modifies the label of the mobile field on the backend form, the field telephone is already provided by UserPlus plugin)

  3. Go to Plugin -> Offline -> mall -> components -> customerprofile -> default.htm Add the following code above line {% if user.customer.is_guest %}

    <div class="mall-two-fields">
        <div class="mall-form-control">
            <label for="phone">{{ 'offline.mall::frontend.form.phone' | trans }}</label>
            <input id="phone" type="tel" placeholder="Telephone" name="phone" value="{{ __SELF__.user.phone }}">
            <div data-validate-for="phone"></div>
        </div>
        <div class="mall-form-control">
            <label for="tin">{{ 'offline.mall::frontend.form.tin' | trans }}</label>
            <input id="tin" type="tel" placeholder="TIN/VAT" name="tin" value="{{ __SELF__.user.mobile }}">
            <div data-validate-for="tin"></div>
        </div>
    </div>
  1. Go to Plugin -> Offline -> mall -> components -> CustomerProfile.php Modify the onSubmit function as following:

    1. Add to the $neededRules array items 'phone', 'phone', after 'email'

    2. Add to the DB::transaction block the following lines of code after email

        $this->user->phone               = $data['phone'];
        $this->user->mobile              = $data['tin'];
      
  2. Go to Plugin -> Offline -> mall -> lang -> en -> frontend.php Add the following entries after 'form.email' => 'E-mail',

    'form.phone' => 'Telephone', 'form.tin' => 'TIN/VAT',

You are now done!

REMARK:

If you are using multiple languages, then update other language as you need in steps 2 and 5.

If in the future you update User Plus and Mall plugins you may loose these changes, so we exhort the Offline Team to take in consideration the need to add more fields without a requirement to make some hacking like the one provided above.

However we must make credit to the exceptional job done by Offline Team, Mall is the BEST E-commerce in the market!

Dabani avatar Sep 28 '20 07:09 Dabani

Look my instruction to add custom field to user profile.

  1. Create our plugin (php artisan plugin:create Author.MallExtend).

  2. Create migration to add phone field to User model: /plugins/author/mallextend/updates/table_users_add_phone_field.php

<?php namespace Author\MallExtend\Updates;

use Schema;
use October\Rain\Database\Schema\Blueprint;
use October\Rain\Database\Updates\Migration;

class TableUsersAddPhoneField extends Migration
{
    const TABLE_NAME = 'users';

    public function up()
    {
        if (!Schema::hasTable(self::TABLE_NAME) || Schema::hasColumn(self::TABLE_NAME, 'phone')) {
            return;
        }

        Schema::table(self::TABLE_NAME, function (Blueprint $obTable) {
            $obTable->string('phone')->nullable();
        });
    }

    public function down()
    {
        if (!Schema::hasTable(self::TABLE_NAME) || !Schema::hasColumn(self::TABLE_NAME, 'phone')) {
            return;
        }

        Schema::table(self::TABLE_NAME, function (Blueprint $obTable) {
            $obTable->dropColumn(['phone']);
        });
    }
}
  1. Next in boot() method our Plugin: /plugins/author/mallextend/Plugin.php
use Input;
use RainLab\User\Controllers\Users;
use RainLab\User\Models\User;

...

public function boot()
{
    // add form field to Backend form
    Users::extendFormFields(function($form, $model, $context) {
        if (!$model instanceof User) {
            return;
        }

        $form->addFields([
            'phone' => [
                'label'    => 'Phone',
                'required' => true,
                'span'     => 'auto'
            ],
        ]);
    });

    User::extend(function ($model) {
        $model->addFillable(['phone']); // create field fillable, without you can not save field
        $model->rules['phone'] = 'required'; // validation rule

        // Before validate User model, add phone attribute value from post form data
        $model->bindEvent('model.beforeValidate', function() use ($model) {
            if (Input::has('phone')) {
                $phone = Input::get('phone');
                $model->phone = $phone;
            }
        });
    });
}
  1. Copy /plugins/offline/mall/components/customerprofile/default.htm to your theme partial folder (/theme/default/partials/customerprofile/default.htm) and add phone field:
...

<div class="mall-form-control">
    <label for="phone">Phone</label>
    <input id="phone" type="phone" name="phone" value="{{ __SELF__.user.phone }}">
    <div data-validate-for="phone"></div>
</div>

...

It's done ;)

p.s. you can update User or Mall plugins, you not loose these changes.

anik1ng avatar Dec 03 '20 06:12 anik1ng

Thanks Constantine, I found this amazing stuff very useful!

Best regards!

Robert MAKUTASystem Analyst & Web DeveloperKigali - RWANDA +250 788 554 939

Le jeudi 3 décembre 2020 à 08:24:26 UTC+2, Constantine Anikin <[email protected]> a écrit :  

Look my instruction to add custom field to user profile.

Create our plugin (php artisan plugin:create Author.MallExtend).

Create migration to add phone field to User model:
/plugins/author/mallextend/updates/table_users_add_phone_field.php

string('phone')->nullable(); }); } public function down() { if (!Schema::hasTable(self::TABLE_NAME) || !Schema::hasColumn(self::TABLE_NAME, 'phone')) { return; } Schema::table(self::TABLE_NAME, function (Blueprint $obTable) { $obTable->dropColumn(['phone']); }); } } - Next in boot() method our Plugin: /plugins/author/mallextend/Plugin.php use Input; use RainLab\User\Controllers\Users; use RainLab\User\Models\User; ... public function boot() { // add form field to Backend form Users::extendFormFields(function($form, $model, $context) { if (!$model instanceof User) { return; } $form->addFields([ 'phone' => [ 'label' => 'Phone', 'required' => true, 'span' => 'auto' ], ]); }); User::extend(function ($model) { $model->addFillable(['phone']); // create field fillable, without you can not save field $model->rules['phone'] = 'required'; // validation rule // Before save User model, add phone attribute value from post form data $model->bindEvent('model.beforeSave', function() use ($model) { if (Input::has('phone')) { $phone = Input::get('phone'); $model->phone = $phone; } }); }); } - Copy /plugins/offline/mall/components/customerprofile/default.htm to your theme partial folder (/theme/default/partials/customerprofile/default.htm) and add phone field: ...
... It's done ;) p.s. you can update User or Mall plugins, you not loose these changes. — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

Dabani avatar Dec 03 '20 07:12 Dabani

Very interested by this issue. For the phone number, I think it make more sense to attach it to the address model than the user model, cause you can manage several addresses in your addressbook, which can lead to different phones numbers.

Zmove avatar Jan 27 '21 07:01 Zmove