[Skip to main content](#vessel-content)

#   Custom plugin

##

- **[diesel1984](/forum/user/30999-diesel1984 "View diesel1984's Profile")**
- [![diesel1984's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/30999-diesel1984 "View diesel1984's Profile") Topic Author
- [ Offline](/forum/user/30999-diesel1984)

Less More

- Posts: 32
- Thank you received: 0
-
-

12 years 4 months ago [\#162531](#162531) by [diesel1984](/forum/user/30999-diesel1984 "View diesel1984's Profile")  *[Custom plugin](/forum/27-checkout/869412-custom-plugin#162531 "Hi guys  I have successfully set up hikashop with the worldpay payment gateway and it all works great. However, I'd like to be able to run a little but of custom code ideally when worldpay silently posts back to my site or if not when the customer returns to my site by clicking on the button on worldpay to return to my site. I'm thinking that ill have to write a custom plugin to achieve this? If so which plugin event would I have to write a plugin for? I'd like to fire the code in the same execution cycle that the basket is cleared out and the order status is updated after the customer makes a successful payment on worldpay if possible?  Thanks for your help")* was created by *[diesel1984](/forum/user/30999-diesel1984 "View diesel1984's Profile")*

Hi guys

I have successfully set up hikashop with the worldpay payment gateway and it all works great. However, I'd like to be able to run a little but of custom code ideally when worldpay silently posts back to my site or if not when the customer returns to my site by clicking on the button on worldpay to return to my site. I'm thinking that ill have to write a custom plugin to achieve this? If so which plugin event would I have to write a plugin for? I'd like to fire the code in the same execution cycle that the basket is cleared out and the order status is updated after the customer makes a successful payment on worldpay if possible?

Thanks for your help

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI3LWNoZWNrb3V0Lzg2OTQxMi1jdXN0b20tcGx1Z2luP3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Away](/forum/user/63-nicolas)

Less More

- Posts: 86587
- Thank you received: 14326
-
-

12 years 4 months ago [\#162541](#162541) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Custom plugin](/forum/27-checkout/869412-custom-plugin#162541 "Hi guys  I have successfully set up hikashop with the worldpay payment gateway and it all works great. However, I'd like to be able to run a little but of custom code ideally when worldpay silently posts back to my site or if not when the customer returns to my site by clicking on the button on worldpay to return to my site. I'm thinking that ill have to write a custom plugin to achieve this? If so which plugin event would I have to write a plugin for? I'd like to fire the code in the same execution cycle that the basket is cleared out and the order status is updated after the customer makes a successful payment on worldpay if possible?  Thanks for your help")*

Hi,

You can create a HikaShop implementing the onAfterOrderUpdate trigger.
In it, just check the old and new status of the order: Code:

function onAfterOrderUpdate(&amp;$order){ if(@$order-&gt;order_status == 'confirmed' &amp;&amp; @$order-&gt;old-&gt;order_status=='created'){ //your custom code } }

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI3LWNoZWNrb3V0Lzg2OTQxMi1jdXN0b20tcGx1Z2luP3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[diesel1984](/forum/user/30999-diesel1984 "View diesel1984's Profile")**
- [![diesel1984's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/30999-diesel1984 "View diesel1984's Profile") Topic Author
- [ Offline](/forum/user/30999-diesel1984)

Less More

- Posts: 32
- Thank you received: 0
-
-

12 years 4 months ago [\#162647](#162647) by [diesel1984](/forum/user/30999-diesel1984 "View diesel1984's Profile")  Replied by *[diesel1984](/forum/user/30999-diesel1984 "View diesel1984's Profile")* on topic *[Custom plugin](/forum/27-checkout/869412-custom-plugin#162647 "Hi guys  I have successfully set up hikashop with the worldpay payment gateway and it all works great. However, I'd like to be able to run a little but of custom code ideally when worldpay silently posts back to my site or if not when the customer returns to my site by clicking on the button on worldpay to return to my site. I'm thinking that ill have to write a custom plugin to achieve this? If so which plugin event would I have to write a plugin for? I'd like to fire the code in the same execution cycle that the basket is cleared out and the order status is updated after the customer makes a successful payment on worldpay if possible?  Thanks for your help")*

Hi Nicolas,

Thanks for your help. That bit of code worked perfectly. However, for some reason i cannot seem to access the session data within this function. Is there a reason for this? I wanted to clear out some custom session data when after the user has paid for his order and when he his returned to the site...So my function now looks like:-
Code:

public function onAfterOrderUpdate(&amp;$order,&amp;$send_email) { if((@$order-&gt;old-&gt;order_status=='created') &amp;&amp; (@$order-&gt;order_status == 'verified')) { $session =&amp; JFactory::getSession(); $session-&gt;clear('samplebox_cid'); $session-&gt;clear('samplebox_img'); $session-&gt;clear('samplebox_name'); } return true; }

Thanks for all your help

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI3LWNoZWNrb3V0Lzg2OTQxMi1jdXN0b20tcGx1Z2luP3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[Jerome](/forum/user/80-jerome "View Jerome's Profile")**
- [![Jerome's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar80.png)](/forum/user/80-jerome "View Jerome's Profile")
- [ Offline](/forum/user/80-jerome)
- HikaShop core developer

Less More

- Posts: 26402
- Thank you received: 4081
-
- [](http://obsi.dev)
-

12 years 4 months ago [\#162650](#162650) by [Jerome](/forum/user/80-jerome "View Jerome's Profile")  Replied by *[Jerome](/forum/user/80-jerome "View Jerome's Profile")* on topic *[Custom plugin](/forum/27-checkout/869412-custom-plugin#162650 "Hi guys  I have successfully set up hikashop with the worldpay payment gateway and it all works great. However, I'd like to be able to run a little but of custom code ideally when worldpay silently posts back to my site or if not when the customer returns to my site by clicking on the button on worldpay to return to my site. I'm thinking that ill have to write a custom plugin to achieve this? If so which plugin event would I have to write a plugin for? I'd like to fire the code in the same execution cycle that the basket is cleared out and the order status is updated after the customer makes a successful payment on worldpay if possible?  Thanks for your help")*

Hi,

The order can be updated in different context : a validation in backend, a payment gateway notification, etc.
So, yes you can't access to the user session because you're not running in the same session that the user.

Regards,

---

Jerome - Obsidev.com
HikaMarket &amp; HikaSerial developer / HikaShop core dev team.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI3LWNoZWNrb3V0Lzg2OTQxMi1jdXN0b20tcGx1Z2luP3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[fengel](/forum/user/37465-fengel "View fengel's Profile")**
- [![fengel's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar37465.jpg)](/forum/user/37465-fengel "View fengel's Profile")
- [ Offline](/forum/user/37465-fengel)

Less More

- Posts: 27
- Thank you received: 4
-
-

11 years 1 month ago -  11 years 1 month ago [\#218489](#218489) by [fengel](/forum/user/37465-fengel "View fengel's Profile")  Replied by *[fengel](/forum/user/37465-fengel "View fengel's Profile")* on topic *[Custom plugin](/forum/27-checkout/869412-custom-plugin#218489 "Hi guys  I have successfully set up hikashop with the worldpay payment gateway and it all works great. However, I'd like to be able to run a little but of custom code ideally when worldpay silently posts back to my site or if not when the customer returns to my site by clicking on the button on worldpay to return to my site. I'm thinking that ill have to write a custom plugin to achieve this? If so which plugin event would I have to write a plugin for? I'd like to fire the code in the same execution cycle that the basket is cleared out and the order status is updated after the customer makes a successful payment on worldpay if possible?  Thanks for your help")*

It's understandable that the event can be triggered from anywhere, therefore the session can't be the same as the one the user has. However, what if I wanted to enqueue a system message to display back to the user?

How could something like this work?: Code:

public function onAfterOrderUpdate(&amp;$order, &amp;$sendmail) { parent::onAfterOrderUpdate($order, $sendmail); // do some other stuff // This message won't make it to after_end.php JFactory::getApplication()-&gt;enqueueMessage('critical message here'); }

Last edit: 11 years 1 month ago by [fengel](/forum/user/37465-fengel "View fengel's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI3LWNoZWNrb3V0Lzg2OTQxMi1jdXN0b20tcGx1Z2luP3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Away](/forum/user/63-nicolas)

Less More

- Posts: 86587
- Thank you received: 14326
-
-

11 years 1 month ago [\#218494](#218494) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Custom plugin](/forum/27-checkout/869412-custom-plugin#218494 "Hi guys  I have successfully set up hikashop with the worldpay payment gateway and it all works great. However, I'd like to be able to run a little but of custom code ideally when worldpay silently posts back to my site or if not when the customer returns to my site by clicking on the button on worldpay to return to my site. I'm thinking that ill have to write a custom plugin to achieve this? If so which plugin event would I have to write a plugin for? I'd like to fire the code in the same execution cycle that the basket is cleared out and the order status is updated after the customer makes a successful payment on worldpay if possible?  Thanks for your help")*

The short answer is : it depends ![:)](/media/kunena/emoticons/3.png ":)")

The long answer is:
Normally, with most payment methods, you're redirected to the payment gateway's payment page after the checkout. Then, once the payment is done, you're brought back to the after_end page where you see the thank you message.
The onAfterOrderUpdate trigger is called during the payment notification which is a server-to-server call from the payment gateway to the payment plugin. So it's not the same session as the session of the customer and thus, if you enqueueMessage a message in the onAfterOrderUpdate, that message will be displayed to the payment gateway server, not your customer.
Thus, that's not a good approach.
The best is to directly edit the file "after_end" of the view "checkout" via the menu Display&gt;Views and directly add your message there.
If it has to be dynamic based on data that you can only get in the onAfterOrderUpdate trigger, you can always store it in the hikashop_order table with a MySQL query and then retrieve it in the after_end view file. However, there is also a slim possibility that the payment notification will be received only after the customer is redirected to the after_end view file (that shouldn't be the case with most payment gateways in normal conditions, but it will likely happen (it happened a few times with PayPal in the past few years for example) ) and in that case, you won't be able to do a dynamic message based on the onAfterOrderUpdate available data.

The following user(s) said Thank You: [fengel](/forum/user/37465-fengel "View fengel's Profile")

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI3LWNoZWNrb3V0Lzg2OTQxMi1jdXN0b20tcGx1Z2luP3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

Board Categories HikaShop Install &amp; Update Product &amp; Category Display Content Creation Sales and Orders Orders management Reports &amp; Statistics Customers Checkout Payment Methods Shipping Methods Import &amp; Export (CSV, XLS…) Specific Features Affilation Taxes Wishlist Vote Carousel &amp; Slider Mass Actions Filters &amp; Search Discount &amp; Coupon Feature Request Integrations Showcase General Talk about HikaShop Development HikaShop 3.0 Beta Translation Commercial Jobs HikaShop Components HikaMarket Market: Feature requests Market: How to? Market: Bug Report HikaSerial General talk about HikaSerial Serial: Bug Report Serial: How to? Support en Français de HikaSerial (French Support) HikaSubscription HikaAuction Auction: Feature requests Auction: How to? Auction: Bug report Hikashop around the world Support en Français (French Support) Russian FAQ. Курс выживания с Hikashop. Частые вопросы и о Расширения Hikashop Наши сайты на Hikashop 日本語版サポート(Japanese Support) Thai German Archives Bug Report How to?

[](/forum/topics/feed/mode-topics?format=feed&type=rss)

Time to create page: 0.062 seconds

[Powered by](/forum/credits) [Kunena Forum](https://www.kunena.org)
