- Posts: 32
- Thank you received: 2
Problems getting custom onAfterOrderCreate to work
I created a zip containing a modified set of three files (contents below), same as the History plugin. Joomla quite happily installed this new plugin, and it's showing as enabled in the plugins list. Hikashop also shows my custom plugin and allows me to configure it. I added a "mail()" line to the History plugin, same as my custom plugin, but when I order a test product, I get the email from the History plugin but not the custom plugin (and also get the "order confirmed" email).
Here's the hikasim.php file:
Here's the XML file:
I've masked/removed personal bits. Although I'm using Joomla 2.5 and the notes above refer to 1.5, the history module seems to work okay - backward compatible I guess. I'm using the free/basic version of Hikashop.
Any ideas please? Thanks.
Please Log in or Create an account to join the conversation.
First of all, in your mail function try to change the
Please Log in or Create an account to join the conversation.
Xavier wrote: Hi GeoffM,
First of all, in your mail function try to change thebyCode:"Order ID: " + $order->order_idIn your XML file, I'm not sure that you need the <params> tag.Code:"Order ID: ".$order->order_id
Hi, thanks for the reply. The Mail() line is the same in the History module and my plugin (apart from subject line to differentiate between the two); it works from the History but not from my plugin. Anyway, I changed it and there was no difference - History mails, my plugin doesn't.
Please Log in or Create an account to join the conversation.
plgHikashopHikasim and not plgHikashopSim.
Since Joomla's event dispatcher doesn't found the correct class, it doesn't use your plugin.
Please Log in or Create an account to join the conversation.
nicolas wrote: In your XML your plugin name is hikasim and its group is hikashop, so the plugin class name should be:
plgHikashopHikasim and not plgHikashopSim.
Since Joomla's event dispatcher doesn't found the correct class, it doesn't use your plugin.
Thanks, that sounds logical. However, assuming you mean to change the <filename plugin=...> line, it still doesn't work! Instead what happens now is Joomla installs into a directory called plgHikashopSim. In addition, this doesn't match the History plugin which has:
<filename plugin="history">history.php</filename>
and
class plgHikashopHistory extends JPlugin
I'll investigate further later.
Please Log in or Create an account to join the conversation.
class plgHikashopSim extends JPlugin
to:
class plgHikashopHikasim extends JPlugin
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
So I decided I just needed to change the method name to
. However, I can't get that to fire. I thought maybe it was a typo but I copied it directly from the dev manual. Does anybody have any ideas please? The very first "mail" line never gets called. All I've done is change the method name (and was only using the order parameter, so that shouldn't be an issue).function onAfterOrderConfirm(&$order,&$methods,$method_id){
The ####s are where I've masked things out in this post.
Please Log in or Create an account to join the conversation.
First of all your class name is different as your function name, try to change it. Else I don't see any problems.
Please Log in or Create an account to join the conversation.
Xavier wrote: Hi,
First of all your class name is different as your function name, try to change it. Else I don't see any problems.
I appreciate the response but I don't see how that can help. Hikashop is looking for a class named in a particular way (see Nicolas' post). Then surely the functions contained within that class must match the onAfterXXX/onBeforeXXX methods?
Please Log in or Create an account to join the conversation.
class plgHikashoppaymentPaypal extends JPlugin
and the method as follows:
function onAfterOrderConfirm(&$order,&$methods,$method_id){
Also other methods like function onPaymentNotification(&$statuses) and function onPaymentDisplay(&$order,&$methods,&$usable_methods).
I must have a typo somewhere but for the life of me I can't find it. No errors or warnings are generated (unless I deliberately type nonsense, then it does show an error).
Please Log in or Create an account to join the conversation.
What I have managed to do, however, is use onAfterOrderUpdate:
However, the foreach never fires, presumably because the cart is empty at this point. I set the option "Clean cart when order is " to "confirmed" but that doesn't affect anything. I do wonder whether another plugin is emptying the cart, or maybe the system calls this after emptying the cart while in the confirmed stage.
Failing that, there must be something else in $order to find out what was ordered! More digging and reading.
Please Log in or Create an account to join the conversation.
What Xavier would told you is that the "constructor" function would not be called. So some parameters could not be loaded correctly by your plugin.
Please use "__construct" in order to be sure that the function would be called, even if you change the class name.
About your other problem. After a "Order Update", you might not have the complete cart.
What you can do is to load the full order.
Best regards,
Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.
Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.
Please Log in or Create an account to join the conversation.
Jerome wrote: Hi,
What Xavier would told you is that the "constructor" function would not be called. So some parameters could not be loaded correctly by your plugin.
Please use "__construct" in order to be sure that the function would be called, even if you change the class name.
To be honest, this is just as cryptic. All I can think of is that the constructor is supposed to have the same name as the class. Like C/C++/C# I guess. Like I say, I'm not a PHP programmer.
In any case, trying it of course it makes zero difference because we already know that two methods already get called; the third doesn't. Quite why is beyond me, and the documentation offers no clues, nor does poring through various other pieces of code. In fact I don't even know what that constructor is doing: I simply followed the instructions in the dev manual to examine the History plugin.
Jerome wrote: About your other problem. After a "Order Update", you might not have the complete cart.
What you can do is to load the full order.At this moment, you would have the complete full order, with cart etc.Code:$orderClass = hikashop_get('class.order'); $full_order = $orderClass->loadFullOrder($order->order_id, true, false);
Best regards,
Still nothing. I can email myself just before the foreach and that gets received. Another email just inside the foreach never gets called. Here's the relevant chunk of code:
I looked up loadFullOrder to see what those parameters were. ABout the only mention of it was "You can look at the function loadFullOrder for more information...". Fine. Where? Am I supposed to pore through code to work out what it does?
Please Log in or Create an account to join the conversation.
loadFullOrder would load products in the $full_order->products array.
It would load addresses in $full_order->shipping_address and $full_order->billing_address objects.
$order->cart is for cart objects which "are becoming" orders (in triggers : onBeforeOrderCreate, onAfterOrderConfirm)
Regards,
Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.
Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.
Please Log in or Create an account to join the conversation.
I wish my server supported .net.
Please Log in or Create an account to join the conversation.
After putting various debugging into the plugin and my own code, here is what have:
Just before the "return true" I put some debugging in which correctly gets triggered, so I know that execution is returning from my stuff and back into the HikaShop code. I also have this code, in the same file:
Now, admittedly I'm struggling to determine whether this actually gets called. However, I do know from the database that the order_status is created, not confirmed, so the second "if" fails.
I only have a PayPal payment method so everything is through that. When a customer orders a product I get an email from PayPal to confirm that payment has been made, with the HikaShop order number contained in that email. So it would seem that somehow there is a PayPal->payment confirmed->HikaShop order confirmed interaction issue. I've no ideas why though, whether it's a misconfiguration on my end or whatever. Any ideas appreciated.
Please Log in or Create an account to join the conversation.
I made a fix in the MassAction system, the package has been updated so you can download it.
It should resolve your problem.
Regards,
Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.
Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.
Please Log in or Create an account to join the conversation.
Jerome wrote: Hi,
I made a fix in the MassAction system, the package has been updated so you can download it.
It should resolve your problem.
Regards,
Wow, that was quick - thank you! Only issue is, where do I download it from? The download page still shows V2.2.0, albeit dated today and the package I downloaded earlier appears to be binary identical to one just now. This assumes you mean to download the entire Hika package rather than just the MassAction plugins/mods/whatever?
Please Log in or Create an account to join the conversation.
The version did not grow up, we do not push HikaShop 2.2.0 available in the auto-updater yet.
You can reinstall HikaShop 2.2.0 over HikaShop 2.2.0, it will just update the files.
Regards,
Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.
Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.
Please Log in or Create an account to join the conversation.