Post by Joe1234 » Mon Sep 26, 2022 10:34 am

I'm setting a "true" variable in
catalog\model\extension\total\coupon.php---->public function getTotal
which gets called first.

and I need to retrieve it in
catalog\controller\extension\total\coupon.php--->public function coupon

It didn't work. I also tried to make the variable global by first creating it at the top of model coupon.php but that didn't work either.

How can I achieve what I need, thanks?
Last edited by Joe1234 on Sat Oct 01, 2022 9:53 pm, edited 1 time in total.

v3.0.3.8
I'm here for a reason, if your response is contact a/the developer, just don't reply.


Active Member

Posts

Joined
Sat Jan 01, 2022 5:47 am

Post by paulfeakins » Mon Sep 26, 2022 7:55 pm

Joe1234 wrote:
Mon Sep 26, 2022 10:34 am
How can I achieve what I need, thanks?
Might be better if you tell us what you're trying to do as it sounds like there will be a better way ...

For quick, professional OpenCart support please email info@antropy.co.uk


User avatar
Guru Member

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - Reigate, Surrey, United Kingdom

Post by ADD Creative » Mon Sep 26, 2022 8:02 pm

getTotal() won't be called by coupon(). The extension\total\coupon route only returns JSON, it does not render the cart. Therefore getTotal() won't be called.

The correct way would depend on where and why you need to set the variable and what you intend to use it for.

www.add-creative.co.uk


Expert Member

Posts

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

Post by Joe1234 » Mon Sep 26, 2022 9:46 pm

I'm using a disable coupon when the product has a special price extension https://www.opencart.com/index.php?rout ... _license=0. What I don't like is a success message is still passed that states the coupon was applied. This will be confusing to a customer and seem like a problem to me. So when the extension detects that a special price is detected I set a "true" variable within that. Then I want to pick up that "true" variable on the other page that is setting the message and change the message based on the true/false variable.

Also on another note, by default with OC, regarding coupon notification in case I run into the same type of issue. Based on my default selection, when someone is not signed in a message is passed stating problems with the COUPON, again poor notifications that will confuse a consumer. This should state the person needs to be signed in first. I was planning on passing a true/false variable the same way for this.

v3.0.3.8
I'm here for a reason, if your response is contact a/the developer, just don't reply.


Active Member

Posts

Joined
Sat Jan 01, 2022 5:47 am

Post by ADD Creative » Tue Sep 27, 2022 3:45 am

You would need to edit the coupon fiction. In the foreach of $this->cart->getProducts() look for the special (in the same way as the extension) and set a variable. You could return the variable in the array with the other coupon information.

www.add-creative.co.uk


Expert Member

Posts

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

Post by Joe1234 » Wed Sep 28, 2022 11:52 am

Thanks, all worked out. One more question, I see the "success" is green and "error" is red when printing out messages. Where do I configure this to add something else with a different color? I want to add "attention" with a yellow color.

v3.0.3.8
I'm here for a reason, if your response is contact a/the developer, just don't reply.


Active Member

Posts

Joined
Sat Jan 01, 2022 5:47 am

Post by DigitCart » Wed Sep 28, 2022 12:49 pm

Hi

If I understand you correctly, You need to do your check in the getCoupon function, Not getTotal.

My Extensions


User avatar
Active Member

Posts

Joined
Thu Jun 22, 2017 5:32 pm


Post by ADD Creative » Wed Sep 28, 2022 6:44 pm

You would need to modify the JavaScript in template\extension\total\coupon.twig theme file. Test the JSON data returned by extension/total/coupon/coupon. Instead of using alert-danger in the class use alert-info.

www.add-creative.co.uk


Expert Member

Posts

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

Post by Joe1234 » Wed Sep 28, 2022 10:21 pm

Having some difficulty here. I basically got it working, but the redirect is wiping out the alert, even if I put the redirect before the alert. If I get rid of the redirect, the message wont appear. This is what I have:

In the coupon controller:

Code: Select all

			if ($coupon_info['coupon_message'] != "") {
				$json['message'] = $coupon_info['coupon_message'];
				$json['info'] = $this->url->link('checkout/cart');
			} else {
				$this->session->data['success'] = $this->language->get('text_success');
				$json['redirect'] = $this->url->link('checkout/cart');
			}
In the javascript in the coupon twig:

Code: Select all

		success: function(json) {
			$('.alert-dismissible').remove();

			if (json['error']) {
				$('.container').prepend('<div class="alert alert-danger alert-dismissible"><i class="fa fa-exclamation-circle"></i> ' + json['error'] + '<button type="button" class="close" data-dismiss="alert">&times;</button></div>');

				$('html, body').animate({ scrollTop: 0 }, 'slow');
			}

			if (json['info']) {

				$('.container').prepend('<div class="alert alert-info alert-dismissible"><i class="fa fa-exclamation-circle"></i> ' + json['message'] + '<button type="button" class="close" data-dismiss="alert">&times;</button></div>');

				location = json['info'];

			}

			if (json['redirect']) {
				location = json['redirect'];
			}
		},
How do I get the message to stay until I get rid of it?

v3.0.3.8
I'm here for a reason, if your response is contact a/the developer, just don't reply.


Active Member

Posts

Joined
Sat Jan 01, 2022 5:47 am

Post by straightlight » Wed Sep 28, 2022 11:18 pm

Joe1234 wrote:
Mon Sep 26, 2022 10:34 am
I'm setting a "true" variable in
catalog\model\extension\total\coupon.php---->public function getTotal
which gets called first.

and I need to retrieve it in
catalog\controller\extension\total\coupon.php--->public function coupon

It didn't work. I also tried to make the variable global by first creating it at the top of model coupon.php but that didn't work either.

How can I achieve what I need, thanks?
Didn't work. Server access logs / Developers Kit results.

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 » Thu Sep 29, 2022 12:02 am

Sorry, I was under the impression you want a different failure message. If you want to redirect to the cart, assuming to update it, you will need to save in the session and modify the checkout/cart controller to feed the message to the template. Changes to JavaScript in the coupon template won't work.

The cart template does have a 'attention' alert. So maybe you could use that. If you set a message in the session the same way as the success.

In checkout/cart, change.

Code: Select all

} else {
	$data['attention'] = '';
}
To something like the following.

Code: Select all

} elseif (isset($this->session->data['message'])) {
	$data['attention'] = $this->session->data['message'];
} else {
	$data['attention'] = '';
}

www.add-creative.co.uk


Expert Member

Posts

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

Post by Joe1234 » Sat Oct 01, 2022 2:46 am

Thanks ADD, all worked out. Going forward, is that the best way to set variables to pass to new pages? By using $data['attention'] = $this->session->data['message']; to set it, and then picking it up on the other page? And yes, I assume this can only be used when logged in.

v3.0.3.8
I'm here for a reason, if your response is contact a/the developer, just don't reply.


Active Member

Posts

Joined
Sat Jan 01, 2022 5:47 am

Post by ADD Creative » Sat Oct 01, 2022 5:02 pm

The session is stored regardless of the login state. So it you need to display a message on the next page after a redirect or reload, then saving a value to the session and testing for it on the next page should work.

www.add-creative.co.uk


Expert Member

Posts

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

Users browsing this forum: No registered users and 33 guests