News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

Custom XML for Products

Started by EvanGR, April 16, 2019, 15:34:52 PM

Previous topic - Next topic

EvanGR

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

Jörgen

Your guidelines from your aggregator site would be a great starting point.
Jörgen @ Kreativ Fotografi
Joomla 3.9.18
Virtuemart 3.4.x
Olympiantheme Hera (customized)
This reflects current status when viewing old post.

GJC Web Design

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"
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

EvanGR

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?

diri

Depends on how complex your XML scheme is. There are branches where even parsing such a result is a pain in the *....

EvanGR

Can somebody point me to the code that creates the category product XML feed? So I can start from somewhere....

pinochico

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


www.minijoomla.org  - new portal for Joomla!, Virtuemart and other extensions
XML Easy Feeder - feeds for FB, GMC,.. from products, categories, orders, users, articles, acymailing subscribers and database table
Virtuemart Email Manager - customs email templates
Import products for Virtuemart - from CSV and XML
Rich Snippets - Google Structured Data
VirtueMart Products Extended - Slider with products, show Others bought, Products by CF ID and others filtering products

PRO

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>';

EvanGR

Beautiful, thanks.

How would I put that code in a URL endpoint so I can create the result?

GJC Web Design

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);

GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation