VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: EvanGR on April 16, 2019, 15:34:52 PM

Title: Custom XML for Products
Post by: EvanGR on April 16, 2019, 15:34:52 PM
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
Title: Re: Custom XML for Products
Post by: Jörgen on April 16, 2019, 15:52:09 PM
Your guidelines from your aggregator site would be a great starting point.
Jörgen @ Kreativ Fotografi
Title: Re: Custom XML for Products
Post by: GJC Web Design on April 16, 2019, 18:08:46 PM
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"
Title: Re: Custom XML for Products
Post by: EvanGR on April 17, 2019, 08:40:48 AM
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?
Title: Re: Custom XML for Products
Post by: diri on April 17, 2019, 09:24:56 AM
Depends on how complex your XML scheme is. There are branches where even parsing such a result is a pain in the *....
Title: Re: Custom XML for Products
Post by: EvanGR on April 18, 2019, 08:52:54 AM
Can somebody point me to the code that creates the category product XML feed? So I can start from somewhere....
Title: Re: Custom XML for Products
Post by: pinochico on May 04, 2019, 14:16:24 PM
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


Title: Re: Custom XML for Products
Post by: PRO on May 08, 2019, 22:33:17 PM
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>';
Title: Re: Custom XML for Products
Post by: EvanGR on May 09, 2019, 10:56:41 AM
Beautiful, thanks.

How would I put that code in a URL endpoint so I can create the result?
Title: Re: Custom XML for Products
Post by: GJC Web Design on May 09, 2019, 11:48:01 AM
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);