2

EE 2.7.2 Store 2.0.3

It doesn't look like the hook (store_order_recalculate_end) is happening as advertised. Works fine when adding the first item to the cart. But upon cart update or adding more items, not happening.

Here is a dead simple test in my extension. (via template logging)

...
'hook' => 'store_order_recalculate_end',
'method' => 'barfoo',
...

public function barfoo(){

    $this->EE->load->library('Template', null, 'TMPL');
    $this->EE->TMPL->log_item("Hello World");

    }

What else can I be doing? Where should I be looking? This method definitely does not happen after the first item is added to the cart.

Thanks for the help.

3

It looks like the hooks were running, but it was more a case of the logged messages not appearing.

Store uses the Post-Redirect-Get pattern, which means that the cart is updated (and hooks run) during an HTTP POST request. When the cart has finished updating (unless there were any errors), it redirects the customer's browser back to the checkout page using a GET request (this prevents them from accidentally resubmitting the form when hitting refresh etc).

Therefore in your case the messages logged in the template library were lost when the customer's browser was redirected, hence why they weren't displayed.

  • Quick followup, if I may. Is it true that none of these hooks run when we use the "Empty Cart" button? – Steve Mock Oct 22 '13 at 13:12
  • Correct, the cart doesn't get recalculated when you empty it (Store just unsets the user's cookie). We could certainly add an extra hook to run when the cart is emptied if you need it though. – Adrian Macneil Oct 22 '13 at 16:48
  • Well, if you get to it that would be cool. But I can certainly get around it for the time being. I see you've already added a couple more in 2.0.4 – Steve Mock Oct 22 '13 at 17:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.