Post by fguzels » Tue Nov 03, 2020 10:05 pm

Hello,
I have installed Journal 3x theme for Opencart Version 3.0.3.2.
In order to receive order conversions in the Google Ads service, I have to paste a code on the order complete page. This code should only be found on the order completion page that appears after you press the complete shopping button. How can I do that.

I tried this with an external plug-in but they were not compatible with theme files so it didn't work. I would be glad if you help.

I reach the order complete page with catalog / view / theme / journal3 / template / common / success.twig, but this is the body of the order complete page. I need to put this code in <head> </head> tags. (Not for the entire site, only for the order completion page)

When I add something to the header.twig file in the same folder, I cannot view it anywhere on the site. (After adding something, I make the necessary renewal from the developer settings from the admin panel, but it still does not work)

I found the following topics in the forum, but I either did not understand the solution or misunderstood and applied it incorrectly. In short, I could not reach a conclusion with these links.

viewtopic.php?f=202&t=217624&p=786182&h ... ds#p786182
viewtopic.php?f=202&t=217624&hilit=checkout+ads
viewtopic.php?f=202&t=207086&hilit=checkout+ads
viewtopic.php?f=202&t=210287&hilit=checkout+ads

Can you help me about this topic?

Newbie

Posts

Joined
Sat Oct 17, 2020 2:35 am

Post by straightlight » Tue Nov 03, 2020 10:15 pm

Since you're looking to create an event with Journal, contact Journal support for assistance.

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 fguzels » Tue Nov 03, 2020 10:25 pm

straightlight wrote:
Tue Nov 03, 2020 10:15 pm
Since you're looking to create an event with Journal, contact Journal support for assistance.

I can also use Opencart's original theme. Then what should I do?

Newbie

Posts

Joined
Sat Oct 17, 2020 2:35 am

Post by straightlight » Tue Nov 03, 2020 10:26 pm

With the original theme, this link works perfectly: viewtopic.php?f=202&t=217624&p=786182&h ... ds#p786182 .

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 fguzels » Tue Nov 03, 2020 10:30 pm

straightlight wrote:
Tue Nov 03, 2020 10:26 pm
With the original theme, this link works perfectly: viewtopic.php?f=202&t=217624&p=786182&h ... ds#p786182 .

As a matter of fact, I studied that text a lot, but I could not understand it. Let me examine it again in the evening with a calm mind. Thank you.

Newbie

Posts

Joined
Sat Oct 17, 2020 2:35 am

Post by JNeuhoff » Tue Nov 03, 2020 11:22 pm

This requires event handlers for the triggers catalog/controller/checkout/success/before (to save the order_id into a session variable), and catalog/controller/checkout/success/after (to modify the <header> section of the output for the given order_id, and then to clear the session variable)

Having said that, don't use Journal3, use a proper standard-compliant web theme. But in this case, above approach could even work for the Journal3 framework, too.

Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig


User avatar
Guru Member

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by fguzels » Wed Nov 04, 2020 6:10 pm

pprmkr wrote:
Sun Sep 23, 2018 2:52 pm
First edit catalog/controller/checkout/success.php:
After:

Code: Select all

if (isset($this->session->data['order_id'])) {
Paste:

Code: Select all

			$data['transaction_id'] = $this->session->data['order_id'];
			$data['cart_total'] = $this->cart->getTotal();
Then edit catalog/view/theme/default/template/common/success.twig:
Before:

Code: Select all

{{ footer }}
Paste:

Code: Select all

{% if transaction_id is defined %}
	transaction ID = {{ transaction_id }}
	cart Total = {{ cart_total }}
	Use these values if needed as parameter in tag.js
	for example:
	<!-- Event snippet for Example conversion page -->
    <script>
      gtag('event', 'conversion', {'send_to': 'AW-123456789/AbC-D_efG-h12_34-567',
        'value': {{ cart_total }},
        'currency': 'USD',
        'transaction_id': '{{ transaction_id }}'
      });
    </script>

{% endif %}
Edit code to fit your needs.

Thank you so much.
It works, but I didn't add the code to the head field. I added it on the footer as in the quote but the tag assistant still reads. Is it ok if I don't add it to the head area?

Image

Attachments

adsS.png

adsS.png (158.64 KiB) Viewed 2589 times


Newbie

Posts

Joined
Sat Oct 17, 2020 2:35 am

Post by fguzels » Wed Nov 04, 2020 6:13 pm

JNeuhoff wrote:
Tue Nov 03, 2020 11:22 pm
This requires event handlers for the triggers catalog/controller/checkout/success/before (to save the order_id into a session variable), and catalog/controller/checkout/success/after (to modify the <header> section of the output for the given order_id, and then to clear the session variable)

Having said that, don't use Journal3, use a proper standard-compliant web theme. But in this case, above approach could even work for the Journal3 framework, too.
Sorry, I could not understand what you mean. It may be because my English is not sufficient. Do you think the above method is correct?

Newbie

Posts

Joined
Sat Oct 17, 2020 2:35 am

Post by straightlight » Wed Nov 04, 2020 8:13 pm

fguzels wrote:
Wed Nov 04, 2020 6:13 pm
JNeuhoff wrote:
Tue Nov 03, 2020 11:22 pm
This requires event handlers for the triggers catalog/controller/checkout/success/before (to save the order_id into a session variable), and catalog/controller/checkout/success/after (to modify the <header> section of the output for the given order_id, and then to clear the session variable)

Having said that, don't use Journal3, use a proper standard-compliant web theme. But in this case, above approach could even work for the Journal3 framework, too.
Sorry, I could not understand what you mean. It may be because my English is not sufficient. Do you think the above method is correct?
It's not. You're editing core files while event handlers are being suggested.

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 JNeuhoff » Wed Nov 04, 2020 8:26 pm

You can use event handlers to modify core files. better than OCmod.

Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig


User avatar
Guru Member

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by fguzels » Thu Nov 05, 2020 3:45 pm

straightlight wrote:
Wed Nov 04, 2020 8:13 pm
It's not. You're editing core files while event handlers are being suggested.
JNeuhoff wrote:
Wed Nov 04, 2020 8:26 pm
You can use event handlers to modify core files. better than OCmod.
I don't know how to do this.

Newbie

Posts

Joined
Sat Oct 17, 2020 2:35 am

Post by straightlight » Thu Nov 05, 2020 8:58 pm

fguzels wrote:
Thu Nov 05, 2020 3:45 pm
straightlight wrote:
Wed Nov 04, 2020 8:13 pm
It's not. You're editing core files while event handlers are being suggested.
JNeuhoff wrote:
Wed Nov 04, 2020 8:26 pm
You can use event handlers to modify core files. better than OCmod.
I don't know how to do this.
Documentation: https://github.com/opencart/opencart/wiki/Events-System .

However, if you are unable to follow this documentation, you could always create a new service request in the Commercial Support section of the forum, or contact an Opencart partner by using the resources link at the top of the site, or contact me directly via PM to get this done 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 straightlight » Fri Nov 06, 2020 11:05 am

In catalog/controller/event folder, create a controller file called: ads.php. Then, paste the following:

Code: Select all

<?php
class ControllerEventAds extends Controller {
	// catalog/controller/checkout/success/after
	public function index(&$route, &$args, &$output) {
		if (isset($this->session->data['order_id'])) {
			$this->load->model('checkout/order');
			
			$order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
			
			if ($order_info) {
				$data = $this->response->getOutput();
				
				if ($data) {
					$data['ads'] = $this->load->controller('checkout/ads');
					
					$output .= str_replace('{{ footer }}', '{% if ads %}{{ ads }}{% endif %}' . "\n{{ footer }}", $output);
				}
			}
		}
	}
}
Then, in your catalog/controller/checkout/ads.php file, add:

Code: Select all

<?php
class ControllerCheckoutAds extends Controller {
	public function index() {
		if (isset($this->session->data['order_id'])) {
			$data['transaction_id'] = $this->session->data['order_id'];
			$data['cart_total'] = $this->cart->getTotal();
		
			return $this->load->view('checkout/ads');
		}
	}
}
Then, in your catalog/view/theme/<your_theme>/template/checkout folder, create a TWIG file called: ads.twig .

Add:

Code: Select all

{% if transaction_id is defined %}
	transaction ID = {{ transaction_id }}
	cart Total = {{ cart_total }}
	Use these values if needed as parameter in tag.js
	for example:
	<!-- Event snippet for Example conversion page -->
    <script>
      gtag('event', 'conversion', {'send_to': 'AW-123456789/AbC-D_efG-h12_34-567',
        'value': {{ cart_total }},
        'currency': 'USD',
        'transaction_id': '{{ transaction_id }}'
      });
    </script>
{% endif %}
Then, in your PHPMyAdmin, on your oc_event table, add:

Code: Select all

INSERT INTO `oc_event` (`code`, `trigger`, `action`, `status`, `sort_order`) VALUES ('checkout_ads', 'catalog/controller/checkout/success/after', 'event/ads', 1, 0);
This should resolved the issue.

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 JNeuhoff » Fri Nov 06, 2020 4:48 pm

The catalog/controller/event and catalog/controller/checkout folders are not among the ones which are allowed to take files from OpenCart extensions. Your class files should go into the catalog/controller/extension folder. Otherwise, the only way to add these new files is via FTP instead of the OpenCart installer. Quote often I bundle all the new files into an upload folder, and create an installable ocmod.zip archive for the OC installer.

Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig


User avatar
Guru Member

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by straightlight » Fri Nov 06, 2020 8:23 pm

JNeuhoff wrote:
Fri Nov 06, 2020 4:48 pm
The catalog/controller/event and catalog/controller/checkout folders are not among the ones which are allowed to take files from OpenCart extensions. Your class files should go into the catalog/controller/extension folder. Otherwise, the only way to add these new files is via FTP instead of the OpenCart installer. Quote often I bundle all the new files into an upload folder, and create an installable ocmod.zip archive for the OC installer.
The catalog/controller/extension folder are for group extensions which, also, are loaded from the header. I would not advise to create event triggers into that location since this folder is not being used for the same concept as Events especially if it needs to be shown to others on the forum. As for the installable OCMod ZIP files, using the checkout folder is still available since the project files are still being stored in the storage folder. The idea on the above was to show how the Events themselves works. Afterwards, the concept remains the same on how and where the project files should be stored into as opposed to work directly on core files.

As for the event folder, perhaps both triggers could be launched from the checkout folder under two separated methods instead of both using index() and modify their targets from the oc_event. That's another way to do it.

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 JNeuhoff » Fri Nov 06, 2020 9:17 pm

The admin/controller/marketplace/install.php only list these allowable folders:

Code: Select all

				// A list of allowed directories to be written to
				$allowed = array(
					'admin/controller/extension/',
					'admin/language/',
					'admin/model/extension/',
					'admin/view/image/',
					'admin/view/javascript/',
					'admin/view/stylesheet/',
					'admin/view/template/extension/',
					'catalog/controller/extension/',
					'catalog/language/',
					'catalog/model/extension/',
					'catalog/view/javascript/',
					'catalog/view/theme/',
					'system/config/',
					'system/library/',
					'image/catalog/'
				);
Though I agree, it would make more sense to have the event classes in the catalog/controller/event folder. I have to try it out again.

Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig


User avatar
Guru Member

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by straightlight » Fri Nov 06, 2020 10:02 pm

The system/config profiles can already instantiate new events (new config files, for instance). In the master branch version, however, the extensions loaded from the installer have been widely modified since recently.

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: Amazon [Bot] and 4 guests