How to detect, whether custom field is rendered in order backend or email?

Started by gba, December 09, 2020, 18:51:28 PM

Previous topic - Next topic

gba

Hello!

I want to display my custom field not in the frontend, not in the order emails, but in the order backend, only.
For the frontend the function plgVmDisplayInOrderFEVM3() is fired and for backend+emails the function plgVmDisplayInOrderBEVM3(), right?

But how can I detect, whether my custom field is being rendered in order backend or in an email, in function plgVmDisplayInOrderBEVM3()?
Thank you very much in advance for any useful hint!

Kind regards,
Gerald

AH

Maybe you should create yourself a new vmcustom - "customfield" plugin. 

You can then just handle the plgVmDisplayInOrderBEVM3() trigger to do exactly what you want (e.g. do nothing for any of the other triggers)

or create your own triggers and make a view override in the BE order display

   public function plgMYTriggerOnViewOrderBE($vars){

Or is this somewhere you don't want to go?

It really depends on what business function you want it to be used for - but you have not given any hint as to that in your post.

Regards
A

Joomla 4.4.5
php 8.1

gba

Thank you for your reply!

I am actually talking about a custom field plugin I am creating.
In this plugin I have the function plgVmDisplayInOrderFEVM3(), which is being triggered for order backend and for e-mails.
In this function I need a way to distinguish the use case - order backend or e-mail.
How can I find out, whether my custom field is being rendered in order backend or in an email?

AH

Would it not be simpler to describe what you want rather than how you think it should work

If you have your own plugin - you can use better triggers than FE
Regards
A

Joomla 4.4.5
php 8.1

gba

I want to differently render my custom field in three different template overrides:
- order detail view in FE
- order detail view in BE
- order e-mail

For order detail in FE I call VirtueMartModelCustomfields::CustomsFieldOrderDisplay($product,'FE').
That triggers the function plgVmDisplayInOrderFEVM3() in my custom field plugin, where I generate the output.

For order detail in BE I call VirtueMartModelCustomfields::CustomsFieldOrderDisplay($product,'BE').
That triggers the function plgVmDisplayInOrderBEVM3() in my custom field plugin, where I generate the output.

At the moment in the order e-mail override I also call VirtueMartModelCustomfields::CustomsFieldOrderDisplay($product,'BE').
So my approach was to generate different output in function plgVmDisplayInOrderBEVM3(), depending on being triggered in the order detail view in BE or in the order e-mail.

But if there was another or even better way to reach my goal, I'd be very greatful for any idea.

AH

Ok that is more informative

You can easily create your own triggers to do what you require and because you already override templates - it is even easier for you as you can fire the triggers when you want in the template overrides and get your plugin to return/do what you need

I thing your plugin extends vmCustomPlugin - so should be loaded by default. if not you can load your plugin.

Rather than using standard plugin calls - you can create your own to fire in the overrides

You can then get these to do whatever you need

Just load the plugin in the view you want render your output (if theses are customfields and you have a customfield plugin - then your plugin and triggers should already be loaded)

This gets your plugin loaded if it is not already, and allows you to fire triggers - note that this may already be loaded and the $dispatcher could also be your own name

JPluginHelper::importPlugin('vmcustom');  // you might not need to do this
$dispatcher = JDispatcher::getInstance(); // you might not need to do this
[code]

Once you know your plugin is loaded - then you can initiate your specific triggers


Your specific triggers may be something like this:
$fe = $dispatcher->trigger('MYOWNTRIGGERFE', $datathetriggerFEmayneed);
$be = $dispatcher->trigger('MYOWNTRIGGERBE', $datathetriggermayneed);
$fe_email = $dispatcher->trigger('MYOWNTRIGGEREMAIL', $datathetriggermayneed);[/code]

etc

Then in your customplugin you create the trigger functions and get them to do what you need e.g.:

function MYOWNTRIGGERFE( $datathetriggerFEmayneed ) {
Your code
}

function MYOWNTRIGGERBE( $datathetriggerFEmayneed ) {
Your code
}

Regards
A

Joomla 4.4.5
php 8.1

gba


AH

Thanks - you are welcome - I hope it helps you get the job done :-)
Regards
A

Joomla 4.4.5
php 8.1