Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opencart's $this->config->get('module_var_name')

Tags:

php

opencart

I'm trying to customize an Opencart payment module, I see many places where config info is being used, but I cant find anything that creates what variables are in use. I know in the admin pages if I select 'paypal standard' I can set all the 'config' info, but I cant find the 'model' underlining it, is there a model, I wish to create a new config setting, settable inside the admin page

How does the admin page know which variables to set? If I change the admin 'view' for the payment module to show a new setting, will that setting automatically be available in the catalog?

example of some of the config data in use...

admin\view\template\payment\pp_standard.tpl (paypal admin template), allows 'test mode' to be set....

<tr>
        <td><?php echo $entry_test; ?></td>
        <td><?php if ($pp_standard_test) { ?>
          <input type="radio" name="pp_standard_test" value="1" checked="checked" />
          <?php echo $text_yes; ?>
          <input type="radio" name="pp_standard_test" value="0" />
          <?php echo $text_no; ?>
          <?php } else { ?>
          <input type="radio" name="pp_standard_test" value="1" />
          <?php echo $text_yes; ?>
          <input type="radio" name="pp_standard_test" value="0" checked="checked" />
          <?php echo $text_no; ?>
          <?php } ?></td>
      </tr>

catalog\controller\poayment\pp_standard.php (paypal catalog controller), uses above 'test mode' to determine which paypal Webservice URL to hit..

if (!$this->config->get('pp_standard_test')) {
    $curl = curl_init('https://www.paypal.com/cgi-bin/webscr');
} else {
    $curl = curl_init('https://www.sandbox.paypal.com/cgi-bin/webscr');
}

I was expecting to find a 'model' somewhere with 'pp_standard_test' defined somewhere, but I've found nothing, any help understanding this would be greatly appreciated.

P.S. There is much advice online stating that the 'paypal standard' payment module is a good place to start, but more than likely, we wont be using paypal, it's the principle I'm trying to figure out.

like image 933
Ninjanoel Avatar asked Jun 05 '13 11:06

Ninjanoel


1 Answers

In OpenCart administration a admin/model/setting/setting.php model is used for such a modules/extensions where only a key group name and the posted data is provided to be stored in the setting DB table... (and optionally a store_id in multistore installation as well)

You could check any of controllers in admin/controller/payment/ dir to see how is this model used (pp_standard.php, from line 10 within OC 1.5.5.1):

$this->load->model('setting/setting');

if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
    $this->model_setting_setting->editSetting('pp_standard', $this->request->post);

    $this->session->data['success'] = $this->language->get('text_success');

    $this->redirect($this->url->link('extension/payment', 'token=' . $this->session->data['token'], 'SSL'));
}

This will write all the form data into the setting DB table while form field's name is used as a key to the value filled within.

Thus if You call

$this->config->get('<KEY>');

You can get the value that is set for the <KEY> key.

like image 75
shadyyx Avatar answered Nov 16 '22 08:11

shadyyx