opencart how to addEvent Journal3?

438 Views Asked by At

work fine in default opencart checkout example..

  1. $this->model_setting_event->addEvent('custom_name', 'catalog/view/theme/default/template/checkout/payment_method/after', 'event_function');
  2. $this->model_setting_event->addEvent('custom_name', 'catalog/controller/checkout/payment_method/save/after', 'event_function');
  3. $this->model_setting_event->addEvent('custom_name', 'catalog/model/checkout/order/addOrder/before', 'event_function');

how can i make it work with journal3 one checkout page?

opencart 3.0.2.0

2

There are 2 best solutions below

0
Stern Chen On BEST ANSWER

There are 2 approaches, you can choose either one to implement based on which approach is more applicable to your situation:

  1. Replace the view file before rendering the output
  2. Modify the html through the output

I assuming you already know how to register an event, following example just demonstrate how to implement the approach. Leave me a comment to let me know if you not sure how to register an event.

1. Replace the view file before rendering the output

Create an event script: catalog/controller/event/my_event.php

/* before */
public function beforeLoadCheckoutView(&$route, &$args) {
    /*
        if the view route is 'journal3/checkout/checkout',
        aka: 'catalog/view/theme/journal3/template/journal3/checkout/checkout.twig'
    */
    if ($route == 'journal3/checkout/checkout') {
        /*
            replace the view file 'journal3/checkout/checkout' with your own view file
            aka: 'catalog/view/theme/journal3/template/journal3/checkout/my_checkout_page.twig'
        */
        $route = str_replace('journal3/checkout/checkout', 'journal3/checkout/my_checkout_page', $route);
    }
}

Create your own checkout page view: catalog/view/theme/journal3/template/journal3/checkout/my_checkout_page.twig

<div>
    I have replace the original view with this!
</div>

Result:

enter image description here

2. Modify the html through the output

Create an event script: catalog/controller/event/my_event.php

/* after */
public function modifyCheckoutPageHtml($route, &$args, &$output) {
    /*
        if the view route is 'journal3/checkout/checkout',
        aka: 'catalog/view/theme/journal3/template/journal3/checkout/checkout.twig'
    */
    if ($route == 'journal3/checkout/checkout') {
        /* replace the title with your own title */
        $output = str_replace('<h1 class="title page-title">Quick Checkout</h1>', '<h1 class="title page-title">I have changed this title!</h1>', $output);
    }
}

Result:

enter image description here

7
NewSmile On

now I am suffering from new problem I can do some code when user click this button(繼續===continue)in default 6step checkout through

$this->model_setting_event->addEvent('name','catalog/controller/checkout/payment_method/save/after', 'function');

enter image description here

but in journal3 one step checkout do not have that button.