Where Should I Add My Function?

I cretaed a table in db that hold some shipping statuses. If an order get delivered, the status changes to “DELIVERED”. I check this condition at some parts of time in day. (like at 8 pm, 12 pm) I want create a function and operates this function by using cronjob and send email to customer that says “Thank you”.



What is my way that I follow? Where (in which file) should I create that function and how can I operate/access to a function in URL? Sould I use $mode like ($mode == 'manage') ?



Note: I can create addons and add function in them.

[quote name='ooaykac' timestamp='1420534133' post='201724']

I cretaed a table in db that hold some shipping statuses. If an order get delivered, the status changes to “DELIVERED”. I check this condition at some parts of time in day. (like at 8 pm, 12 pm) I want create a function and operates this function by using cronjob and send email to customer that says “Thank you”.



What is my way that I follow? Where (in which file) should I create that function and how can I operate/access to a function in URL? Sould I use $mode like ($mode == 'manage') ?



Note: I can create addons and add function in them.

[/quote]



You can create a new controller in the app/addons/YOUR_ADDON/controllers/frontend directory. (E.g. shipping_statuses.php). The content should be similar to:


```php

if (!defined('BOOTSTRAP')) { die('Access denied'); }
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
return true;
}
if ($mode == 'check' && $_REQUEST['key'] == 'vGH34df4') {

YOUR CUSTOM FUNCTIONALITY HERE

echo('OK');
exit();
}
```

where [b]vGH34df4[/b] is the secret key

Then you should add a new cron job with the following command:

```php
wget -q "http://domain.com/index.php?dispatch=shipping_statuses.check&key=vGH34df4" >/dev/null 2>&1
```

You can also emulate cron job by running the following URL in your browser:

```php http://domain.com/index.php?dispatch=shipping_statuses.check&key=vGH34df4 ```

You are really great man. Thanks a lot. :)

[quote name=‘ooaykac’ timestamp=‘1420546925’ post=‘201754’]

You are really great man. Thanks a lot. :)

[/quote]



Thank you for the kind words!