Post by KFR_jonatan » Sat Jul 31, 2021 9:27 pm

Hello,

I have a problem with my first Module.
I would like to save the settings in the oc_setting table.

Code: Select all

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

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

			$this->response->redirect($this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL'));
		}
Everything seems to be fine but no settings are being saved.
If I manually add the appropriate values in the oc_setting table the data reads correctly but when I try to change them the data does not save and even the whole record is deleted from the table.
No errors whatsoever. After pressing the save button a message appears that the settings have been successfully saved.

Below is the entire controller code

Code: Select all

<?php
class ControllerModuleGratis extends Controller {
	private $error = array();

	public function index() {
		$this->load->language('module/gratis');

		$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('gratis', $this->request->post);

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

			$this->response->redirect($this->url->link('extension/module', '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['entry_status'] = $this->language->get('entry_status');

		$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'] = '';
		}

		$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_module'),
			'href' => $this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL')
		);

		$data['breadcrumbs'][] = array(
			'text' => $this->language->get('heading_title'),
			'href' => $this->url->link('module/gratis', 'token=' . $this->session->data['token'], 'SSL')
		);

		$data['action'] = $this->url->link('module/gratis', 'token=' . $this->session->data['token'], 'SSL');

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

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

		$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('module/gratis.tpl', $data));
	}

	protected function validate() {
		if (!$this->user->hasPermission('modify', 'module/gratis')) {
			$this->error['warning'] = $this->language->get('error_permission');
		}

		return !$this->error;
	}
}

Do you have any idea why this is happening?
Last edited by KFR_jonatan on Tue Aug 03, 2021 12:09 pm, edited 2 times in total.

Newbie

Posts

Joined
Sat Jul 31, 2021 9:10 pm

Post by straightlight » Mon Aug 02, 2021 6:33 am

OC version.

In admin/controller/setting/setting.php file.

Above:

Code: Select all

$this->response->redirect($this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL'));
add:

Code: Select all

echo "<pre />\n";
print_r($this->request->post);
echo "</pre>\n";
exit;
Save the file. Go back to your edit settings page, save again. See if there's an array posted on a white page. If so, please post it on the forum (if not running live). However, if your store is running live, please send it via the forum PM to me in bb code. I will take a look.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by KFR_jonatan » Mon Aug 02, 2021 3:48 pm

Thank you for your reply.
OpenCart version 2.0.2.0

in admin/controller/setting/setting.php file.
I do not have such a line of code

Code: Select all

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

I have this:

Code: Select all

.
$this->response->redirect($this->url->link('setting/store', 'token=' . $this->session->data['token'], 'SSL'))
.

Newbie

Posts

Joined
Sat Jul 31, 2021 9:10 pm

Post by straightlight » Mon Aug 02, 2021 6:02 pm

KFR_jonatan wrote:
Mon Aug 02, 2021 3:48 pm
Thank you for your reply.
OpenCart version 2.0.2.0

in admin/controller/setting/setting.php file.
I do not have such a line of code

Code: Select all

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

I have this:

Code: Select all

.
$this->response->redirect($this->url->link('setting/store', 'token=' . $this->session->data['token'], 'SSL'))
.
Then, above that line.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by KFR_jonatan » Mon Aug 02, 2021 6:50 pm

I pasted the code (below the result).
But this result appears only when saving settings in menu
system->settings
When I save my module settings nothing happens.

Code: Select all

Array
(
    [config_name] => domain.com
    [config_owner] => domain.com
    [config_address] => domain.com
    [config_geocode] => 
    [config_email] => info@domain.com
    [config_telephone] =>  ---
    [config_fax] => 
    [config_image] => catalog/image_0012.png
    [config_open] => 
    [config_comment] => 
    [config_meta_title] => page title
    [config_meta_description] => Page description 
    [config_meta_keyword] => 
    [config_template] => default
    [config_layout_id] => 4
    [config_country_id] => 170
    [config_zone_id] => 2641
    [config_language] => en
    [config_admin_language] => en
    [config_currency] => USD
    [config_currency_auto] => 1
    [config_length_class_id] => 1
    [config_weight_class_id] => 1
    [config_product_count] => 0
    [config_product_limit] => 100
    [config_product_description_length] => 100
    [config_limit_admin] => 1000
    [config_review_status] => 1
    [config_review_guest] => 1
    [config_review_mail] => 1
    [config_voucher_min] => 1
    [config_voucher_max] => 1000
    [config_tax] => 1
    [config_tax_default] => shipping
    [config_tax_customer] => shipping
    [config_customer_online] => 1
    [config_customer_group_id] => 1
    [config_customer_group_display] => Array
        (
            [0] => 1
        )

    [config_customer_price] => 0
    [config_login_attempts] => 5
    [config_account_id] => 0
    [config_account_mail] => 0
    [config_invoice_prefix] => INV-2021-00
    [config_api_id] => 1
    [config_cart_weight] => 0
    [config_checkout_guest] => 1
    [config_checkout_id] => 0
    [config_order_status_id] => 1
    [config_processing_status] => Array
        (
            [0] => 41
        )

    [config_complete_status] => Array
        (
            [0] => 112
        )

    [config_order_mail] => 1
    [config_stock_display] => 0
    [config_stock_warning] => 0
    [config_stock_checkout] => 0
    [config_affiliate_approval] => 0
    [config_affiliate_auto] => 0
    [config_affiliate_commission] => 5
    [config_affiliate_id] => 4
    [config_affiliate_mail] => 0
    [config_return_id] => 0
    [config_return_status_id] => 2
    [config_logo] => catalog/logo.png
    [config_icon] => catalog/fav.png
    [config_image_category_width] => 200
    [config_image_category_height] => 200
    [config_image_thumb_width] => 350
    [config_image_thumb_height] => 350
    [config_image_popup_width] => 400
    [config_image_popup_height] => 400
    [config_image_product_width] => 250
    [config_image_product_height] => 250
    [config_image_additional_width] => 250
    [config_image_additional_height] => 250
    [config_image_related_width] => 300
    [config_image_related_height] => 300
    [config_image_compare_width] => 90
    [config_image_compare_height] => 90
    [config_image_wishlist_width] => 47
    [config_image_wishlist_height] => 47
    [config_image_cart_width] => 47
    [config_image_cart_height] => 47
    [config_image_location_width] => 268
    [config_image_location_height] => 50
    [config_ftp_hostname] => ftp.domain.com
    [config_ftp_port] => 21
    [config_ftp_username] => 
    [config_ftp_password] => 
    [config_ftp_root] => 
    [config_ftp_status] => 0
    [config_mail_protocol] => smtp
    [config_mail_parameter] => info@domain.com
    [config_mail_smtp_hostname] => xxx
    [config_mail_smtp_username] => xxx
    [config_mail_smtp_password] => xxx
    [config_mail_smtp_port] => 25
    [config_mail_smtp_timeout] => 5
    [config_mail_alert] => xxx@xxx.com
    [config_fraud_detection] => 0
    [config_fraud_key] => 
    [config_fraud_score] => 
    [config_fraud_status_id] => 107
    [config_secure] => 1
    [config_shared] => 0
    [config_robots] => abot
dbot
ebot
hbot
kbot
lbot
mbot
nbot
obot
pbot
rbot
sbot
tbot
vbot
ybot
zbot
bot.
bot/
_bot
.bot
/bot
-bot
:bot
(bot
crawl
slurp
spider
seek
accoona
acoon
adressendeutschland
ah-ha.com
ahoy
altavista
ananzi
anthill
appie
arachnophilia
arale
araneo
aranha
architext
aretha
arks
asterias
atlocal
atn
atomz
augurfind
backrub
bannana_bot
baypup
bdfetch
big brother
biglotron
bjaaland
blackwidow
blaiz
blog
blo.
bloodhound
boitho
booch
bradley
butterfly
calif
cassandra
ccubee
cfetch
charlotte
churl
cienciaficcion
cmc
collective
comagent
combine
computingsite
csci
curl
cusco
daumoa
deepindex
delorie
depspid
deweb
die blinde kuh
digger
ditto
dmoz
docomo
download express
dtaagent
dwcp
ebiness
ebingbong
e-collector
ejupiter
emacs-w3 search engine
esther
evliya celebi
ezresult
falcon
felix ide
ferret
fetchrover
fido
findlinks
fireball
fish search
fouineur
funnelweb
gazz
gcreep
genieknows
getterroboplus
geturl
glx
goforit
golem
grabber
grapnel
gralon
griffon
gromit
grub
gulliver
hamahakki
harvest
havindex
helix
heritrix
hku www octopus
homerweb
htdig
html index
html_analyzer
htmlgobble
hubater
hyper-decontextualizer
ia_archiver
ibm_planetwide
ichiro
iconsurf
iltrovatore
image.kapsi.net
imagelock
incywincy
indexer
infobee
informant
ingrid
inktomisearch.com
inspector web
intelliagent
internet shinchakubin
ip3000
iron33
israeli-search
ivia
jack
jakarta
javabee
jetbot
jumpstation
katipo
kdd-explorer
kilroy
knowledge
kototoi
kretrieve
labelgrabber
lachesis
larbin
legs
libwww
linkalarm
link validator
linkscan
lockon
lwp
lycos
magpie
mantraagent
mapoftheinternet
marvin/
mattie
mediafox
mediapartners
mercator
merzscope
microsoft url control
minirank
miva
mj12
mnogosearch
moget
monster
moose
motor
multitext
muncher
muscatferret
mwd.search
myweb
najdi
nameprotect
nationaldirectory
nazilla
ncsa beta
nec-meshexplorer
nederland.zoek
netcarta webmap engine
netmechanic
netresearchserver
netscoop
newscan-online
nhse
nokia6682/
nomad
noyona
nutch
nzexplorer
objectssearch
occam
omni
open text
openfind
openintelligencedata
orb search
osis-project
pack rat
pageboy
pagebull
page_verifier
panscient
parasite
partnersite
patric
pear.
pegasus
peregrinator
pgp key agent
phantom
phpdig
picosearch
piltdownman
pimptrain
pinpoint
pioneer
piranha
plumtreewebaccessor
pogodak
poirot
pompos
poppelsdorf
poppi
popular iconoclast
psycheclone
publisher
python
rambler
raven search
roach
road runner
roadhouse
robbie
robofox
robozilla
rules
salty
sbider
scooter
scoutjet
scrubby
search.
searchprocess
semanticdiscovery
senrigan
sg-scout
shai'hulud
shark
shopwiki
sidewinder
sift
silk
simmany
site searcher
site valet
sitetech-rover
skymob.com
sleek
smartwit
sna-
snappy
snooper
sohu
speedfind
sphere
sphider
spinner
spyder
steeler/
suke
suntek
supersnooper
surfnomore
sven
sygol
szukacz
tach black widow
tarantula
templeton
/teoma
t-h-u-n-d-e-r-s-t-o-n-e
theophrastus
titan
titin
tkwww
toutatis
t-rex
tutorgig
twiceler
twisted
ucsd
udmsearch
url check
updated
vagabondo
valkyrie
verticrawl
victoria
vision-search
volcano
voyager/
voyager-hc
w3c_validator
w3m2
w3mir
walker
wallpaper
wanderer
wauuu
wavefire
web core
web hopper
web wombat
webbandit
webcatcher
webcopy
webfoot
weblayers
weblinker
weblog monitor
webmirror
webmonkey
webquest
webreaper
websitepulse
websnarf
webstolperer
webvac
webwalk
webwatch
webwombat
webzinger
whizbang
whowhere
wild ferret
worldlight
wwwc
wwwster
xenu
xget
xift
xirq
yandex
yanga
yeti
yodao
zao
zippp
zyborg
    [config_seo_url] => 1
    [config_file_max_size] => 300000
    [config_file_ext_allowed] => zip
txt
png
jpe
jpeg
jpg
gif
bmp
ico
tiff
tif
svg
svgz
zip
rar
msi
cab
mp3
qt
mov
pdf
psd
ai
eps
ps
doc
webp
    [config_file_mime_allowed] => text/plain
image/png
image/jpeg
image/gif
image/bmp
image/tiff
image/webp
image/svg+xml
application/zip
"application/zip"
application/x-zip
"application/x-zip"
application/x-zip-compressed
"application/x-zip-compressed"
application/rar
"application/rar"
application/x-rar
"application/x-rar"
application/x-rar-compressed
"application/x-rar-compressed"
application/octet-stream
"application/octet-stream"
audio/mpeg
video/quicktime
application/pdf
    [config_maintenance] => 0
    [config_password] => 0
    [config_encryption] => LnQbo2uYJL4No2N3pL4NN3p9
    [config_compression] => 9
    [config_error_display] => 1
    [config_error_log] => 1
    [config_error_filename] => error.log
    [config_google_analytics] => <!-- Google Tag Manager -->
<script></script>
<!-- End Google Tag Manager -->
    [config_google_analytics_status] => 1
    [config_google_captcha_public] => 
    [config_google_captcha_secret] => 
    [config_google_captcha_status] => 0
)

Newbie

Posts

Joined
Sat Jul 31, 2021 9:10 pm

Post by straightlight » Mon Aug 02, 2021 7:17 pm

While you're also using Google Tag Manager extension, you'll also need to apply this code where you are saving your actual module. Then, provide the array.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by KFR_jonatan » Mon Aug 02, 2021 7:51 pm

thank you for your reply.
I don't have much experience with OpenCart but could you explain what effect Google Tag Manager extension has on saving my module data to oc_setting table?
And where and what code should I add in my module to make editSetting method work.
At the moment even when I copy the code of simple module "Filter" (all files - controller, language, view), which works fine (there is only on/off option - like in my module) to my module files (of course changing everywhere filter -> gratis etc.) the editSetting method still does not work i.e. the method does not create a new record with the appropriate data, and when I manually enter the data into the database the editSetting method does not overwrite the data but only deletes them. And as before there are no errors only a message that the database has been correctly saved.
Could this be a problem with the server? I am currently using xampp locally on my computer.
Last edited by KFR_jonatan on Mon Aug 02, 2021 8:16 pm, edited 1 time in total.

Newbie

Posts

Joined
Sat Jul 31, 2021 9:10 pm

Post by straightlight » Mon Aug 02, 2021 8:05 pm

KFR_jonatan wrote:
Mon Aug 02, 2021 7:51 pm
thank you for your reply.
I don't have much experience with OpenCart but could you explain what effect Google Tag Manager extension has on saving my module data to oc_setting table?
And where and what code should I add in my module to make editSetting method work.
At the moment even when I copy the code of simple module "Filter" (all files - controller, language, view), which works fine (there is only on/off option - like in my module) to my module files (of course changing everywhere filter -> gratis etc.) the editSetting method still does not work i.e. the method does not create a new record with the appropriate data, and when I manually enter the data into the database the editSetting method does not overwrite the data but only deletes them. And as before there are no errors only a message that the database has been correctly saved.
Could this be a problem with the server? I am currently using xampp locally on my computer.


Translated with www.DeepL.com/Translator (free version)
Since you're not sure on how to proceed at this point, better to create a new service request in the Commercial Support section of the forum, or contact me directly via the forum PM, to have this issue investigated as a custom job.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by ADD Creative » Tue Aug 03, 2021 12:54 am

What is the data you are trying to write? What are you using as the name in your template?

Depending on what you are writing, this may have an effect.
https://github.com/opencart/opencart/issues/3015

Also it's better to change.

Code: Select all

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

Code: Select all

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

www.add-creative.co.uk


Expert Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by KFR_jonatan » Tue Aug 03, 2021 1:44 am

ADD Creative wrote:
Tue Aug 03, 2021 12:54 am
What is the data you are trying to write? What are you using as the name in your template?

Depending on what you are writing, this may have an effect.
https://github.com/opencart/opencart/issues/3015

Also it's better to change.

Code: Select all

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

Code: Select all

if (isset($this->request->post['gratis_status'])) {
			$data['gratis_status'] = $this->request->post['gratis_status'];
		} else {
			$data['gratis_status'] = $this->config->get('gratis_status');
		}
Thank you very much.
The problem was in the variable name.

Instead of 'status' it should be 'gratis_status'

Now everything works perfectly.

Newbie

Posts

Joined
Sat Jul 31, 2021 9:10 pm

Post by straightlight » Tue Aug 03, 2021 1:45 am

Now that the issue has been solved, please add: [SOLVED} at the beginning of the subject line on your first post.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON
Who is online

Users browsing this forum: No registered users and 58 guests