Page 1 of 1
[SOLVED] Checking if an extension is enabled in a template file
Posted: Sun Jan 07, 2024 12:11 am
by Cue4cheap
OC 2.3.0.2.
Sorry not feeling well and I had a quick change that I thought was simple but it isn't working (brain fog?).
I would like to make a change to the checkout.tpl file.
I was trying to add a small amount of code only if the square payment extension was enabled. So I put this code in the checkout.tpl file.
<?php if ($this->config->get('squareup_status')) {
Echo 'Square is in testing mode only - please don't use.';
} ?>
It gives me "Call to a member function get() on null"
What am I missing?
Mike
Re: Checking if an extension is enabled in a template file
Posted: Sun Jan 07, 2024 1:13 am
by straightlight
Cue4cheap wrote: ↑Sun Jan 07, 2024 12:11 am
OC 2.3.0.2.
Sorry not feeling well and I had a quick change that I thought was simple but it isn't working (brain fog?).
I would like to make a change to the checkout.tpl file.
I was trying to add a small amount of code only if the square payment extension was enabled. So I put this code in the checkout.tpl file.
<?php if ($this->config->get('squareup_status')) {
Echo 'Square is in testing mode only - please don't use.';
} ?>
It gives me "Call to a member function get() on null"
What am I missing?
Mike
You could change the extension title directly from the language file instead of adding a code to display a text in the checkout.tpl file.
Re: Checking if an extension is enabled in a template file
Posted: Sun Jan 07, 2024 1:21 am
by Cue4cheap
straightlight wrote: ↑Sun Jan 07, 2024 1:13 am
Cue4cheap wrote: ↑Sun Jan 07, 2024 12:11 am
OC 2.3.0.2.
Sorry not feeling well and I had a quick change that I thought was simple but it isn't working (brain fog?).
I would like to make a change to the checkout.tpl file.
I was trying to add a small amount of code only if the square payment extension was enabled. So I put this code in the checkout.tpl file.
<?php if ($this->config->get('squareup_status')) {
Echo 'Square is in testing mode only - please don't use.';
} ?>
It gives me "Call to a member function get() on null"
What am I missing?
Mike
You could change the extension title directly from the language file instead of adding a code to display a text in the checkout.tpl file.
Understood but wish to use that example for other things later so would like a working example.
Thank you,
Mike
Re: Checking if an extension is enabled in a template file
Posted: Sun Jan 07, 2024 1:27 am
by straightlight
Cue4cheap wrote: ↑Sun Jan 07, 2024 1:21 am
straightlight wrote: ↑Sun Jan 07, 2024 1:13 am
Cue4cheap wrote: ↑Sun Jan 07, 2024 12:11 am
OC 2.3.0.2.
Sorry not feeling well and I had a quick change that I thought was simple but it isn't working (brain fog?).
I would like to make a change to the checkout.tpl file.
I was trying to add a small amount of code only if the square payment extension was enabled. So I put this code in the checkout.tpl file.
<?php if ($this->config->get('squareup_status')) {
Echo 'Square is in testing mode only - please don't use.';
} ?>
It gives me "Call to a member function get() on null"
What am I missing?
Mike
You could change the extension title directly from the language file instead of adding a code to display a text in the checkout.tpl file.
Understood but wish to use that example for other things later so would like a working example.
Thank you,
Mike
By creating an event from the checkout page, that can also be accomplished by validating the shipping_address of the session_data or by editing the extension model title with IF conditions as per the above and one you can add. This can be achieved in multiple ways.
Re: Checking if an extension is enabled in a template file
Posted: Sun Jan 07, 2024 2:31 am
by Cue4cheap
Shouldn't what I have work though on the template file?
I'll check back later days when I'm feeling better.
Thanks,
Mike
Re: Checking if an extension is enabled in a template file
Posted: Sun Jan 07, 2024 3:36 am
by straightlight
Cue4cheap wrote: ↑Sun Jan 07, 2024 2:31 am
Shouldn't what I have work though on the template file?
I'll check back later days when I'm feeling better.
Thanks,
Mike
Code: Select all
<?php if ($this->config->get('payment_squareup_status')) {
echo '...';
?>
Re: Checking if an extension is enabled in a template file
Posted: Mon Jan 08, 2024 2:57 am
by Cue4cheap
straightlight wrote: ↑Sun Jan 07, 2024 3:36 am
Code: Select all
<?php if ($this->config->get('payment_squareup_status')) {
echo '...';
?>
I'm a bit better but that code didn't work for me in the .tpl file so I did it the more proper way, in the controller file.
Thank you for your input.
Mike
Re: Checking if an extension is enabled in a template file
Posted: Mon Jan 08, 2024 6:29 pm
by paulfeakins
Cue4cheap wrote: ↑Mon Jan 08, 2024 2:57 am
I'm a bit better but that code didn't work for me in the .tpl file so I did it the more proper way, in the controller file.
So you knew the proper way to do it but decided to try and hack it? Tut tut.
TPL files don't have access to anything other than the data passed to them from the controller, that's why it didn't work.
Re: Checking if an extension is enabled in a template file
Posted: Mon Jan 08, 2024 10:12 pm
by Cue4cheap
paulfeakins wrote: ↑Mon Jan 08, 2024 6:29 pm
Cue4cheap wrote: ↑Mon Jan 08, 2024 2:57 am
I'm a bit better but that code didn't work for me in the .tpl file so I did it the more proper way, in the controller file.
So you knew the proper way to do it but decided to try and hack it? Tut tut.
TPL files don't have access to anything other than the data passed to them from the controller, that's why it didn't work.
Yeah.... sometimes you do something that
should be the fast way and when it doesn't work it, drives you crazy no matter if you know the other way to do it.
Plus it was supposed to just be for one store, that has low traffic, and since that store is the only one using that template I figured 'easy way to isolate'.
Mike