Skip to content
View in the app

A better way to browse. Learn more.

thirty bees forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

How to add custom fields without overrides

Featured Replies

Hi to all We need to add 2 custom fields during customer registration (just after date of birth) but without using overrides.

Is this possible ? Any workaround ?

  • Author

AFAIK some overrides (or changes to the core files) are needed to write a module for this

  • Author

@datakick said in How to add custom fields without overrides:

@gandalf why the no override requirement?

Because it's a perfect recipe for a disaster. Overriding core features is wrong, under any point of view. During a TB update you have to remember which modules are overriding which function and update these module accordingly and this is not always possible. You could have created an ovverride based on a function that is removed or changed in newer version and you can't bring that back without breaking everything else (discovered this in the worst way on a production ecommerce)

Probably, some hooks to be added in the core would do the trick without any overrides. As PS doesn't have any hook for doing this, i've thought that TB added something.

Maybe a pull-request would be accepted for this ?

without using overrides.

Looking up the templates, like themes/community-theme-default/identity.tpl or themes/community-theme-default/authentication-create.tpl, one can find a few hooks which allow extending these fields. Just search for hook.

During a TB update you have to remember which modules are overriding which function and update these module accordingly and this is not always possible.

Partially true. It's true that sloppily written overrides can mess up a lot. Especially those just copying the entire original method to change just a line or two. One can write better overrides, though: - Check in each invocation whether the module is actually enabled. - Write code for just the change and call the parent method for everything else.

That said, a solution using hooks is still the better choice. PS 1.7 removed overrides for a reason.

  • Author

@traumflug said in How to add custom fields without overrides:

Write code for just the change and call the parent method for everything else.

Exactly. This is what we do when we are forced to use overrides. But this is possible only if parent function can be called (before or after customization). If you need to customize something "in the middle" of parent function, you can't simply call the parent.

And, as Murphy's Law tells you, most of the time you need to customize the middle of the parent method :)

I've never seen "HOOKCREATEACCOUNT_FORM" before, any example on how to use this ? I don't think would be possible to use this hook to save additional data to the customer table, as this extra field won't be saved by the TB controller. Isn't it ?

@gandalf said in How to add custom fields without overrides:

Hi to all We need to add 2 custom fields during customer registration (just after date of birth) but without using overrides.

Is this possible ? Any workaround ?

If you have Panda template, you can add custom fonts (that is what we did)

I do not know if I read and understood everything correctly, my last sentence is probably the most important to note.

A free shop system for the general public. For special needs you can create / buy a module or use the overrides.

For me it is important that the basic system works. Custom things are a different story. Regional larger things may be an additional topic.

To integrate 2 fields for registration, you must either write a module yourself or buy a suitable one or use overrides.

I'm sorry, that's my personal opinion. That's a minor matter. What's wrong with taking notes on your own customizations / overrides or overwriting the affected files directly? Before each update, you should anyway create backup and test before. I know, it does not always work. Hence the backup from the backup.

Finally, I would like to add: - Overwrite the core files and put them into the database works only partially (why and a mandatory field?) - custom fields ----> - Login - account - invoice - pdf - back office - .... ------> standard theme, panda theme, or warhouse theme etc -> = does not work in the basic system for everything else, it does not matter

@gandalf the Customer class extends ObjectModel, which provides multiple hooks through the object lifecycle.

In your case you would be interested in actionObjectCustomerAddAfter and actionObjectCustomerUpdateAfter. Probably also actionObjectCustomerUpdateAfter to clean leftover data.

  • 2 weeks later...
  • Author

@gonssal said in How to add custom fields without overrides:

@gandalf the Customer class extends ObjectModel, which provides multiple hooks through the object lifecycle.

In your case you would be interested in actionObjectCustomerAddAfter and actionObjectCustomerUpdateAfter. Probably also actionObjectCustomerUpdateAfter to clean leftover data.

How would you use this hook to add, let's say, 2 mandatory custom fields in the customer registration form ? Can you make me an example ?

  • Author

My only idea is to add some fields in the customer registration form. Via Javascript, on form submit, take these fields value, concatenate on an existing filed (so that it will be submitted with anything else) and, with some actionObjectCustomerAddBefore and actionObjectCustomerUpdateBefore split these concatenated fields, save properly in DB and let everything else flow through.

Just a proof-of-concept

@gandalf well the Javascript way is an option, not ideal and easily broken depending on the user's input, but could work.

I would probably combine the already mentioned tpl/form hooks, the actionCustomerAccountAdd hook and the other hooks provided by ObjectModel.

No, I can't make an example, sorry.

It's also very likely there's at least a module that already implements this without overrides.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.