What does $dispatch_extra mean and why is it be used?
?dispatch parameter values are dot (.) separated. I.e. ?dispatch=controller.mode.action.dispatch_extra
These are all set for you to be used in your controller.
The most common thing you might see is ?dispatch=cart.add..$product_id
which adds the product $product_id to the cart. Since the $action parameter is empty, it will default to quantity 1. If instead
?dispatch=cart.add.25.$product_id, then quantity would be set to 25.
Hope this helps you understand how all this is used.
I think I understand but what if I need it in a function?
I tried it in my addon. If I use $dispatch_extra like this
if ($mode == 'blablabla') {if ($dispatch_extra && !empty($_REQUEST[‘order_ids’])) {
…
}}
in orders.post.php there is NO problem , but if I use the same code in func.php in my addon I experience a problem. It says:
Undefined variable: dispatch_extra
I think I need to define $dispatch_extra variable. But what to define?
Can I use $dispatch_extra only in modes??
I understrand. I need to post value like this:
data-ca-dispatch="dispatch[orders.mode_name..{$any_value}]"
Then I can get it by using $dispatch_extra variable in mode like this:
if ($mode == 'mode_name') {if($dispatch_extra) { ..... }
}
Correct?
In checking the mode, yes. If you want to get it in a function, use Registry::get('runtime.dispatch_extra');
I understrand. I need to post value like this:
data-ca-dispatch="dispatch[orders.mode_name..{$any_value}]"Then I can get it by using $dispatch_extra variable in mode like this:
if ($mode == 'mode_name') {if($dispatch_extra) { ..... }
}
Correct?
Correct! Example can be found in the app/controllers/frontend/checkout.php file