Prestashop 1.7 hookActionObjectCustomerUpdateBefore and after - hook

So, I'm wondering why if I put a variable (public) in the hook hookActionObjectCustomerUpdateBefore and read it, then in the hook hookActionObjectCustomerUpdateAfter I lose it. Even if I assign it as smarty variable.
I'm running these hooks from a module and in backend.
Thanks for your tips.

To add a public variable on Customer class, you should override this class and add your custom variable. then you can use it every where on PrestaShop.
You can't use "action hooks" to add new definitions to PrestaShop. these hooks are made just for the actions.

Related

Fluid variables do not read the child values anymore. (TYPO3 9.5.*)

So i have a table which lists some appointments. These appointments belong to an event. The goal here is to list all the appointments and get the information of the event that they belong to.
So far everything works fine until i try to get the information of the event. I get an object which looks like this:
Now if i use something like this : {appointment.event.title} it will give back NULL.
That means that it doesnt access the properties. In TYPO3 v8 it works perfectly, but not in TYPO3 v9.
If i activate the <f:debug>{appointment}</f:debug> and get the whole object as debugged, then this {appointment.event.title} works! I can get the title.
The question now is what have changed since TYPO3 8 and can not access these properties anymore and how can i regain access?
In use: TYPO3 v9
Mode: Composer
Best regards,
I found the solution to my problem.
Thanks to #Claus Due i visited my Model to see if the getters und setters are there. They were there BUT before my getter, the #lazy parameter was present. After i removed, everything worked as it should.
Thank you!
Probably one of the following is true:
You forgot to add a getter method for the property you try to access and you are confusing the output of f:debug with what is actually gettable from the object. The debug ViewHelper outputs also protected properties.
You constructed the model object with __call or __get so you are affected by https://github.com/TYPO3/Fluid/pull/438 which is solved but not yet released (current Fluid version is 2.6.0, patch will be included in next version).
You don't say which TYPO3 version you use, nor if you are using composer, so it's hard to tell if your versions of Fluid are the same - they should be, since both TYPO3 v8 and TYPO3 v9 use the same external Fluid library.
The solution in either case is to add proper getter methods to your domain model object and always remember that the output of f:debug does not 100% correspond to what you can actually access: f:debug will for example not show virtual getter methods that don't have a property associated with it.

What is the best practice for overriding strings in Orchard CMS?

I often have the situation where the wording of specific strings from various modules or core features needs to be changed for specific tenants & themes in Orchard CMS.
For example, I may have a client that prefers to have the shopping cart checkout button say "Checkout Now" rather than "Go to checkout" which is a string contained within a view in a shopping module.
I can simply override the razor view in my theme and change the string, however views often are quite complex, and it doesn't feel right overriding a view just to change one string.
Another approach I have tried is to define a po translation file within my theme to override the string from the module. This works because the strings in the module are defined using the T() syntax. However, I've noticed that as soon as I define an override for a string within my theme, this override effects all tenants, instead of just the one tenant that has this theme enabled. I'm inclined to think that translations within modules/themes should be ignored from tenants where they are not enabled.
So I'm left wondering what the best approach for this scenario is?
The localisation/po file approach would be ok if tenants ignored po files from themes that aren't enabled, but then again, it would be really nice if there was a module or feature in core that allowed you to specify string overrides via the admin interface. I guess it's more of a "rewording" task than a "translation" task.
The preferred way of doing this is through template overrides. If you don't want to do that, you can actually break shapes down, and delegate the rendering to smaller templates that are easier to override. This is done by simply refactoring the part of a template that you want to be able to override individually into a separate template. This post explains how to do that: http://weblogs.asp.net/bleroy/creating-shapes-on-the-fly
If you're not willing to do that, you can use this module to get strings from the database instead of po files: http://gallery.orchardproject.net/List/Modules/Orchard.Module.Q42.DbTranslations It should be possible to modify it to fit your sceanrio.

Adding new section in control panel of Liferay

I want to add a new section in control panel of liferay and within that section I want to have my custom-portlet. I did it using ext. However I want to do it with hook . Is it possible ?
I don't think it would be that easy with a hook, because of the following reasons:
You can't modify in a Hook - the class com.liferay.portal.util.PortletCategoryKeys which contains the keys for displaying the different sections. The different sections are hard-coded in this class in a String array ALL.
You can't modify the logic of PortalImpl#isControlPanelPortlet() which uses the PortletCategoryKeys#ALL to determine if the request in question is for a control panel portlet.
Then you also have another method which you can't modify with a Hook and is used extensively PortalImpl#getControlPanelCategory()
Doing it with a hook:
I have not tried this but I think if you need to do it with a hook you would have to change all those JSPs which make use of PortletCategoryKeys#ALL and the methods of PortalImpl as stated above, and provide your custom implementation for all these methods in the JSP.
I would really like to know how you implemented it with an EXT may be just the steps or the methods you have overridden. So that I can try to convert those in terms of a hook.
This is as far as my understanding goes. Hope this helps.
With the advent of Marketplace, ControlPanel has a new category named "Marketplace" and that section is introduced in a plugin. However, I never checked if 6.1 GA2 introduced a new section that this plugin just fills. Check the marketplace plugin if you can find a trace of this section implemented there.
On the other hand, nobody has yet named any section that definitely required a new section (though some have asked me how to solve the same problem). For this reason, you might want to re-think the requirement and choose one of the existing sections. If you don't, at least I'd be interested in the name and purpose of the new section - I might find a first one actually justifying this kind of implementation...

How add custom method and fields to Liferay User model class

I want to add 3 more methods and one field to liferay.portal.model.User class. Anyone knows how can I do this? Can I switch the class by hook like this:
<service>
<service-type>com.liferay.portal.model.User</service-type>
<service-impl>my.pack.userExpanded</service-impl>
</service>
I want to have a close look at service builder but can't find good sources which will show how to switch liferay class with my own class (cause of too many uses).
So second question is does anyone know about some good tutorial or blogs regarding this? Especially I am interested in adding extra methods and fields.
The standard Liferay Developer Documentation is good:
http://www.liferay.com/documentation/liferay-portal/6.1/development/-/ai/overriding-a-portal-servi-4
Another alternative is to add Custom Fields to User entity:
You can't modify a liferay entity. Neither you can use hook to modify these things, hook can only modify limited things as suggested by the documentation.
I don't think you can even use a EXT to modify a liferay entity.
So now the what comes to my mind remains is to create custom-fields for your field requirement and build a helper utility class which will provide you with your required User methods.
You can make the helper class available to the portal by packaging in a jar and pasting it in the global path (in tomcat [TOMCAT_HOME]/lib/ext).

What is PortletURLListener used for? And can I make use of it in a hook?

Can somebody give me a use case as to how can the PortletURLListener be used? if it can be used at all?
Like we have ModelListener can we also use PortletURLListener?
Just like in ModelListener we can inject functionality on creation of a model, on update of a model or on delete and so on.
So can we use the PortletURLListener the same way like ModelListener to do
something when a specific URL is called? Any other approach if not PortletURLListener? Since the name is such I thought that could be of help.
And can we use it in a hook? or it is just used by Liferay? Any other practical usecase you have seen or implemented by extending or using this class?
Thanks in advance.
Thanks Mark for the prompt :-)
The PortletURLListener is used e.g. for deploying and undeploying by Liferay core. For more details see Liferay sources for PortletHotDeployListener:
https://github.com/liferay/liferay-portal/blob/master/portal-impl/src/com/liferay/portal/deploy/hot/PortletHotDeployListener.java
Answer after Update:
You can create hook and put servlet.service.events.post=com.my.MyAfterChangeAction propery to the portal.properties. The MyAfterChangeAction class must implements com.liferay.portal.kernel.events.Action.

Resources