2

I'm not sure if is deliberate, but the way hooks have been implemented in Exp:resso Store don't seem to allow the modification of data?

Using pass by reference has no effect (because of EE's hook calling approach?); any changes made to the data passed in the params is not available in the same variables in the hook calling method.

And there doesn't seem to be any point returning data from the extension method because there is no assignment in the Order model's addItem method, where the hook is called.

Are the hooks designed to expose data for reading-only? If I have to start hacking the Store logic code to add an assignment, or messing about modifying the records in the database, then the likelihood of functionality breaking with an update is high.

I'm disappointed this type of situation wasn't envisioned by the module developers. Why limit the hooks like this?

2

I have often used store_order_item_add_end to modify product attributes. $item is an object, and pass by reference does indeed work in this context.

So this code in your extension should change every item's price to $20:

$item->price = '20.00';

I have several sites doing this for items which I have javascript-driven price configurations for, and for which I want to confirm server-side to protect from being artificially modified in the browser.

| improve this answer | |
  • Thanks, Derek! FWIW, Tom, Derek's suggestion worked great for me in a quick test when I switched over to using store_order_item_add_end instead of store_order_item_add_start -- having access to $item was what I was missing in my tests. – Alex Kendrick Feb 2 '15 at 21:28
  • I was trying to modify the contents of the $item_attributes param, which I tried altering to pass by reference (had no effect). I also tried to access the $order->items array in the store_order_item_add_end hook, but strangely this wasn't defined. I'd presumed that since $item had already been added to the $order->items array in the addItem logic flow (before the store_order_item_add_end hook was called), that it was too late to change the contents of $item. Really wish the documentation was better for the hooks - not just "read the module code to figure these out"! – Tom Feb 3 '15 at 9:27
0

What Store hook are you using? You can definitely modify Store data using an extension. Did you try using $order->save() ?

For example

public function store_order_complete_start($order)
{   

    // Save some custom data on the order
    $order->order_custom4 = $my_custom_data;
    $order->save();

    return $order;
}
| improve this answer | |
  • 1
    store_order_item_add_start or store_order_item_add_end - i.e. the item is not yet part of the order, or in the database. store_order_complete_start looks like an order completion hook (so the data is in the db already). – Tom Feb 2 '15 at 17:21
  • Ah, right. You said that in the title of your question. :-P I haven't made use of those hooks before myself and in a few quick tests I wasn't able to get anywhere. Sorry I can't be of more help, but I bet someone with more experience in that area will chime in here on using those hooks. You might get better help if you update your question with sample code and more info about your specific goals. – Alex Kendrick Feb 2 '15 at 18:26
  • Derek's answer hopefully gets you where you need to go, at least with the store_order_item_add_end hook. – Alex Kendrick Feb 2 '15 at 21:30

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.