Both of your replies were really helpful.
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:
function generateXML() {
if(!hikashop_level(1))
return '';
$app = JFactory::getApplication();
$db = JFactory::getDBO();
$pluginsClass = hikashop_get('class.plugins');
$plugin = $pluginsClass->getByName('hikashop','google_products');
$query = 'SELECT * FROM '.hikashop_table('order').' WHERE order_status=\'confirmed\'';
$db->setQuery($query);
$orders = $db->loadObjectList();
if(empty($orders)){
return true;
}
$ids = array();
foreach($orders as $key => $row){
$ids[] = (int)$row->order_id;
$products[$key]->alias = JFilterOutput::stringURLSafe($row->order_number);
}
$conf = JFactory::getConfig();
if(!HIKASHOP_J30) {
$siteName = $conf->getValue('config.sitename');
$siteDesc = $conf->getValue('config.MetaDesc');
} else {
$siteName = $conf->get('sitename');
$siteDesc = $conf->get('MetaDesc');
}
$siteAddress = JURI::base();
$siteAddress = str_replace('administrator/','',$siteAddress);
$xml = '<?xml version="1.0" encoding="UTF-8" ?>'."\n";
$productClass = hikashop_get('class.product');
$volumeHelper = hikashop_get('helper.volume');
$weightHelper = hikashop_get('helper.weight');
foreach($orders as $order) {
$orderClass = hikashop_get('class.order');
$order = $orderClass->loadFullOrder($order->order_id, true, false);
$billing_address = $order->billing_address;
$shipping_address = $order->shipping_address;
$xml .= "<Header>";
$xml .= "<Megrendeles_adatai>";
$xml .= "<Rendeles_szama>".$order->order_number."</Rendeles_szama>";
$xml .= "<Datum>".hikashop_getDate($order->order_created, 'Y.m.d H:i:s')."</Datum>";
$xml .= "<Fizetesi_mod>".$order->order_payment_method."</Fizetesi_mod>";
$xml .= "<Szallitasi_mod>".$order->order_shipping_method."</Szallitasi_mod>";
$xml .= "<Megjegyzes_rendeleshez>".$order->comment."</Megjegyzes_rendeleshez>";
$xml .= "<Header_Vevo>";
$xml .= "<Vevo_neve>".$billing_address->address_company."</Vevo_neve>";
$xml .= "<Vevo_irsz>".$billing_address->address_post_code."</Vevo_irsz>";
$xml .= "<Vevo_varos>".$billing_address->address_city."</Vevo_varos>";
$xml .= "<Vevo_cim>".$billing_address->address_street." ".$billing_address->address_street2."</Vevo_cim>";
$xml .= "<Szallitas_nev>".$shipping_address->address_lastname." ".$shipping_address->address_firstname."</Szallitas_nev>";
$xml .= "<Szallitas_irsz>".$shipping_address->address_post_code."</Szallitas_irsz>";
$xml .= "<Szallitas_varos>".$shipping_address->address_city."</Szallitas_varos>";
$xml .= "<Szallitas_cim>".$shipping_address->address_street." ".$shipping_address->address_street2."</Szallitas_cim>";
$xml .= "<Telefon>".$shipping_address->address_telephone."</Telefon>";
$xml .= "<Email>".$order->customer->email."</Email>";
$xml.= "<Adoszam>".$order->billing_address->address_vat."</Adoszam>";
$xml .= "</Header_Vevo>";
$xml .= "<Items>";
foreach($order->products as $product) {
$productData = $productClass->get($product->product_id);
$xml .= "<Megrendelt_Tetelek>";
$xml .= "<Termek_neve>".$product->order_product_name."</Termek_neve>";
$xml .= "<Termekkod>".$product->order_product_code."</Termekkod>";
$xml .= "<Cikkszam></Cikkszam>";
$xml .= "<Mennyiseg>".$product->order_product_quantity."</Mennyiseg>";
$xml .= "<Mee>".$productData->mennyisegiegyseg."</Mee>";
$xml .= "<Netto_egysegar>".$product->order_product_price."</Netto_egysegar>";
$xml .= "<AFA>27%</AFA>";
$xml .= "<Kedvezmeny_szazaleka>0</Kedvezmeny_szazaleka>";
$xml .= "</Megrendelt_Tetelek>";
}
$xml .= "</Items>";
$xml .= "</Megrendeles_adatai>";
$xml .= "</Header>";
}
return $xml;
}
}
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.