Hello,
I need to create custom XML documents (various), following specific guidelines 3rd party aggregator sites.
What is the file I can use as a starting point to create variations from?
Any other pointers? Thanks
Your guidelines from your aggregator site would be a great starting point.
Jörgen @ Kreativ Fotografi
I do this either with an admin module, a plugin or a root script with Joomla imported and fired by cron or url.
Basically u need to query the products ( try to use native VM models )..
loop the results and print an xml which you can then save "somewhere"
Thanks.
I was hoping there would be a way to make a "copy" of the current XML product feed (php), and then create custom variations using different URL parameters.
It's not that simple, is it?
Depends on how complex your XML scheme is. There are branches where even parsing such a result is a pain in the *....
Can somebody point me to the code that creates the category product XML feed? So I can start from somewhere....
You can use our component - EasyFeeder XML, which You can create any xml output (products, orders, any db table)
https://www.minijoomla.org/extensions/xml-easy-feeder
https://gitlab.easy.minion.cz/documentation/com_easyfeeder_docs
Rudolf
I just wrote my own category and product sitemap creator this week. This code does not produce xml format, only text i can copy and put in xml file.
for categories i use this code on the front end.
$categories='';
$html='';
function get_table($table){
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('*');
$query->from($db->quoteName($table));
$query->where('published=1');
$db->setQuery($query);
$rows = $db->loadAssocList();
return $rows;
}
echo '<div style="padding:50px;">';
echo htmlentities('<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">');
echo '<br/>';
$categories=get_table('#__virtuemart_categories');
foreach ($categories as $cat){
//print_r($cat);
$caturl = JRoute::_ ( 'index.php?option=com_virtuemart&view=category&virtuemart_category_id=' . $cat['virtuemart_category_id'] , FALSE);
$caturl=str_replace( '/new', '', $caturl );
$html.=htmlentities('<url><loc>').'https://www.PUT-YOUR-DOT-COM-HERE';
$html.=$caturl;
$html.=htmlentities('</loc></url>');
$html.='<br/>';
}
echo $html;
echo '<br/>';
echo htmlentities('</urlset>');
echo '</div>';
FOR PRODUCTS I USE THE CODE BELOW, my code also checks for canonical url
$products='';
$html='';
function get_table($table){
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('*');
$query->from($db->quoteName($table));
$db->setQuery($query);
$rows = $db->loadAssocList();
return $rows;
}
function get_product($id){
if (!class_exists( 'VmConfig' )) require(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_virtuemart'.DS.'helpers'.DS.'config.php');
VmConfig::loadConfig();
if (!class_exists( 'VmModel' )) require(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_virtuemart'.DS.'helpers'.DS.'vmmodel.php');
$product_model = VmModel::getModel('product');
$product = $product_model->getProduct($id,TRUE,TRUE,TRUE,1);
if ($product->product_canon_category_id >0){
$product->virtuemart_category_id=$product->product_canon_category_id;
}
$link= JRoute::_('index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id='.$id.'&virtuemart_category_id='.$product->virtuemart_category_id.'');
$html='';
//$html.=$product->virtuemart_product_id;
$html.=htmlentities('<url><loc>').'https://www.PUT-YOUR-DONT-COM-HERE'.$link.htmlentities('</loc></url>');
return $html.'<br/>';
}
echo '<div style="padding:50px;">';
echo htmlentities('<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">');
echo '<br/>';
$products=get_table('#__virtuemart_products');
foreach ($products as $product){
$html.=get_product($product['virtuemart_product_id']);
}
echo $html;
echo '<br/>';
echo htmlentities('</urlset>');
echo '</div>';
Beautiful, thanks.
How would I put that code in a URL endpoint so I can create the result?
build it out as a formatted xml then use standard php folder / file functions to save it in a folder as a xxxx.xml
in the loop do like
$output = "your opening tags";
{
$output .= '<product ITEM="'.$product->virtuemart_product_id.'">
<uid><![CDATA['.$product->virtuemart_product_id.']]></uid>
<sku><![CDATA['.$product->product_sku.']]></sku>";
}
etc
$output .= "your closing tags";
then file_put_contents('xml/products.xml', $output);