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

#   plugin

##

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

Less More

- Posts: 28
- Thank you received: 1
-
-

3 years 11 months ago -  3 years 11 months ago [\#347427](#347427) by [highstat@highstat.com](/forum/user/70596-highstat-highstat-com "View highstat@highstat.com's Profile")  *[plugin](/forum/31-development/905522-plugin#347427 "-- Joomla version -- : 4.latest -- PHP version -- : 8.1  Hello,  I am writing a plugin that does the following upon successful payment:  1. Get the invoice number and email address of the customer. 2. Inspect the products that were ordered. 3. If products A, B and C were ordered (these are E-books), then add his/her email address to each page of an existing pdf file (E-book). And save the pdf. 4. Email the customer with a download link for the newly created pdf.  I am not an expert in php, but I know how to google. Step 3, I managed to program using the Setas package. Step 4 ... I still need to think about how to do this. As to steps 1 and 2.....I spent most of this day on your manual and Forums. I came up with the php code below. It seems to work ok.  My question is: Is this a valid way to obtain the invoice number and email address of the customer, and the products that were ordered? I am slightly confused why $cart = $cartClass-&gt;getFullCart(); is linked to the current order. Why can't you take the ordered products from the $order object? Would that not be better?  Alain  And this is the xml file")* was created by *[highstat@highstat.com](/forum/user/70596-highstat-highstat-com "View highstat@highstat.com's Profile")*

-- Joomla version -- : 4.latest
-- PHP version -- : 8.1

Hello,

I am writing a plugin that does the following upon successful payment:

1. Get the invoice number and email address of the customer.
2. Inspect the products that were ordered.
3. If products A, B and C were ordered (these are E-books), then add his/her email address to each page of an existing pdf file (E-book). And save the pdf.
4. Email the customer with a download link for the newly created pdf.

I am not an expert in php, but I know how to google. Step 3, I managed to program using the Setas package. Step 4 ... I still need to think about how to do this. As to steps 1 and 2.....I spent most of this day on your manual and Forums. I came up with the php code below. It seems to work ok.

My question is: Is this a valid way to obtain the invoice number and email address of the customer, and the products that were ordered? I am slightly confused why $cart = $cartClass-&gt;getFullCart(); is linked to the current order. Why can't you take the ordered products from the $order object? Would that not be better?

Alain

Code:

&lt;?php class plgHikashopSocialdrm extends JPlugin { function plgHikashopSocialdrm(&amp;$subject, $config){ parent::__construct($subject, $config); } // Execute code upon order confirmation function onAfterOrderUpdate(&amp;$order,&amp;$send_email){ if(!@include_once(rtrim(JPATH_ADMINISTRATOR,DS).DS.'components'.DS.'com_hikashop'.DS.'helpers'.DS.'helper.php')){ return false; } //Step 1: Get order ID, invoice number, user ID and email address $order_id = $order-&gt;order_id; $Output = 'Order id = ' . $order_id; hikashop_writeToLog($Output); $InvNum = $order-&gt;order_invoice_number; $Output ="Invoice number: " . $InvNum; hikashop_writeToLog($Output); $UserID = $order-&gt;order_user_id; $Output ="User ID: " . $UserID; hikashop_writeToLog($Output); $userClass = hikashop_get('class.user'); $user = $userClass-&gt;get($order-&gt;order_user_id); $UserEmail = $user-&gt;user_email; $Output ="User email: " . $UserEmail; hikashop_writeToLog($Output); //Step 2: Order confirmed? $app = JFactory::getApplication(); $config =&amp; hikashop_config(); $confirmed = $config-&gt;get('order_confirmed_status'); //If order is confirmed show the products. if($order-&gt;order_status == $confirmed){ //Load the current cart data: $cartClass = hikashop_get('class.cart'); $cart = $cartClass-&gt;getFullCart(); //The products in the cart will be available in the //attribute as an array of product objects: foreach($cart-&gt;products as $product) { hikashop_writeToLog($product-&gt;product_name); //TO BE EXTENDED WITH switch OR if TO CHECK WHETHER PRODUCTS A, B OR C WERE SELECTED. } } } }

And this is the xml file
Code:

&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;extension version="1.0" type="plugin" method="upgrade" group="hikashop"&gt; &lt;name&gt;Hikashop Social DRM&lt;/name&gt; &lt;author&gt;Alain Zuur&lt;/author&gt; &lt;creationDate&gt;December 2022&lt;/creationDate&gt; &lt;version&gt;1.0.0&lt;/version&gt; &lt;description&gt;Social DRM&lt;/description&gt; &lt;files&gt; &lt;filename plugin="socialdrm"&gt;socialdrm.php&lt;/filename&gt; &lt;/files&gt; &lt;/extension&gt;

Last edit: 3 years 11 months ago by [nicolas](/forum/user/63-nicolas "View nicolas's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMxLWRldmVsb3BtZW50LzkwNTUyMi1wbHVnaW4/dG1wbD1tYXJrZG93bg==) 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: 86541
- Thank you received: 14304
-
-

3 years 11 months ago [\#347428](#347428) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[plugin](/forum/31-development/905522-plugin#347428 "-- Joomla version -- : 4.latest -- PHP version -- : 8.1  Hello,  I am writing a plugin that does the following upon successful payment:  1. Get the invoice number and email address of the customer. 2. Inspect the products that were ordered. 3. If products A, B and C were ordered (these are E-books), then add his/her email address to each page of an existing pdf file (E-book). And save the pdf. 4. Email the customer with a download link for the newly created pdf.  I am not an expert in php, but I know how to google. Step 3, I managed to program using the Setas package. Step 4 ... I still need to think about how to do this. As to steps 1 and 2.....I spent most of this day on your manual and Forums. I came up with the php code below. It seems to work ok.  My question is: Is this a valid way to obtain the invoice number and email address of the customer, and the products that were ordered? I am slightly confused why $cart = $cartClass-&gt;getFullCart(); is linked to the current order. Why can't you take the ordered products from the $order object? Would that not be better?  Alain  And this is the xml file")*

Hi,

You should use the loadFullOrder method instead of the get method on class.order.
That way, you'll get all the data of the order including the user data in $order-&gt;customer and the products in $order-&gt;products

Loading the cart data there is risky as the current cart might not correspond to the current order. For example, if the "clean cart when order is" setting of the HikaShop configuration is set to "created" instead of "confirmed", the cart will be deleted before reaching your code and it won't work.

The page [ www.hikashop.com/support/documentation/6...umentation.html#code](https://www.hikashop.com/support/documentation/62-hikashop-developer-documentation.html#code) actually has some sample codes including some code to load the data of an order and loop through its products.

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

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

Less More

- Posts: 28
- Thank you received: 1
-
-

3 years 11 months ago -  3 years 11 months ago [\#347443](#347443) by [highstat@highstat.com](/forum/user/70596-highstat-highstat-com "View highstat@highstat.com's Profile")  Replied by *[highstat@highstat.com](/forum/user/70596-highstat-highstat-com "View highstat@highstat.com's Profile")* on topic *[plugin](/forum/31-development/905522-plugin#347443 "-- Joomla version -- : 4.latest -- PHP version -- : 8.1  Hello,  I am writing a plugin that does the following upon successful payment:  1. Get the invoice number and email address of the customer. 2. Inspect the products that were ordered. 3. If products A, B and C were ordered (these are E-books), then add his/her email address to each page of an existing pdf file (E-book). And save the pdf. 4. Email the customer with a download link for the newly created pdf.  I am not an expert in php, but I know how to google. Step 3, I managed to program using the Setas package. Step 4 ... I still need to think about how to do this. As to steps 1 and 2.....I spent most of this day on your manual and Forums. I came up with the php code below. It seems to work ok.  My question is: Is this a valid way to obtain the invoice number and email address of the customer, and the products that were ordered? I am slightly confused why $cart = $cartClass-&gt;getFullCart(); is linked to the current order. Why can't you take the ordered products from the $order object? Would that not be better?  Alain  And this is the xml file")*

Hello....thanks for your feedback. Greatly appreciated. I wish I had changed from Virtuemart to Hikashop much earlier!

Following your suggestions, I ended up with the code below.

1. That's better now?
2. I assume that the order_id in &amp;$order is the same order id as from loadFullOrder?
3. And can I just double-check that onAfterOrderUpdate is only being called after payment? I copied the if($FullOrder-&gt;order_status == $confirmed){ from somewhere....but I am just guessing that it may be needed in case a payment is not successful?

Alain
Code:

&lt;?php class plgHikashopSocialdrm extends JPlugin { function plgHikashopSocialdrm(&amp;$subject, $config){ parent::__construct($subject, $config); } // Execute code upon order confirmation function onAfterOrderUpdate(&amp;$order,&amp;$send_email){ if(!@include_once(rtrim(JPATH_ADMINISTRATOR,DS).DS.'components'.DS.'com_hikashop'.DS.'helpers'.DS.'helper.php')){ return false; } //Step 1: Get order ID. $order_id = $order-&gt;order_id; //Step 2: Load the whole information of an order via loadFullOrder $orderClass = hikashop_get('class.order'); $FullOrder = $orderClass-&gt;loadFullOrder($order_id, true, false); //Step 3: Get invoice number, user ID and email address //3A: Invoice number $InvNum = $FullOrder-&gt;order_invoice_number; //3B: User ID $UserID = $FullOrder-&gt;order_user_id; $Output ="User ID: " . $UserID; //3C: User email $userClass = hikashop_get('class.user'); $user = $userClass-&gt;get($FullOrder-&gt;order_user_id); $UserEmail = $user-&gt;user_email; //Step 4: Order confirmed? $app = JFactory::getApplication(); $config =&amp; hikashop_config(); $confirmed = $config-&gt;get('order_confirmed_status'); //If order is confirmed, show the products. if($FullOrder-&gt;order_status == $confirmed){ foreach($FullOrder-&gt;products as $product) { hikashop_writeToLog($product-&gt;order_product_name); hikashop_writeToLog($product-&gt;order_product_id); $ProductID = $product-&gt;order_product_id; // Now do things with $ProductID } } } }

Last edit: 3 years 11 months ago by [Jerome](/forum/user/80-jerome "View Jerome's Profile"). Reason: [code] tag is really nice

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMxLWRldmVsb3BtZW50LzkwNTUyMi1wbHVnaW4/dG1wbD1tYXJrZG93bg==) 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: 86541
- Thank you received: 14304
-
-

3 years 11 months ago [\#347444](#347444) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[plugin](/forum/31-development/905522-plugin#347444 "-- Joomla version -- : 4.latest -- PHP version -- : 8.1  Hello,  I am writing a plugin that does the following upon successful payment:  1. Get the invoice number and email address of the customer. 2. Inspect the products that were ordered. 3. If products A, B and C were ordered (these are E-books), then add his/her email address to each page of an existing pdf file (E-book). And save the pdf. 4. Email the customer with a download link for the newly created pdf.  I am not an expert in php, but I know how to google. Step 3, I managed to program using the Setas package. Step 4 ... I still need to think about how to do this. As to steps 1 and 2.....I spent most of this day on your manual and Forums. I came up with the php code below. It seems to work ok.  My question is: Is this a valid way to obtain the invoice number and email address of the customer, and the products that were ordered? I am slightly confused why $cart = $cartClass-&gt;getFullCart(); is linked to the current order. Why can't you take the ordered products from the $order object? Would that not be better?  Alain  And this is the xml file")*

Hi,

1. That's better.

2. Yes.

3. You're raising a good point here. onAfterOrderUpdate is called each time an order is changed. So no only when an order's status changes to confirmed.
So you need to improve your check to something like that: Code:

if(!empty($order-&gt;order_status) &amp;&amp; $order-&gt;order_status == $confirmed &amp;&amp; $order-&gt;old-&gt;order_status != $confirmed){ ... }

That way, you'll be sure the code inside will only run when the order's status is being changed, and only when it's changed from something which isn't confirmed to confirmed.
Also, you might want to add a check like this, especially if you plan on releasing this plugin to others or if you plan on using HikaMarket in the future: Code:

if($order-&gt;old-&gt;order_type!='sale') return;

HikaMarket will create sub sales (one sub order for each vendor of an order) with a different order_type than "sale". And you likely want to ignore these sub sales with that extra check.

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

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

Less More

- Posts: 28
- Thank you received: 1
-
-

3 years 11 months ago [\#347462](#347462) by [highstat@highstat.com](/forum/user/70596-highstat-highstat-com "View highstat@highstat.com's Profile")  Replied by *[highstat@highstat.com](/forum/user/70596-highstat-highstat-com "View highstat@highstat.com's Profile")* on topic *[plugin](/forum/31-development/905522-plugin#347462 "-- Joomla version -- : 4.latest -- PHP version -- : 8.1  Hello,  I am writing a plugin that does the following upon successful payment:  1. Get the invoice number and email address of the customer. 2. Inspect the products that were ordered. 3. If products A, B and C were ordered (these are E-books), then add his/her email address to each page of an existing pdf file (E-book). And save the pdf. 4. Email the customer with a download link for the newly created pdf.  I am not an expert in php, but I know how to google. Step 3, I managed to program using the Setas package. Step 4 ... I still need to think about how to do this. As to steps 1 and 2.....I spent most of this day on your manual and Forums. I came up with the php code below. It seems to work ok.  My question is: Is this a valid way to obtain the invoice number and email address of the customer, and the products that were ordered? I am slightly confused why $cart = $cartClass-&gt;getFullCart(); is linked to the current order. Why can't you take the ordered products from the $order object? Would that not be better?  Alain  And this is the xml file")*

Thank you very much. That seems to all work fine!

Alain

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMxLWRldmVsb3BtZW50LzkwNTUyMi1wbHVnaW4/dG1wbD1tYXJrZG93bg==) 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.069 seconds

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