December 18, 20187 yr 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 ?
December 20, 20187 yr Author AFAIK some overrides (or changes to the core files) are needed to write a module for this
December 20, 20187 yr 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 ?
December 20, 20187 yr 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.
December 20, 20187 yr 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 ?
December 21, 20187 yr @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)
December 29, 20187 yr 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
December 29, 20187 yr @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.
January 8, 20197 yr 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 ?
January 8, 20197 yr 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
January 8, 20197 yr @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.
January 9, 20197 yr @gandalf @gonssal I haven't thought in detail about it, but I would probably go the same way.
Create an account or sign in to comment