OFFLINE-GmbH / oc-mall-plugin

:convenience_store: E-commerce solution for October CMS
https://offline-gmbh.github.io/oc-mall-plugin
MIT License
167 stars 112 forks source link

Make required signup/checkout user data more customizable #172

Open X3-STUDIO opened 5 years ago

X3-STUDIO commented 5 years ago

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

tobias-kuendig commented 5 years ago

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

papppeter commented 5 years ago

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?

X3-STUDIO commented 5 years ago

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 notifications@github.com 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.

tobias-kuendig commented 5 years ago

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.

shahnawab commented 4 years ago

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

tobias-kuendig commented 4 years ago

I'm consolidating a few issues into this:

Dabani commented 3 years ago

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!

anik1ng commented 3 years ago

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']);
    });
}

}


3. Next in boot() method our Plugin:
`/plugins/author/mallextend/Plugin.php`
```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.

Dabani commented 3 years ago

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 <notifications@github.com> a écrit :  

Look my instruction to add custom field to user profile.

<?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']);
    });
}

}

...

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;
        }
    });
});

}

... 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.

Zmove commented 3 years ago

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.