Post by preto » Sat Sep 21, 2013 1:07 am

Hello,

I would like to enable a extension by code using a condition to make it.

For example, I would like to enable a extension every wednesday. From this link(http://forum.opencart.com/viewtopic.php?t=64752), I saw I can use the function Date, but I don't know how to enable the extension by code. Even in the database I don't know where this status is stored.

I appreciate any help

Newbie

Posts

Joined
Wed Mar 07, 2012 4:25 am

Post by Qphoria » Sat Sep 21, 2013 1:46 am

Best not to do it that way. Instead leave the extension installed and enabled at all times

What type of extension is it?


If payment, you can do this
1. EDIT: catalog/model/payment/xxx.php

2. FIND:

Code: Select all

if ($status) {
3. BEFORE, ADD:

Code: Select all

if (date('l') != 'Wednesday') { return false; }

if it is an order total
1. EDIT: catalog/model/total/xxx.php

2. FIND:

Code: Select all

public function getTotal(&$total_data, &$total, &$taxes) {
3. AFTER, ADD:

Code: Select all

if (date('l') != 'Wednesday') { return false; }


if it is a shipping extension
1. EDIT: catalog/model/shipping/xxx.php

2. FIND:

Code: Select all

function getQuote($address) {
3. AFTER, ADD:

Code: Select all

if (date('l') != 'Wednesday') { return false; }

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by preto » Sat Sep 21, 2013 3:42 am

Hello Qphoria,

Thank you for answer.

In this case I would like to enable a banner. I could do like the link I referenced, but it should have a position in the middle of others modules.

Before asking here, I had it done by editing /catolog/controller/commom/content_top.php

After this:

Code: Select all

if ($modules) {
				foreach ($modules as $module) {
I added this code ( the banner_id of my banner is 13) :

Code: Select all

if(date('D') == 'Wed'){ 
	if (isset($module['banner_id']) && $module['banner_id'] == 13) $module['status'] = 1;
}
But I was looking for a better and more generic way. And I prefer changing in the DB because the status would be consistent with the admin panel too. But it seems not easy to do.

So, using your help, I edited the file catalog/controller/module/banner.php

after this code:

Code: Select all

foreach ($results as $result) {
I added ( the banner_id of my banner is 13):

Code: Select all

if ((date('l') != 'Wednesday') && ($result['banner_id'] == 13)){
	unset($result);
	break;
}
and this is working. :)

Anyways, I think Opencart could have a better documentation...or it has and I don't know where check this.

Once again, thanks for your time and help.

Newbie

Posts

Joined
Wed Mar 07, 2012 4:25 am
Who is online

Users browsing this forum: No registered users and 20 guests