20

What is the name of the event that is dispatched when a customer clicks "Go To Checkout" after adding stuff on their cart? I want to register that a user started a checkout process for analytics. Specifically, I need to capture the contents of the cart and other information such as total price etc.

I've tried most of the events on this list that are related to either "checkout" or "cart". None of them seem to be dispatched when a user clicks checkout. The nearest that I could get was

controller_action_predispatch_checkout_cart_index

which is dispatched when a user clicks "View and Edit Cart".

I'm looking at a couple of ways to solve this

  1. Get the name of the event that is dispatched when a user clicks "Go To Checkout". Observe that event and "hook" my code to it.
  2. Or is there a way to see all the events that are being dispatched in real time? I'm thinking that I might be able to find some other event that is dispatched near the same time as checkout and then observe that one.
dchayka
  • 1,291
  • 12
  • 20
satnam
  • 1,457
  • 4
  • 23
  • 43

6 Answers6

3

Use controller_action_predispatch_checkout_index_index.

Tunaki
  • 132,869
  • 46
  • 340
  • 423
Poorvi Dubey
  • 51
  • 1
  • 7
0

You can use checkout_cart_save_before this event which you can find in vendor/magento/module-checkout/Model/Cart.php

Search following code snippet:

$this->_eventManager->dispatch('checkout_cart_save_before', ['cart' => $this]);

Hope this helps you

0

Probably, this is a second way you are looking for. You can log all events in "\Magento\Framework\Event\Manager::dispatch" method (file ./vendor/magento/framework/Event/Manager.php):

public function dispatch($eventName, array $data = [])
{
    $obm = \Magento\Framework\App\ObjectManager::getInstance();
    /** @var  $logger \Psr\Log\LoggerInterface */
    $logger = $obm->get(\Psr\Log\LoggerInterface::class);
    $logger->debug($eventName);
    // original code
    $eventName = mb_strtolower($eventName);
    ...
}

Log files are placed in "./var/log" folder

Alex Gusev
  • 1,526
  • 3
  • 16
  • 35
0

I think it should be

    sales_quote_save_after

Hope, it helps you out.

Abhishek Dhanraj Shahdeo
  • 1,356
  • 2
  • 14
  • 35
0

If I want to log all events that are dispatched after some certain interaction, I go to Magento\Framework\Event\Manager and set a breakpoint in the dispatch method that logs $eventName to the console.

You can also add a log statement or write a plugin in a custom module that logs the event name to some file.

There are many events dispatched when you click Go to checkout, maybe checkout_cart_save_before is the one you are looking for.

bpoiss
  • 13,673
  • 3
  • 35
  • 49
  • Modify core inadmissible in Magento, please do not teach like that even saying that is a dirty hack – bxN5 Sep 10 '18 at 22:06
0

use layout_render_before_checkout_index_index or controller_action_predispatch_checkout_index_index

AlexanderPop
  • 141
  • 1
  • 3