I've set up this module for a payment gateway on opencart but i got this error which i changed $this->data to $data, I get a blank page. If i change it back to $this->data i get this error http://prntscr.com/832nd2
here is the code
<?php
class ControllerPaymentCipgSim extends Controller {
private $error = array();
public function index() {
$this->load->language('payment/cipg_sim');
$this->data['heading_title'] = $this->language->get('heading_title');
$this->load->model('setting/setting');
if (($this->request->server['REQUEST_METHOD'] == 'POST') && ($this->validate())) {
$this->load->model('setting/setting');
$this->model_setting_setting->editSetting('cipg_sim', $this->request->post);
$this->session->data['success'] = $this->language->get('text_success');
$this->redirect(HTTPS_SERVER .'index.php?route=extension/payment&token=' . $this->session->data['token']);
}
$this->data['heading_title'] = $this->language->get('heading_title');
$this->data['text_enabled'] = $this->language->get('text_enabled');
$this->data['text_disabled'] = $this->language->get('text_disabled');
$this->data['text_all_zones'] = $this->language->get('text_all_zones');
$this->data['text_yes'] = $this->language->get('text_yes');
$this->data['text_no'] = $this->language->get('text_no');
$this->data['text_test'] = $this->language->get('text_test');
$this->data['text_live'] = $this->language->get('text_live');
$this->data['button_save'] = $this->language->get('button_save');
$this->data['button_cancel'] = $this->language->get('button_cancel');
$this->data['tab_general'] = $this->language->get('tab_general');
$this->data['get_from_aznet'] = $this->language->get('text_get_from_aznet');
$this->data['set_at_aznet'] = $this->language->get('text_set_at_aznet');
$this->data['optional_aznet'] = $this->language->get('text_optional_aznet');
$this->data['text_min_amount'] = $this->language->get('text_min_amount');
$this->data['text_order_status'] = $this->language->get('text_order_status');
$this->data['text_custom_html'] = $this->language->get('text_custom_html');
$this->data['text_custom_html_help']= $this->language->get('text_custom_html_help');
$this->data['entry_status'] = $this->language->get('entry_status');
$this->data['entry_login_id'] = $this->language->get('entry_login_id');
$this->data['entry_transaction_key']= $this->language->get('entry_transaction_key');
$this->data['entry_response_key'] = $this->language->get('entry_response_key');
$this->data['entry_minimum_amt'] = $this->language->get('entry_minimum_amt');
$this->data['entry_server'] = $this->language->get('entry_server');
$this->data['entry_test'] = $this->language->get('entry_test');
$this->data['entry_geo_zone'] = $this->language->get('entry_geo_zone');
$this->data['entry_order_status'] = $this->language->get('entry_order_status');
$this->data['entry_sort_order'] = $this->language->get('entry_sort_order');
$this->data['entry_custom_header'] = $this->language->get('entry_custom_header');
$this->data['entry_custom_footer'] = $this->language->get('entry_custom_footer');
$this->load->model('localisation/order_status');
$this->data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
$this->load->model('localisation/geo_zone');
$this->data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones();
if (isset($this->request->post['cipg_sim_login_id'])) {
$this->data['cipg_sim_login_id'] = $this->request->post['cipg_sim_login_id'];
} else {
$this->data['cipg_sim_login_id'] = $this->config->get('cipg_sim_login_id');
}
if (isset($this->request->post['cipg_sim_transaction_key'])) {
$this->data['cipg_sim_transaction_key'] = $this->request->post['cipg_sim_transaction_key'];
} else {
$this->data['cipg_sim_transaction_key'] = $this->config->get('cipg_sim_transaction_key');
}
if (isset($this->request->post['cipg_sim_response_key'])) {
$this->data['cipg_sim_response_key'] = $this->request->post['cipg_sim_response_key'];
} else {
$this->data['cipg_sim_response_key'] = $this->config->get('cipg_sim_response_key');
}
if (isset($this->request->post['cipg_sim_total'])) {
$this->data['cipg_sim_total'] = $this->request->post['cipg_sim_total'];
} else {
$this->data['cipg_sim_total'] = $this->config->get('cipg_sim_total');
}
if (isset($this->request->post['cipg_sim_server'])) {
$this->data['cipg_sim_server'] = $this->request->post['cipg_sim_server'];
} else {
$this->data['cipg_sim_server'] = $this->config->get('cipg_sim_server');
}
if (isset($this->request->post['cipg_sim_test'])) {
$this->data['cipg_sim_test'] = $this->request->post['cipg_sim_test'];
} else {
$this->data['cipg_sim_test'] = $this->config->get('cipg_sim_test');
}
if (isset($this->request->post['cipg_sim_status'])) {
$this->data['cipg_sim_status'] = $this->request->post['cipg_sim_status'];
} else {
$this->data['cipg_sim_status'] = $this->config->get('cipg_sim_status');
}
if (isset($this->request->post['cipg_sim_geo_zone_id'])) {
$this->data['cipg_sim_geo_zone_id'] = $this->request->post['cipg_sim_geo_zone_id'];
} else {
$this->data['cipg_sim_geo_zone_id'] = $this->config->get('cipg_sim_geo_zone_id');
}
if (isset($this->request->post['cipg_sim_sort_order'])) {
$this->data['cipg_sim_sort_order'] = $this->request->post['cipg_sim_sort_order'];
} else {
$this->data['cipg_sim_sort_order'] = $this->config->get('cipg_sim_sort_order');
}
if (isset($this->request->post['cipg_sim_order_status_id'])) {
$this->data['cipg_sim_order_status_id'] = $this->request->post['cipg_sim_order_status_id'];
} else {
$this->data['cipg_sim_order_status_id'] = $this->config->get('cipg_sim_order_status_id');
}
if (isset($this->request->post['cipg_sim_custom_header'])) {
$this->data['cipg_sim_custom_header'] = $this->request->post['cipg_sim_custom_header'];
} else {
$this->data['cipg_sim_custom_header'] = $this->config->get('cipg_sim_custom_header');
}
if (isset($this->request->post['cipg_sim_custom_footer'])) {
$this->data['cipg_sim_custom_footer'] = $this->request->post['cipg_sim_custom_footer'];
} else {
$this->data['cipg_sim_custom_footer'] = $this->config->get('cipg_sim_custom_footer');
}
if (isset($this->error['warning'])) {
$this->data['error_warning'] = $this->error['warning'];
} else {
$this->data['error_warning'] = '';
}
if (isset($this->error['login_id'])) {
$this->data['error_login_id'] = $this->error['login_id'];
} else {
$this->data['error_login_id'] = '';
}
if (isset($this->error['transaction_key'])) {
$this->data['error_transaction_key'] = $this->error['transaction_key'];
} else {
$this->data['error_transaction_key'] = '';
}
if (isset($this->error['response_key'])) {
$this->data['error_response_key'] = $this->error['response_key'];
} else {
$this->data['error_response_key'] = '';
}
$this->data['breadcrumbs'] = array();
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'),
'separator' => false
);
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('text_payment'),
'href' => $this->url->link('extension/payment', 'token=' . $this->session->data['token'], 'SSL'),
'separator' => ' :: '
);
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('payment/cipg_sim', 'token=' . $this->session->data['token'], 'SSL'),
'separator' => ' :: '
);
$this->data['action'] = HTTPS_SERVER .'index.php?route=payment/cipg_sim&token=' . $this->session->data['token'];
$this->data['cancel'] = HTTPS_SERVER .'index.php?route=extension/payment&token=' . $this->session->data['token'];
$this->template = 'payment/cipg_sim.tpl';
$this->children = array(
'common/header',
'common/footer'
);
$this->response->setOutput($this->render());
}
private function validate() {
/*if (!$this->user->hasPermission('modify', 'payment/cipg_sim')){
$this->error['warning'] = $this->language->get('error_permission');
}
if (!$this->request->post['cipg_sim_login_id']) {
$this->error['login_id'] = $this->language->get('error_login_id');
}
if (!$this->request->post['cipg_sim_transaction_key']) {
$this->error['transaction_key'] = $this->language->get('error_transaction_key');
}
if (!$this->request->post['cipg_sim_response_key']) {
$this->error['response_key'] = $this->language->get('error_response_key');
} elseif(isset($this->request->post['cipg_sim_response_key']) && (strlen(preg_replace( '/\s+/', ' ', $this->request->post['cipg_sim_response_key'])) > 20)) {
$this->error['response_key'] = $this->language->get('error_response_key');
}*/
if (!$this->error) {
return TRUE;
} else {
return FALSE;
}
}
}
?>
Can someone please assist?
It seems like you are using a very recent version of OpenCart. The data attribute is no longer a member of the Controller class, as you can see in the version history.
I also assume you are using a third-party extension from the Shop. Searching for "stanbic" brings up one result, which isn't compatible with any recent OpenCart version.
Try the same extension on an older OpenCart version. Or you can try to fix the implementation yourself:
Create a local variable $data = array(); right at the beginning of the index function
Replace all references to "$this->data" with "$data"
Pass the local $data to the setOutput function: $this->response->setOutput($this->load->view('foldername/filename.tpl',
$data));
This isnt tested and it is likely that you will have to modify more code, because it appears that the OpenCart 2.x code is quite different from the 1.5.x codebase. Use a recent controller as reference.
Related
I have an e-commerce site in opencart and I have a problem in the RG field which is as follows, when the user registers it fills all the fields normally but in the RG field there are those users that have one digit less in the RG that they are usually 9 more digits have users with 8 and they usually register on the site more when they are going to make a purchase they can not conclude it because the RG is with a number less would like to know if it is possible to put a code that does the following when the User to enter a RG with one digit less or less than 9 add a 0 at the end of the field so that it is complete.
This is uexatamente the input that I need to change so that when the user clicks on register it will be saved with the longest digit
<Input type = "text" name = "custom_field [account] [2]" value = "" placeholder = "RG" id = "input-custom-field2" class = "form-control">
I do not know if this is where I am going to implement my code but this is one of the controllers responsible for the registration of the form
<?php
class ControllerAccountRegister extends Controller {
private $error = array();
public function index() {
if ($this->customer->isLogged()) {
$this->response->redirect($this->url->link('account/account', '', 'SSL'));
}
$this->load->language('account/register');
$this->document->setTitle($this->language->get('heading_title'));
$this->document->addScript('catalog/view/javascript/jquery/datetimepicker/moment.js');
$this->document->addScript('catalog/view/javascript/jquery/datetimepicker/bootstrap-datetimepicker.min.js');
$this->document->addStyle('catalog/view/javascript/jquery/datetimepicker/bootstrap-datetimepicker.min.css');
$this->load->model('account/customer');
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
$customer_id = $this->model_account_customer->addCustomer($this->request->post);
// Clear any previous login attempts for unregistered accounts.
$this->model_account_customer->deleteLoginAttempts($this->request->post['email']);
$this->customer->login($this->request->post['email'], $this->request->post['password']);
unset($this->session->data['guest']);
// Add to activity log
$this->load->model('account/activity');
$activity_data = array(
'customer_id' => $customer_id,
'name' => $this->request->post['firstname']
//'name' => $this->request->post['firstname'] . ' ' . $this->request->post['lastname']
);
$this->model_account_activity->addActivity('register', $activity_data);
$this->response->redirect($this->url->link('account/success'));
}
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home')
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_account'),
'href' => $this->url->link('account/account', '', 'SSL')
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_register'),
'href' => $this->url->link('account/register', '', 'SSL')
);
$data['heading_title'] = $this->language->get('heading_title');
$data['text_account_already'] = sprintf($this->language->get('text_account_already'), $this->url->link('account/login', '', 'SSL'));
$data['text_your_details'] = $this->language->get('text_your_details');
$data['text_your_address'] = $this->language->get('text_your_address');
$data['text_your_password'] = $this->language->get('text_your_password');
$data['text_newsletter'] = $this->language->get('text_newsletter');
$data['text_yes'] = $this->language->get('text_yes');
$data['text_no'] = $this->language->get('text_no');
$data['text_select'] = $this->language->get('text_select');
$data['text_none'] = $this->language->get('text_none');
$data['text_loading'] = $this->language->get('text_loading');
$data['entry_customer_group'] = $this->language->get('entry_customer_group');
$data['entry_firstname'] = $this->language->get('entry_firstname');
// $data['entry_lastname'] = $this->language->get('entry_lastname');
$data['entry_email'] = $this->language->get('entry_email');
$data['entry_telephone'] = $this->language->get('entry_telephone');
$data['entry_fax'] = $this->language->get('entry_fax');
$data['entry_company'] = $this->language->get('entry_company');
$data['entry_address_1'] = $this->language->get('entry_address_1');
$data['entry_address_2'] = $this->language->get('entry_address_2');
$data['entry_postcode'] = $this->language->get('entry_postcode');
$data['entry_city'] = $this->language->get('entry_city');
$data['entry_country'] = $this->language->get('entry_country');
$data['entry_zone'] = $this->language->get('entry_zone');
$data['entry_newsletter'] = $this->language->get('entry_newsletter');
$data['entry_password'] = $this->language->get('entry_password');
$data['entry_confirm'] = $this->language->get('entry_confirm');
$data['button_continue'] = $this->language->get('button_continue');
$data['button_upload'] = $this->language->get('button_upload');
if (isset($this->error['warning'])) {
$data['error_warning'] = $this->error['warning'];
} else {
$data['error_warning'] = '';
}
if (isset($this->error['firstname'])) {
$data['error_firstname'] = $this->error['firstname'];
} else {
$data['error_firstname'] = '';
}
// if (isset($this->error['lastname'])) {
// $data['error_lastname'] = $this->error['lastname'];
// } else {
// $data['error_lastname'] = '';
// }
if (isset($this->error['email'])) {
$data['error_email'] = $this->error['email'];
} else {
$data['error_email'] = '';
}
if (isset($this->error['telephone'])) {
$data['error_telephone'] = $this->error['telephone'];
} else {
$data['error_telephone'] = '';
}
if (isset($this->error['address_1'])) {
$data['error_address_1'] = $this->error['address_1'];
} else {
$data['error_address_1'] = '';
}
if (isset($this->error['city'])) {
$data['error_city'] = $this->error['city'];
} else {
$data['error_city'] = '';
}
if (isset($this->error['postcode'])) {
$data['error_postcode'] = $this->error['postcode'];
} else {
$data['error_postcode'] = '';
}
if (isset($this->error['country'])) {
$data['error_country'] = $this->error['country'];
} else {
$data['error_country'] = '';
}
if (isset($this->error['zone'])) {
$data['error_zone'] = $this->error['zone'];
} else {
$data['error_zone'] = '';
}
if (isset($this->error['custom_field'])) {
$data['error_custom_field'] = $this->error['custom_field'];
} else {
$data['error_custom_field'] = array();
}
if (isset($this->error['password'])) {
$data['error_password'] = $this->error['password'];
} else {
$data['error_password'] = '';
}
if (isset($this->error['confirm'])) {
$data['error_confirm'] = $this->error['confirm'];
} else {
$data['error_confirm'] = '';
}
$data['action'] = $this->url->link('account/register', '', 'SSL');
$data['customer_groups'] = array();
if (is_array($this->config->get('config_customer_group_display'))) {
$this->load->model('account/customer_group');
$customer_groups = $this->model_account_customer_group->getCustomerGroups();
foreach ($customer_groups as $customer_group) {
if (in_array($customer_group['customer_group_id'], $this->config->get('config_customer_group_display'))) {
$data['customer_groups'][] = $customer_group;
}
}
}
if (isset($this->request->post['customer_group_id'])) {
$data['customer_group_id'] = $this->request->post['customer_group_id'];
} else {
$data['customer_group_id'] = $this->config->get('config_customer_group_id');
}
if (isset($this->request->post['firstname'])) {
$data['firstname'] = $this->request->post['firstname'];
} else {
$data['firstname'] = '';
}
// if (isset($this->request->post['lastname'])) {
// $data['lastname'] = $this->request->post['lastname'];
// } else {
// $data['lastname'] = '';
// }
if (isset($this->request->post['email'])) {
$data['email'] = $this->request->post['email'];
} else {
$data['email'] = '';
}
if (isset($this->request->post['telephone'])) {
$data['telephone'] = $this->request->post['telephone'];
} else {
$data['telephone'] = '';
}
if (isset($this->request->post['fax'])) {
$data['fax'] = $this->request->post['fax'];
} else {
$data['fax'] = '';
}
if (isset($this->request->post['company'])) {
$data['company'] = $this->request->post['company'];
} else {
$data['company'] = '';
}
if (isset($this->request->post['address_1'])) {
$data['address_1'] = $this->request->post['address_1'];
} else {
$data['address_1'] = '';
}
if (isset($this->request->post['address_2'])) {
$data['address_2'] = $this->request->post['address_2'];
} else {
$data['address_2'] = '';
}
if (isset($this->request->post['postcode'])) {
$data['postcode'] = $this->request->post['postcode'];
} elseif (isset($this->session->data['shipping_address']['postcode'])) {
$data['postcode'] = $this->session->data['shipping_address']['postcode'];
} else {
$data['postcode'] = '';
}
if (isset($this->request->post['city'])) {
$data['city'] = $this->request->post['city'];
} else {
$data['city'] = '';
}
if (isset($this->request->post['country_id'])) {
$data['country_id'] = $this->request->post['country_id'];
} elseif (isset($this->session->data['shipping_address']['country_id'])) {
$data['country_id'] = $this->session->data['shipping_address']['country_id'];
} else {
$data['country_id'] = $this->config->get('config_country_id');
}
if (isset($this->request->post['zone_id'])) {
$data['zone_id'] = $this->request->post['zone_id'];
} elseif (isset($this->session->data['shipping_address']['zone_id'])) {
$data['zone_id'] = $this->session->data['shipping_address']['zone_id'];
} else {
$data['zone_id'] = '';
}
$this->load->model('localisation/country');
$data['countries'] = $this->model_localisation_country->getCountries();
// Custom Fields
$this->load->model('account/custom_field');
$data['custom_fields'] = $this->model_account_custom_field->getCustomFields();
if (isset($this->request->post['custom_field'])) {
if (isset($this->request->post['custom_field']['account'])) {
$account_custom_field = $this->request->post['custom_field']['account'];
} else {
$account_custom_field = array();
}
if (isset($this->request->post['custom_field']['address'])) {
$address_custom_field = $this->request->post['custom_field']['address'];
} else {
$address_custom_field = array();
}
$data['register_custom_field'] = $account_custom_field + $address_custom_field;
} else {
$data['register_custom_field'] = array();
}
if (isset($this->request->post['password'])) {
$data['password'] = $this->request->post['password'];
} else {
$data['password'] = '';
}
if (isset($this->request->post['confirm'])) {
$data['confirm'] = $this->request->post['confirm'];
} else {
$data['confirm'] = '';
}
if (isset($this->request->post['newsletter'])) {
$data['newsletter'] = $this->request->post['newsletter'];
} else {
$data['newsletter'] = '';
}
if ($this->config->get('config_account_id')) {
$this->load->model('catalog/information');
$information_info = $this->model_catalog_information->getInformation($this->config->get('config_account_id'));
if ($information_info) {
$data['text_agree'] = sprintf($this->language->get('text_agree'), $this->url->link('information/information/agree', 'information_id=' . $this->config->get('config_account_id'), 'SSL'), $information_info['title'], $information_info['title']);
} else {
$data['text_agree'] = '';
}
} else {
$data['text_agree'] = '';
}
if (isset($this->request->post['agree'])) {
$data['agree'] = $this->request->post['agree'];
} else {
$data['agree'] = false;
}
$data['column_left'] = $this->load->controller('common/column_left');
$data['column_right'] = $this->load->controller('common/column_right');
$data['content_top'] = $this->load->controller('common/content_top');
$data['content_bottom'] = $this->load->controller('common/content_bottom');
$data['footer'] = $this->load->controller('common/footer');
$data['header'] = $this->load->controller('common/header');
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/account/register.tpl')) {
$this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/account/register.tpl', $data));
} else {
$this->response->setOutput($this->load->view('default/template/account/register.tpl', $data));
}
}
public function validate() {
if ((utf8_strlen(trim($this->request->post['firstname'])) < 1) || (utf8_strlen(trim($this->request->post['firstname'])) > 32)) {
$this->error['firstname'] = $this->language->get('error_firstname');
}
// if ((utf8_strlen(trim($this->request->post['lastname'])) < 1) || (utf8_strlen(trim($this->request->post['lastname'])) > 32)) {
// $this->error['lastname'] = $this->language->get('error_lastname');
// }
if ((utf8_strlen($this->request->post['email']) > 96) || !preg_match('/^[^\#]+#.*.[a-z]{2,15}$/i', $this->request->post['email'])) {
$this->error['email'] = $this->language->get('error_email');
}
if ($this->model_account_customer->getTotalCustomersByEmail($this->request->post['email'])) {
$this->error['warning'] = $this->language->get('error_exists');
}
if ((utf8_strlen($this->request->post['telephone']) < 3) || (utf8_strlen($this->request->post['telephone']) > 32)) {
$this->error['telephone'] = $this->language->get('error_telephone');
}
if ((utf8_strlen(trim($this->request->post['address_1'])) < 3) || (utf8_strlen(trim($this->request->post['address_1'])) > 128)) {
$this->error['address_1'] = $this->language->get('error_address_1');
}
if ((utf8_strlen(trim($this->request->post['city'])) < 2) || (utf8_strlen(trim($this->request->post['city'])) > 128)) {
$this->error['city'] = $this->language->get('error_city');
}
$this->load->model('localisation/country');
$country_info = $this->model_localisation_country->getCountry($this->request->post['country_id']);
if ($country_info && $country_info['postcode_required'] && (utf8_strlen(trim($this->request->post['postcode'])) < 2 || utf8_strlen(trim($this->request->post['postcode'])) > 10)) {
$this->error['postcode'] = $this->language->get('error_postcode');
}
if ($this->request->post['country_id'] == '') {
$this->error['country'] = $this->language->get('error_country');
}
if (!isset($this->request->post['zone_id']) || $this->request->post['zone_id'] == '') {
$this->error['zone'] = $this->language->get('error_zone');
}
// Customer Group
if (isset($this->request->post['customer_group_id']) && is_array($this->config->get('config_customer_group_display')) && in_array($this->request->post['customer_group_id'], $this->config->get('config_customer_group_display'))) {
$customer_group_id = $this->request->post['customer_group_id'];
} else {
$customer_group_id = $this->config->get('config_customer_group_id');
}
// Custom field validation
$this->load->model('account/custom_field');
$custom_fields = $this->model_account_custom_field->getCustomFields($customer_group_id);
foreach ($custom_fields as $custom_field) {
if ($custom_field['required'] && empty($this->request->post['custom_field'][$custom_field['location']][$custom_field['custom_field_id']])) {
$this->error['custom_field'][$custom_field['custom_field_id']] = sprintf($this->language->get('error_custom_field'), $custom_field['name']);
}
}
if ((utf8_strlen($this->request->post['password']) < 4) || (utf8_strlen($this->request->post['password']) > 20)) {
$this->error['password'] = $this->language->get('error_password');
}
if ($this->request->post['confirm'] != $this->request->post['password']) {
$this->error['confirm'] = $this->language->get('error_confirm');
}
// Agree to terms
if ($this->config->get('config_account_id')) {
$this->load->model('catalog/information');
$information_info = $this->model_catalog_information->getInformation($this->config->get('config_account_id'));
if ($information_info && !isset($this->request->post['agree'])) {
$this->error['warning'] = sprintf($this->language->get('error_agree'), $information_info['title']);
}
}
return !$this->error;
}
public function customfield() {
$json = array();
$this->load->model('account/custom_field');
// Customer Group
if (isset($this->request->get['customer_group_id']) && is_array($this->config->get('config_customer_group_display')) && in_array($this->request->get['customer_group_id'], $this->config->get('config_customer_group_display'))) {
$customer_group_id = $this->request->get['customer_group_id'];
} else {
$customer_group_id = $this->config->get('config_customer_group_id');
}
$custom_fields = $this->model_account_custom_field->getCustomFields($customer_group_id);
foreach ($custom_fields as $custom_field) {
$json[] = array(
'custom_field_id' => $custom_field['custom_field_id'],
'required' => $custom_field['required']
);
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}
may be you can use this script.
function putZeroToLastItem($text) {
$length = strlen($text);
if( $length < 9 ) {
$text .= '0'
}
return $text
}
I hope , this script will solve your porblem.
<?php
$num = 3;
$num_padded = sprintf("%02d", $num);
echo $num_padded; // returns 03
?>
Try this simple snippet
You want to add 0 after the number (9 digit)? Use jquery if you want it in client side.
function addZero (data){
return data+(data <10 ? '0':'');
}
var num =$('#number').val();
var nNum = addZero(num);
Hope it helps.
A reduced way of #mehfatitem:
function putZeroToLastItem($text) {
return (strlen($text) < 9) ? $text . '0' : $text;
}
Any guidance/advice would be great.
We have WorldPay installed with Opencart 2.0.1.1
All online orders/transactions work fine, everything processes.
However, at the end of the transaction the relay response does not work.
Customers are not re-directed back to the website.
WorldPay have confirmed this should be working (all settings are correct)
It must be a problem with the worldpay.php itself.
Complete shot in the dark, but has anybody experienced this? Opencart forums are usless.
Really appreciate your help!
<?php
class ControllerPaymentWorldPay extends Controller {
private $error = array();
public function index() {
$this->load->language('payment/worldpay');
$this->document->setTitle($this->language->get('heading_title'));
$this->load->model('setting/setting');
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
$this->model_setting_setting->editSetting('worldpay', $this->request->post);
$this->session->data['success'] = $this->language->get('text_success');
$this->response->redirect($this->url->link('extension/payment', 'token=' . $this->session->data['token'], 'SSL'));
}
$data['heading_title'] = $this->language->get('heading_title');
$data['text_edit'] = $this->language->get('text_edit');
$data['text_enabled'] = $this->language->get('text_enabled');
$data['text_disabled'] = $this->language->get('text_disabled');
$data['text_all_zones'] = $this->language->get('text_all_zones');
$data['text_yes'] = $this->language->get('text_yes');
$data['text_no'] = $this->language->get('text_no');
$data['text_successful'] = $this->language->get('text_successful');
$data['text_declined'] = $this->language->get('text_declined');
$data['text_off'] = $this->language->get('text_off');
$data['entry_merchant'] = $this->language->get('entry_merchant');
$data['entry_password'] = $this->language->get('entry_password');
$data['entry_callback'] = $this->language->get('entry_callback');
$data['entry_test'] = $this->language->get('entry_test');
$data['entry_total'] = $this->language->get('entry_total');
$data['entry_order_status'] = $this->language->get('entry_order_status');
$data['entry_geo_zone'] = $this->language->get('entry_geo_zone');
$data['entry_status'] = $this->language->get('entry_status');
$data['entry_sort_order'] = $this->language->get('entry_sort_order');
$data['help_password'] = $this->language->get('help_password');
$data['help_callback'] = $this->language->get('help_callback');
$data['help_total'] = $this->language->get('help_total');
$data['button_save'] = $this->language->get('button_save');
$data['button_cancel'] = $this->language->get('button_cancel');
if (isset($this->error['warning'])) {
$data['error_warning'] = $this->error['warning'];
} else {
$data['error_warning'] = '';
}
if (isset($this->error['merchant'])) {
$data['error_merchant'] = $this->error['merchant'];
} else {
$data['error_merchant'] = '';
}
if (isset($this->error['password'])) {
$data['error_password'] = $this->error['password'];
} else {
$data['error_password'] = '';
}
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/dashboard', 'token=' . $this->session->data['token'], 'SSL')
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_payment'),
'href' => $this->url->link('extension/payment', 'token=' . $this->session->data['token'], 'SSL')
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('payment/worldpay', 'token=' . $this->session->data['token'], 'SSL')
);
$data['action'] = $this->url->link('payment/worldpay', 'token=' . $this->session->data['token'], 'SSL');
$data['cancel'] = $this->url->link('extension/payment', 'token=' . $this->session->data['token'], 'SSL');
if (isset($this->request->post['worldpay_merchant'])) {
$data['worldpay_merchant'] = $this->request->post['worldpay_merchant'];
} else {
$data['worldpay_merchant'] = $this->config->get('worldpay_merchant');
}
if (isset($this->request->post['worldpay_password'])) {
$data['worldpay_password'] = $this->request->post['worldpay_password'];
} else {
$data['worldpay_password'] = $this->config->get('worldpay_password');
}
$data['callback'] = HTTP_CATALOG . 'index.php?route=payment/worldpay/callback';
if (isset($this->request->post['worldpay_test'])) {
$data['worldpay_test'] = $this->request->post['worldpay_test'];
} else {
$data['worldpay_test'] = $this->config->get('worldpay_test');
}
if (isset($this->request->post['worldpay_total'])) {
$data['worldpay_total'] = $this->request->post['worldpay_total'];
} else {
$data['worldpay_total'] = $this->config->get('worldpay_total');
}
if (isset($this->request->post['worldpay_order_status_id'])) {
$data['worldpay_order_status_id'] = $this->request->post['worldpay_order_status_id'];
} else {
$data['worldpay_order_status_id'] = $this->config->get('worldpay_order_status_id');
}
$this->load->model('localisation/order_status');
$data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
if (isset($this->request->post['worldpay_geo_zone_id'])) {
$data['worldpay_geo_zone_id'] = $this->request->post['worldpay_geo_zone_id'];
} else {
$data['worldpay_geo_zone_id'] = $this->config->get('worldpay_geo_zone_id');
}
$this->load->model('localisation/geo_zone');
$data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones();
if (isset($this->request->post['worldpay_status'])) {
$data['worldpay_status'] = $this->request->post['worldpay_status'];
} else {
$data['worldpay_status'] = $this->config->get('worldpay_status');
}
if (isset($this->request->post['worldpay_sort_order'])) {
$data['worldpay_sort_order'] = $this->request->post['worldpay_sort_order'];
} else {
$data['worldpay_sort_order'] = $this->config->get('worldpay_sort_order');
}
$data['header'] = $this->load->controller('common/header');
$data['column_left'] = $this->load->controller('common/column_left');
$data['footer'] = $this->load->controller('common/footer');
$this->response->setOutput($this->load->view('payment/worldpay.tpl', $data));
}
protected function validate() {
if (!$this->user->hasPermission('modify', 'payment/worldpay')) {
$this->error['warning'] = $this->language->get('error_permission');
}
if (!$this->request->post['worldpay_merchant']) {
$this->error['merchant'] = $this->language->get('error_merchant');
}
if (!$this->request->post['worldpay_password']) {
$this->error['password'] = $this->language->get('error_password');
}
return !$this->error;
}
}
I just wanted to clone the moneybookers payment module to mpower payment module in Open Cart and guess what I am stuck here now with this error as :
Fatal error: Call to undefined method Loader::controller() in /home/hunter/public_html/opencart_new/admin/controller/payment/mpower.php on line 213
Here is the full /home/hunter/public_html/opencart_new/admin/controller/payment/mpower.php file as :
<?php
class ControllerPaymentMPower extends Controller {
private $error = array();
public function index() {
$this->load->language('payment/mpower');
$this->document->setTitle($this->language->get('heading_title'));
$this->load->model('setting/setting');
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
$this->model_setting_setting->editSetting('mpower', $this->request->post);
$this->session->data['success'] = $this->language->get('text_success');
$this->response->redirect($this->url->link('extension/payment', 'token=' . $this->session->data['token'], 'SSL'));
}
$data['heading_title'] = $this->language->get('heading_title');
$data['text_edit'] = $this->language->get('text_edit');
$data['text_enabled'] = $this->language->get('text_enabled');
$data['text_disabled'] = $this->language->get('text_disabled');
$data['text_all_zones'] = $this->language->get('text_all_zones');
$data['entry_MasterKey'] = $this->language->get('entry_MasterKey');
$data['entry_PublicKey'] = $this->language->get('entry_PublicKey');
$data['entry_PrivateKey'] = $this->language->get('entry_PrivateKey');
$data['entry_Mode'] = $this->language->get('entry_Mode');
$data['entry_Token'] = $this->language->get('entry_Token');
$data['entry_StoreName'] = $this->language->get('entry_StoreName');
$data['entry_StoreTagline'] = $this->language->get('entry_StoreTagline');
$data['entry_PhoneNumber'] = $this->language->get('entry_PhoneNumber');
$data['entry_PostalAddress'] = $this->language->get('entry_PostalAddress');
$data['entry_total'] = $this->language->get('entry_total');
$data['entry_order_status'] = $this->language->get('entry_order_status');
$data['entry_pending_status'] = $this->language->get('entry_pending_status');
$data['entry_canceled_status'] = $this->language->get('entry_canceled_status');
$data['entry_failed_status'] = $this->language->get('entry_failed_status');
$data['entry_chargeback_status'] = $this->language->get('entry_chargeback_status');
$data['entry_geo_zone'] = $this->language->get('entry_geo_zone');
$data['entry_status'] = $this->language->get('entry_status');
$data['entry_sort_order'] = $this->language->get('entry_sort_order');
$data['entry_custnote'] = $this->language->get('entry_custnote');
$data['help_total'] = $this->language->get('help_total');
$data['button_save'] = $this->language->get('button_save');
$data['button_cancel'] = $this->language->get('button_cancel');
if (isset($this->error['warning'])) {
$data['error_warning'] = $this->error['warning'];
} else {
$data['error_warning'] = '';
}
if (isset($this->error['email'])) {
$data['error_email'] = $this->error['email'];
} else {
$data['error_email'] = '';
}
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/dashboard', 'token=' . $this->session->data['token'], 'SSL')
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_payment'),
'href' => $this->url->link('extension/payment', 'token=' . $this->session->data['token'], 'SSL')
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('payment/mpower', 'token=' . $this->session->data['token'], 'SSL')
);
$data['action'] = $this->url->link('payment/mpower', 'token=' . $this->session->data['token'], 'SSL');
$data['cancel'] = $this->url->link('extension/payment', 'token=' . $this->session->data['token'], 'SSL');
if (isset($this->request->post['mpower_MasterKey'])) {
$data['mpower_MasterKey'] = $this->request->post['mpower_MasterKey'];
} else {
$data['mpower_MasterKey'] = $this->config->get('mpower_MasterKey');
}
if (isset($this->request->post['mpower_PublicKey'])) {
$data['mpower_PublicKey'] = $this->request->post['mpower_PublicKey'];
} else {
$data['mpower_PublicKey'] = $this->config->get('mpower_PublicKey');
}
if (isset($this->request->post['mpower_PrivateKey'])) {
$data['mpower_PrivateKey'] = $this->request->post['mpower_PrivateKey'];
} else {
$data['mpower_PrivateKey'] = $this->config->get('mpower_PrivateKey');
}
if (isset($this->request->post['mpower_Token'])) {
$data['mpower_Token'] = $this->request->post['mpower_Token'];
} else {
$data['mpower_Token'] = $this->config->get('mpower_Token');
}
if (isset($this->request->post['mpower_mode'])) {
$data['mpower_mode'] = $this->request->post['mpower_mode'];
} else {
$data['mpower_mode'] = $this->config->get('mpower_mode');
}
if (isset($this->request->post['mpower_StoreName'])) {
$data['mpower_StoreName'] = $this->request->post['mpower_StoreName'];
} else {
$data['mpower_StoreName'] = $this->config->get('mpower_StoreName');
}
if (isset($this->request->post['mpower_StoreTagline'])) {
$data['mpower_StoreTagline'] = $this->request->post['mpower_StoreTagline'];
} else {
$data['mpower_StoreTagline'] = $this->config->get('mpower_StoreTagline');
}
if (isset($this->request->post['mpower_PhoneNumber'])) {
$data['mpower_PhoneNumber'] = $this->request->post['mpower_PhoneNumber'];
} else {
$data['mpower_PhoneNumber'] = $this->config->get('mpower_PhoneNumber');
}
if (isset($this->request->post['mpower_PostalAddress'])) {
$data['mpower_PostalAddress'] = $this->request->post['mpower_PostalAddress'];
} else {
$data['mpower_PostalAddress'] = $this->config->get('mpower_PostalAddress');
}
if (isset($this->request->post['mpower_total'])) {
$data['mpower_total'] = $this->request->post['mpower_total'];
} else {
$data['mpower_total'] = $this->config->get('mpower_total');
}
if (isset($this->request->post['mpower_order_status_id'])) {
$data['mpower_order_status_id'] = $this->request->post['mpower_order_status_id'];
} else {
$data['mpower_order_status_id'] = $this->config->get('mpower_order_status_id');
}
if (isset($this->request->post['mpower_pending_status_id'])) {
$data['mpower_pending_status_id'] = $this->request->post['mpower_pending_status_id'];
} else {
$data['mpower_pending_status_id'] = $this->config->get('mpower_pending_status_id');
}
if (isset($this->request->post['mpower_canceled_status_id'])) {
$data['mpower_canceled_status_id'] = $this->request->post['mpower_canceled_status_id'];
} else {
$data['mpower_canceled_status_id'] = $this->config->get('mpower_canceled_status_id');
}
if (isset($this->request->post['mpower_failed_status_id'])) {
$data['mpower_failed_status_id'] = $this->request->post['mpower_failed_status_id'];
} else {
$data['mpower_failed_status_id'] = $this->config->get('mpower_failed_status_id');
}
if (isset($this->request->post['mpower_chargeback_status_id'])) {
$data['mpower_chargeback_status_id'] = $this->request->post['mpower_chargeback_status_id'];
} else {
$data['mpower_chargeback_status_id'] = $this->config->get('mpower_chargeback_status_id');
}
$this->load->model('localisation/order_status');
$data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
if (isset($this->request->post['mpower_geo_zone_id'])) {
$data['mpower_geo_zone_id'] = $this->request->post['mpower_geo_zone_id'];
} else {
$data['mpower_geo_zone_id'] = $this->config->get('mpower_geo_zone_id');
}
$this->load->model('localisation/geo_zone');
$data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones();
if (isset($this->request->post['mpower_status'])) {
$data['mpower_status'] = $this->request->post['mpower_status'];
} else {
$data['mpower_status'] = $this->config->get('mpower_status');
}
if (isset($this->request->post['mpower_sort_order'])) {
$data['mpower_sort_order'] = $this->request->post['mpower_sort_order'];
} else {
$data['mpower_sort_order'] = $this->config->get('mpower_sort_order');
}
if (isset($this->request->post['mpower_rid'])) {
$data['mpower_rid'] = $this->request->post['mpower_rid'];
} else {
$data['mpower_rid'] = $this->config->get('mpower_rid');
}
if (isset($this->request->post['mpower_custnote'])) {
$data['mpower_custnote'] = $this->request->post['mpower_custnote'];
} else {
$data['mpower_custnote'] = $this->config->get('mpower_custnote');
}
$data['header'] = $this->load->controller('common/header');
$data['column_left'] = $this->load->controller('common/column_left');
$data['footer'] = $this->load->controller('common/footer');
$this->response->setOutput($this->load->view('payment/mpower.tpl', $data));
}
protected function validate() {
if (!$this->user->hasPermission('modify', 'payment/mpower')) {
$this->error['warning'] = $this->language->get('error_permission');
}
if (!$this->request->post['mpower_MasterKey']) {
$this->error['MasterKey'] = $this->language->get('error_MasterKey');
}
if (!$this->request->post['mpower_PublicKey']) {
$this->error['PublicKey'] = $this->language->get('error_PublicKey');
}
if (!$this->request->post['mpower_PrivateKey']) {
$this->error['PrivateKey'] = $this->language->get('error_PrivateKey');
}
if (!$this->request->post['mpower_Token']) {
$this->error['Token'] = $this->language->get('error_Token');
}
return !$this->error;
}
}
Line number 213 is :
$data['header'] = $this->load->controller('common/header');
I have not been completed developing the module fully but almost done with the admin side of the payment module but it is giving error so if anyone can please have a look and let me know that what I am doing wrong please?
Here is your code after line no 213:
Replace this code:
$data['header'] = $this->load->controller('common/header');
$data['column_left'] = $this->load->controller('common/column_left');
$data['footer'] = $this->load->controller('common/footer');
$this->response->setOutput($this->load->view('payment/mpower.tpl', $data));
With
$this->template = 'payment/mpower.tpl';
$this->children = array(
'common/header',
'common/column_left',
'common/footer'
);
$this->response->setOutput($this->render());
No need to call controller for header, footer and etc.
And also no need to pass $data in setOutput, it will automatically pass in your view file when you are load your payment gateway link in browser because of it will call your index method by default.
I encountered the same problem, and discovered that I was using a 2.0.X.X module in opencart version 1.5.X.X. You may simply be using the wrong version of the module.
I am beginner to OpenCart eshop. I am trying to create a custom form depending on printing services. I need to insert an uploaded image into MySQL and show it at OpenCart's admin section. How to validate <input type='file'> file type input in OpenCart? In pure PHP there is $_FILES[][] array applicable but how to access submitted files in OpenCart? Please, help me solve it.
if (isset($this->error['file'])) {
$this->data['error_file'] = $this->error['file'];
} else {
$this->data['error_file'] = '';
}
My custom page controller:
<?php
class ControllerInformationDesign extends Controller {
private $error = array();
public function index() {
/*if (!$this->customer->isLogged()) {
$this->session->data['redirect'] = $this->url->link('account/custreview', '', 'SSL');
$this->redirect($this->url->link('account/login', '', 'SSL'));
} */
$this->language->load('information/design');
$this->document->setTitle($this->config->get('config_name') . ' - ' . $this->language->get('heading_title'));
$this->load->model('account/custreview');
$this->getForm();
}
public function insert() {
$this->load->language('information/design');
$this->document->setTitle($this->config->get('config_name') . ' - ' . $this->language->get('heading_title'));
$this->load->model('account/custreview');
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
$this->model_account_custreview->addReview($this->request->post);
$this->session->data['success'] = $this->language->get('text_success');
$this->redirect($this->url->link('information/design'));
}
$this->getForm();
}
private function getForm() {
$this->data['heading_title'] = $this->language->get('heading_title');
$this->data['entry_prefix'] = $this->language->get('entry_prefix');
$this->data['entry_desc'] = $this->language->get('entry_desc');
$this->data['entry_industry'] = $this->language->get('entry_industry');
$this->data['entry_design'] = $this->language->get('entry_design');
$this->data['entry_prefix1'] = $this->language->get('entry_prefix1');
$this->data['entry_other'] = $this->language->get('entry_other');
$this->data['entry_prefix2'] = $this->language->get('entry_prefix2');
$this->data['entry_prefix3'] = $this->language->get('entry_prefix3');
$this->data['entry_prefix4'] = $this->language->get('entry_prefix4');
$this->data['logged'] = $this->customer->getFirstname() . ' ' . $this->customer->getLastName();
$this->data['text_none'] = $this->language->get('text_none');
$this->data['text_select'] = $this->language->get('text_select');
$this->data['entry_product'] = $this->language->get('entry_product');
$this->data['entry_author'] = $this->language->get('entry_author');
$this->data['entry_rating'] = $this->language->get('entry_rating');
$this->data['entry_review'] = $this->language->get('entry_review');
$this->data['entry_good'] = $this->language->get('entry_good');
$this->data['entry_bad'] = $this->language->get('entry_bad');
$this->data['button_save'] = $this->language->get('continue_shop');
$this->data['button_checkout'] = $this->language->get('check_out');
if (isset($this->error['warning'])) {
$this->data['error_warning'] = $this->error['warning'];
} else {
$this->data['error_warning'] = '';
}
if (isset($this->session->data['success'])) {
$this->data['success'] = $this->session->data['success'];
unset($this->session->data['success']);
} else {
$this->data['success'] = '';
}
if (isset($this->error['product'])) {
$this->data['error_product'] = $this->error['product'];
} else {
$this->data['error_product'] = '';
}
if (isset($this->error['product_id'])) {
$this->data['error_product_id'] = $this->error['product_id'];
} else {
$this->data['error_product_id'] = '';
}
if (isset($this->error['author'])) {
$this->data['error_author'] = $this->error['author'];
} else {
$this->data['error_author'] = '';
}
if (isset($this->error['text'])) {
$this->data['error_text'] = $this->error['text'];
} else {
$this->data['error_text'] = '';
}
if (isset($this->error['rating'])) {
$this->data['error_rating'] = $this->error['rating'];
} else {
$this->data['error_rating'] = '';
}
if (isset($this->error['cdesc'])) {
$this->data['error_desc'] = $this->error['cdesc'];
} else {
$this->data['error_desc'] = '';
}
if (isset($this->error['industry'])) {
$this->data['error_industry'] = $this->error['industry'];
} else {
$this->data['error_industry'] = '';
}
if (isset($this->error['design'])) {
$this->data['error_design'] = $this->error['design'];
} else {
$this->data['error_design'] = '';
}
if (isset($this->error['other'])) {
$this->data['error_other'] = $this->error['other'];
} else {
$this->data['error_other'] = '';
}
if (isset($this->error['file'])) {
$this->data['error_file'] = $this->error['file'];
} else {
$this->data['error_file'] = '';
}
$this->data['breadcrumbs'] = array();
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home', 'SSL'),
'separator' => false
);
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('information/design','SSL'),
'separator' => ' :: '
);
if (!isset($this->request->get['review_id'])) {
$this->data['action'] = $this->url->link('information/design/insert');
}
$this->data['cancel'] = $this->url->link('information/design','SSL');
if (isset($this->request->get['review_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) {
$review_info = $this->model_account_custreview->getReview($this->request->get['review_id']);
}
$this->load->model('catalog/category');
$this->data['categories'] = $this->model_catalog_category->getCategories(0);
$this->load->model('catalog/product');
if (isset($this->request->post['product_id'])) {
$this->data['product_id'] = $this->request->post['product_id'];
$product_info = $this->model_catalog_product->getProduct($this->request->post['product_id']);
if ($product_info) {
$this->data['product'] = $product_info['name'];
} else {
$this->data['product'] = '';
}
} elseif (isset($review_info)) {
$this->data['product_id'] = $review_info['product_id'];
$product_info = $this->model_catalog_product->getProduct($review_info['product_id']);
if ($product_info) {
$this->data['product'] = $product_info['name'];
} else {
$this->data['product'] = '';
}
} else {
$this->data['product_id'] = '';
}
if (isset($this->request->post['product_id'])) {
$this->data['product_id'] = $this->request->post['product_id'];
} elseif (isset($review_info)) {
$this->data['product_id'] = $review_info['product_id'];
} else {
$this->data['product_id'] = '';
}
if (isset($this->request->post['product'])) {
$this->data['product'] = $this->request->post['product'];
} elseif (isset($review_info)) {
$this->data['product'] = $review_info['product'];
} else {
$this->data['product'] = '';
}
if (isset($this->request->post['author'])) {
$this->data['author'] = $this->request->post['author'];
} elseif (isset($review_info)) {
$this->data['author'] = $review_info['author'];
} else {
$this->data['author'] = '';
}
if (isset($this->request->post['text'])) {
$this->data['text'] = $this->request->post['text'];
} elseif (isset($review_info)) {
$this->data['text'] = $review_info['text'];
} else {
$this->data['text'] = '';
}
if (isset($this->request->post['rating'])) {
$this->data['rating'] = $this->request->post['rating'];
} elseif (isset($review_info)) {
$this->data['rating'] = $review_info['rating'];
} else {
$this->data['rating'] = '';
}
if (isset($this->request->post['cdesc'])) {
$this->data['cdesc'] = $this->request->post['cdesc'];
} elseif (isset($review_info)) {
$this->data['cdesc'] = $review_info['cdesc'];
} else {
$this->data['cdesc'] = '';
}
if (isset($this->request->post['industry'])) {
$this->data['industry'] = $this->request->post['industry'];
} elseif (isset($review_info)) {
$this->data['industry'] = $review_info['industry'];
} else {
$this->data['industry'] = '';
}
if (isset($this->request->post['design'])) {
$this->data['design'] = $this->request->post['design'];
} elseif (isset($review_info)) {
$this->data['design'] = $review_info['design'];
} else {
$this->data['design'] = '';
}
if (isset($this->request->post['other'])) {
$this->data['other'] = $this->request->post['other'];
} elseif (isset($review_info)) {
$this->data['other'] = $review_info['other'];
} else {
$this->data['other'] = '';
}
if (isset($this->request->post['file'])) {
$this->data['file'] = $this->request->post['file'];
} elseif (isset($review_info)) {
$this->data['file'] = $review_info['file'];
} else {
$this->data['file'] = '';
}
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/information/design.tpl')) {
$this->template = $this->config->get('config_template') . '/template/information/design.tpl';
} else {
$this->template = 'default/template/information/design.tpl';
}
$this->children = array(
'common/column_left',
'common/column_right',
'common/content_top',
'common/content_bottom',
'common/footer',
'common/header'
);
$this->response->setOutput($this->render());
}
private function validateForm() {
/*if (!$this->request->post['product_id']) {
$this->error['product'] = $this->language->get('error_product');
}
if (!$this->request->post['product_id']) {
$this->error['product_id'] = $this->language->get('error_product_id');
}*/
if ((strlen(utf8_decode($this->request->post['author'])) < 3) || (strlen(utf8_decode($this->request->post['author'])) > 64)) {
$this->error['author'] = $this->language->get('error_author');
}
/*
if (strlen(utf8_decode($this->request->post['text'])) < 1) {
$this->error['text'] = $this->language->get('error_text');
}*/
/*if (!isset($this->request->post['rating'])) {
$this->error['rating'] = $this->language->get('error_rating');
}
if (!isset($this->request->post['file'])) {
$this->error['file'] = $this->language->get('error_file');
}*/
if ((strlen(utf8_decode($this->request->post['cdesc'])) < 3) || (strlen(utf8_decode($this->request->post['cdesc'])) > 1000)) {
$this->error['cdesc'] = $this->language->get('error_desc');
}
if ((strlen(utf8_decode($this->request->post['industry'])) < 3) || (strlen(utf8_decode($this->request->post['industry'])) > 1000)) {
$this->error['industry'] = $this->language->get('error_industry');
}
if ((strlen(utf8_decode($this->request->post['design'])) < 3) || (strlen(utf8_decode($this->request->post['design'])) > 1000)) {
$this->error['design'] = $this->language->get('error_design');
}
if ((strlen(utf8_decode($this->request->post['other'])) < 3) || (strlen(utf8_decode($this->request->post['other'])) > 1000)) {
$this->error['other'] = $this->language->get('error_other');
}
if (!$this->error) {
return true;
} else {
return false;
}
}
public function autocomplete() {
$json = array();
if (isset($this->request->post['filter_name'])) {
$this->load->model('catalog/product');
$data = array(
'filter_name' => $this->request->post['filter_name'],
'start' => 0,
'limit' => 20
);
$results = $this->model_catalog_product->getProducts($data);
foreach ($results as $result) {
$json[] = array(
'product_id' => $result['product_id'],
'name' => html_entity_decode($result['name'], ENT_QUOTES, 'UTF-8'),
'model' => $result['model'],
'price' => $result['price']
);
}
}
$this->load->library('json');
$this->response->setOutput(Json::encode($json));
}
}
?>
How to handle file upload in OpenCart and how to insert uploaded files into database? How to solve it? Please guide me...
I am newer in Open cart frame work. I am working to create custom page with file uploading and direct checkout button(just like shopping cart page.)In this page, i already create (tpl files) view and controller based on contact form.
Here my controller:
<?php
class ControllerInformationRequest extends Controller {
private $error = array();
public function index() {
$this->language->load('information/request');
$this->document->setTitle($this->language->get('heading_title'));
$this->load->model('account/request');
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
$this->redirect($this->url->link('information/request/success'));
}
$this->data['breadcrumbs'] = array();
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home'),
'separator' => false
);
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('information/request'),
'separator' => $this->language->get('text_separator')
);
$this->data['heading_title'] = $this->language->get('heading_title');
$this->data['text_location'] = $this->language->get('text_location');
$this->data['text_contact'] = $this->language->get('text_contact');
$this->data['text_address'] = $this->language->get('text_address');
$this->data['text_telephone'] = $this->language->get('text_telephone');
$this->data['text_fax'] = $this->language->get('text_fax');
$this->data['entry_name'] = $this->language->get('entry_name');
$this->data['entry_email'] = $this->language->get('entry_email');
$this->data['entry_enquiry'] = $this->language->get('entry_enquiry');
$this->data['entry_captcha'] = $this->language->get('entry_captcha');
$this->data['entry_phone'] = $this->language->get('entry_phone');
if (isset($this->error['name'])) {
$this->data['error_name'] = $this->error['name'];
} else {
$this->data['error_name'] = '';
}
if (isset($this->error['telephone'])) {
$this->data['error_telephone'] = $this->error['telephone'];
} else {
$this->data['error_telephone'] = '';
}
if (isset($this->error['email'])) {
$this->data['error_email'] = $this->error['email'];
} else {
$this->data['error_email'] = '';
}
if (isset($this->error['enquiry'])) {
$this->data['error_enquiry'] = $this->error['enquiry'];
} else {
$this->data['error_enquiry'] = '';
}
if (isset($this->error['captcha'])) {
$this->data['error_captcha'] = $this->error['captcha'];
} else {
$this->data['error_captcha'] = '';
}
$this->data['button_continue'] = $this->language->get('button_continue');
$this->data['action'] = $this->url->link('information/request');
$this->data['store'] = $this->config->get('config_name');
$this->data['address'] = nl2br($this->config->get('config_address'));
$this->data['telephone'] = $this->config->get('config_telephone');
$this->data['fax'] = $this->config->get('config_fax');
if (isset($this->request->post['name'])) {
$this->data['name'] = $this->request->post['name'];
} else {
$this->data['name'] = $this->customer->getFirstName();
}
if (isset($this->request->post['email'])) {
$this->data['email'] = $this->request->post['email'];
} else {
$this->data['email'] = $this->customer->getEmail();
}
if (isset($this->request->post['telephone'])) {
$this->data['telephone'] = $this->request->post['telephone'];
} else {
//$this->data['phone'] = $this->customer->getPhone();
$this->data['telephone'] = $this->customer->getTelephone();
}
if (isset($this->request->post['enquiry'])) {
$this->data['enquiry'] = $this->request->post['enquiry'];
} else {
$this->data['enquiry'] = '';
}
if (isset($this->request->post['captcha'])) {
$this->data['captcha'] = $this->request->post['captcha'];
} else {
$this->data['captcha'] = '';
}
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/information/request.tpl')) {
$this->template = $this->config->get('config_template') . '/template/information/request.tpl';
} else {
$this->template = 'default/template/information/request.tpl';
}
$this->load->model('account/request');
$this->children = array(
'common/column_left',
'common/column_right',
'common/content_top',
'common/content_bottom',
'common/footer',
'common/header'
);
$this->response->setOutput($this->render());
}
public function success() {
$this->language->load('information/request');
$this->document->setTitle($this->language->get('heading_title'));
$this->data['breadcrumbs'] = array();
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home'),
'separator' => false
);
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('information/request'),
'separator' => $this->language->get('text_separator')
);
$this->data['heading_title'] = $this->language->get('heading_title');
$this->data['text_message'] = $this->language->get('text_message');
$this->data['button_continue'] = $this->language->get('button_continue');
$this->data['continue'] = $this->url->link('common/home');
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/success.tpl')) {
$this->template = $this->config->get('config_template') . '/template/common/success.tpl';
} else {
$this->template = 'default/template/common/success.tpl';
}
$this->children = array(
'common/column_left',
'common/column_right',
'common/content_top',
'common/content_bottom',
'common/footer',
'common/header'
);
$this->response->setOutput($this->render());
}
private function validate() {
if ((utf8_strlen($this->request->post['name']) < 3) || (utf8_strlen($this->request->post['name']) > 32)) {
$this->error['name'] = $this->language->get('error_name');
}
if (!preg_match('/^[^\#]+#.*\.[a-z]{2,6}$/i', $this->request->post['email'])) {
$this->error['email'] = $this->language->get('error_email');
}
if ((utf8_strlen($this->request->post['enquiry']) < 10) || (utf8_strlen($this->request->post['enquiry']) > 3000)) {
$this->error['enquiry'] = $this->language->get('error_enquiry');
}
if (empty($this->session->data['captcha']) || ($this->session->data['captcha'] != $this->request->post['captcha'])) {
$this->error['captcha'] = $this->language->get('error_captcha');
}
if (!$this->error) {
return true;
} else {
return false;
}
}
public function captcha() {
$this->load->library('captcha');
$captcha = new Captcha();
$this->session->data['captcha'] = $captcha->getCode();
$captcha->showImage();
}
}
?>
In view .tpl files contain name,Email address, phone,message and captcha images.I just want to stored that data into database,I already create model file in particular locations,
How to call model file ($this->load->model('account/request');)...its doesnt working and its cant stored database also.How is it possible ?please provide me solutions for this....
To load model from controller use this syntax;
for instance to load opencart folder / catalog/model/catalog/category
$this->load->model('catalog/category');
then you can happily call method from that model like below ;
$categories = $this->model_catalog_category->getCategories(0);