Page 1 of 1

PHP Notice: Undefined variable

Posted: Mon Aug 28, 2017 10:10 pm
by 1stTEster
Good evening.
I try to make my payment with credit card and i have some trouble with this.
Opencart version is 2.0.3.1
Problem is
PHP Notice: Undefined variable: creditcard_geo_zone_id in F:\Serv\OpenServer\domains\open-test.lol\admin\view\template\payment\creditcard.tpl on line 60
I check this file on line 60 and im at a loss..

Code: Select all

            <div class="col-sm-10">
              <select name="creditcard_geo_zone_id" id="input-geo-zone" class="form-control">
                <option value="0"><?php echo $text_all_zones; ?></option>
                <?php foreach ($geo_zones as $geo_zone) { ?>
                <?php if ($geo_zone['geo_zone_id'] == $creditcard_geo_zone_id) { ?> (Line 60 with error.) 
                <option value="<?php echo $geo_zone['geo_zone_id']; ?>" selected="selected"><?php echo $geo_zone['name']; ?></option>
                <?php } else { ?>
                <option value="<?php echo $geo_zone['geo_zone_id']; ?>"><?php echo $geo_zone['name']; ?></option>
                <?php } ?>
                <?php } ?>
              </select>
            </div>
I think that i make some mistake in catalog/model/payment/creditcard.php but i make all by this tutorial
catalog/model/payment/creditcard.php code is here

Code: Select all

<?php
class ModelPaymentPPPro extends Model {
	public function getMethod($address, $total) {
		$this->language->load('payment/creditcard');

		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "zone_to_geo_zone WHERE geo_zone_id = '" . (int)$this->config->get('creditcard_geo_zone_id') . "' AND country_id = '" . (int)$address['country_id'] . "' AND (zone_id = '" . (int)$address['zone_id'] . "' OR zone_id = '0')");

		if ($this->config->get('creditcard_total') > 0 && $this->config->get('creditcard_total') > $total) {
			$status = false;
		} elseif (!$this->config->get('creditcard_geo_zone_id')) {
			$status = true;
		} elseif ($query->num_rows) {
			$status = true;
		} else {
			$status = false;
		}

		$method_data = array();

		if ($status) {
			$method_data = array(
				'code'       => 'creditcard',
				'title'      => $this->language->get('text_title'),
				'terms'      => '',
				'sort_order' => $this->config->get('creditcard_sort_order')
			);
		}

		return $method_data;
	}
}
Can u say me what is problem? What need to do? And how i can fix this? Hope for your help!
Sry for my bad english. It's hard to explain thinks in language what you don't know good...

Re: PHP Notice: Undefined variable

Posted: Tue Aug 29, 2017 2:32 am
by kestas
:) seems you forget define in admin controller file something like this...

Code: Select all

if (isset($this->request->post['creditcard_geo_zone_id'])) {
			$data['creditcard_geo_zone_id'] = $this->request->post['creditcard_geo_zone_id'];
		} else {
			$data['creditcard_geo_zone_id'] = $this->config->get('creditcard_geo_zone_id');
		}

Re: PHP Notice: Undefined variable

Posted: Tue Aug 29, 2017 2:58 pm
by 1stTEster
kestas wrote:
Tue Aug 29, 2017 2:32 am
:) seems you forget define in admin controller file something like this...

Code: Select all

if (isset($this->request->post['creditcard_geo_zone_id'])) {
			$data['creditcard_geo_zone_id'] = $this->request->post['creditcard_geo_zone_id'];
		} else {
			$data['creditcard_geo_zone_id'] = $this->config->get('creditcard_geo_zone_id');
		}
Wow, yes i forgot this ^^. It my fail.. Now I define this and now i have some more trouble :D
Fatal error: Uncaught Error: Class 'Modelpaymentcreditcard' not found in F:\Serv\OpenServer\domains\open-test.lol\system\engine\loader.php:22 Stack trace: #0 F:\Serv\OpenServer\domains\open-test.lol\catalog\controller\checkout\payment_method.php(43): Loader->model('payment/creditc...') #1 F:\Serv\OpenServer\domains\open-test.lol\system\engine\action.php(65): ControllerCheckoutPaymentMethod->index(Array) #2 F:\Serv\OpenServer\domains\open-test.lol\system\engine\front.php(34): Action->execute(Object(Registry)) #3 F:\Serv\OpenServer\domains\open-test.lol\system\engine\front.php(29): Front->execute(Object(Action)) #4 F:\Serv\OpenServer\domains\open-test.lol\index.php(256): Front->dispatch(Object(Action), Object(Action)) #5 {main} thrown in F:\Serv\OpenServer\domains\open-test.lol\system\engine\loader.php on line 22
As I understand this problem start from admin/model/payment because i dont have file in this folder. Now i make file and problem not gone. It need to make this file with database working?
I check all files and i don't understand what happing, because i do not change this files, i chandeg only like a tutorial. But some more truble fu** my brain now...
Dear friends, can u forward me in the right direction?

Re: PHP Notice: Undefined variable

Posted: Tue Aug 29, 2017 3:59 pm
by kestas
at first your model file first strings should be:

Code: Select all

<?php
class ModelPaymentCreditcard extends Model {    
Class name should start in capital letters (this are the names of the folders and module name) like in the example code. Not necessary make some connections to DB. it's depends what you want to do...

Re: PHP Notice: Undefined variable

Posted: Tue Aug 29, 2017 4:26 pm
by 1stTEster
kestas wrote:
Tue Aug 29, 2017 3:59 pm
at first your model file first strings should be:

Code: Select all

<?php
class ModelPaymentCreditcard extends Model {    
Class name should start in capital letters (this are the names of the folders and module name) like in the example code. Not necessary make some connections to DB. it's depends what you want to do...
Ok, I understand where is was my fail with this class.Thank for this! Can you help me some more?
It's my pay method and now i can see him, all right!
https://gyazo.com/86deefea7e512f6e66c95e5fcc614fad
But in next step i have this:
https://gyazo.com/cab7a7473270be10357c009502b06916
Why i see only array? Can u send me in the right direction one more time?
I'll never make my modules again ... :D:D

Re: PHP Notice: Undefined variable

Posted: Wed Aug 30, 2017 2:19 am
by kestas
Hi,
I write you PM.