blauwfruit / PrestaShop-Order-Reference

PrestaShop module that customizes the order reference of an order.
24 stars 6 forks source link

global order in hookActionValidateOrder #2

Closed N-Wouda closed 3 years ago

N-Wouda commented 3 years ago

Hey guys, thanks for your module!

In:

https://github.com/blauwfruit/PrestaShop-Order-Reference/blob/b9f1d8c8f91f97fc9ba708c5cb02c2083de23ccc/orderreference.php#L129-L135

Is there a reason you need to add the order to the list of globals? I quite like this module and intend to use it for a client, but I'm hesitant to add one that pollutes the global namespace without knowing why.

muyncky commented 3 years ago

Hi @N-Wouda,

That is for now, the only way to change the Order::$reference before all other processing are executed. You should think about all other modules that want use Order, like payment modules, etc. We are also not super happy to use global, but it seems to have a good use case here. I'm also thinking about maybe registrering a hook like actionOrderAdd, but I'm not sure that hook exists.

N-Wouda commented 3 years ago

There is a actionObjectOrderAddBefore (and similarly an UpdateBefore) hook that's executed in ObjectModel::add (resp, ::update). You might be able to use those instead?

muyncky commented 3 years ago

@N-Wouda that is a good suggestion. I havent been able to have a look at this my self. If you worked on a solution you can make a pull request!