- Posts: 171
- Thank you received: 9
Generating Custom XML with Mass Action button
- pepecortez
-
Topic Author
- Offline
-- Joomla version -- : 4.1.5
-- PHP version -- : 7.4
Hi there!
I wanna ask for some help how can I create an XML with the content in the orders.
We have an ERP system, and we got a sample XML what we can use.
Sometime we want to import the orders to the ERP with that XML.
I've successfully displayed the Mass action button, I've set it to "Run PHP code", and I've added some sample lines to check wether it is working.
But after pressing the button I got a message like:
An error has occurred.
500 Layout output not found.
Is there any way to do that with Mass Action, any sample code would be great help solving that.
Sample is like:
Thanks in advance!
PePe
Please Log in or Create an account to join the conversation.
So you can output XML code but you need to do that in PHP.
For example:
So it would be best to output it as a download file:
Please Log in or Create an account to join the conversation.
- pepecortez
-
Topic Author
- Offline
- Posts: 171
- Thank you received: 9
For anyone else how needs:
Please Log in or Create an account to join the conversation.
- pepecortez
-
Topic Author
- Offline
- Posts: 171
- Thank you received: 9
To reach that I modified the Mass action to run every minute,
filter products by order status set to confirmed,
and run php code below.
1.) But I always get just the first order in the XML. Could I ask for a little help how to modify code to read all the orders to the XML?
2.) Also a problem that if I run it on Mass Actions form, it generates the XML file to /administrator folder, with cron link(/index.php?option=com_hikashop&ctrl=cron), it does not. Maybe folder permissions cause that? If yes, how should I set it to another folder?
Please Log in or Create an account to join the conversation.
1. The action will run once for each order filtered by the filters of your mass action.
So here, there is not much point in using a mass action for what you want to do.
I would rather recommend you develop a plugin ( www.hikashop.com/support/documentation/6...r-documentation.html ) implementing the onHikashopCronTrigger (
www.hikashop.com/support/documentation/6...nHikashopCronTrigger ) event. In it, you would first run a MySQL query to load the confirmed orders, and then you would generate the XML file.
2. That's because of your line: $dom->save('orders.xml');
You only provide the filename. But in the backend, the current folder in /administrator/ while on the frontend (where the cron runs) the current folder is /.
The solution is to provide the full folder like this: $dom->save(HIKASHOP_ROOT.'orders.xml');
That way it will always save it on the root folder of the website.
Please Log in or Create an account to join the conversation.
- pepecortez
-
Topic Author
- Offline
- Posts: 171
- Thank you received: 9
1.) I've used your google products plugin - of course I've elminated a few params from it - as a prefect example I can rewrite to fit my needs. Now cron does the job - generates XML with all the needed data, the ERP is checking and reads in automatically. Thanks a lot.
Here's the main part, the generateXML function, and I also attached a .htaccess file to only be readable by the ERP's IP:
2.) $dom->save(HIKASHOP_ROOT.'orders.xml'); -> was also useful, works as u described.
nicolas wrote: Hi,
1. The action will run once for each order filtered by the filters of your mass action.
So here, there is not much point in using a mass action for what you want to do.
I would rather recommend you develop a plugin ( www.hikashop.com/support/documentation/6...r-documentation.html ) implementing the onHikashopCronTrigger (
www.hikashop.com/support/documentation/6...nHikashopCronTrigger ) event. In it, you would first run a MySQL query to load the confirmed orders, and then you would generate the XML file.
2. That's because of your line: $dom->save('orders.xml');
You only provide the filename. But in the backend, the current folder in /administrator/ while on the frontend (where the cron runs) the current folder is /.
The solution is to provide the full folder like this: $dom->save(HIKASHOP_ROOT.'orders.xml');
That way it will always save it on the root folder of the website.
Please Log in or Create an account to join the conversation.