2

In OpenCart 2, I am editing the appearance/php of the header only in the "success"/"thank you" page (catalog/view/theme/*/template/common/success.tpl).

So, in catalog/view/theme/*/template/common/header.tpl I want to do something like:

if( $is_thank_you_page ){
   echo "stuff";
   // bonus: I wanted to get the order email but maybe it should be a different post
}

But how can I check in the header.tpl if it is the "success"/"thank you" page?

I tried setting a variable in success.tpl before printing the header with no results.

focus.style
  • 6,612
  • 4
  • 26
  • 38

3 Answers3

1

You could try something like this (go about it based on your URL):

<?php 
$parameters = explode('/', $_SERVER['REQUEST_URI']);

if(end($parameters) === 'success.tpl'){ 
    //the condition with $parameters depends on the exact look of your URL
    //you could also access an index directly
}

Basically, it takes the REQUEST_URI (part after the domain), splits it around the / symbols and then checks if it ends with success.tpl

You could also make a switch for the end($parameters) instead of the if.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Morgosus
  • 807
  • 5
  • 18
0

I don't know opencart structure, but if this value never change you can try with strpos/stripos, something like:

if(stripos($var_with_page_title, 'thank you') !== false) {
    do_something();
}
0

If you want you detect checkout/success page in you header, do following:

open catalog/controller/common/header.php

find

// Menu
$this->load->model('catalog/category');

Add before

// success page checking 
$data['success'] = '';
if (isset($this->request->get['route']) && $this->request->get['route'] == 'checkout/success') {
  $data['success'] = true;
}

// looking for email from the order
$data['success_email'] = '';
if ($this->customer->isLogged()) {
  $data['success_email'] = $customer_info['email'];
} elseif (isset(this->session->data['guest']['email'])) {
  $data['success_email'] = $this->session->data['guest']['email'];
}

Now in catalog/view/theme/YOUR_THEME/template/common/header.tpl

add anywhere you like

<?php if ($success) { ?>
  //do something
  <?php if ($success_email) { ?><?php echo $success_email; ?><?php } ?>
<?php } ?>

With bonus email

focus.style
  • 6,612
  • 4
  • 26
  • 38
  • No, unfortunately neither works. I understand that I need to set the variables in the form of `$data['foo']` but maybe the email is cleared from the session by that time. Then again I do not know why `$data['success']` is not passed – the1_fisherman Aug 31 '20 at 21:49
  • Have you cleared OCMOD cache? Email is clearing from session by the time, but not just after checkout. I will test it again tomorrow and update the answer. Keep in touch. $data['success'] should work, already checked it – focus.style Aug 31 '20 at 21:53