VirtueMart Forum

VirtueMart 2 + 3 + 4 => General Questions => Topic started by: pm4698 on June 20, 2016, 09:21:52 AM

Title: Create custom xml feed
Post by: pm4698 on June 20, 2016, 09:21:52 AM
Hello there,

I need to create a custom xml feed for Virtuemart 2.6.10 and joomla 2.5.x

I want to do this via php like this:
<?php

$xml 
= new SimpleXMLElement('<xml/>');

foreach (
$this->products as product) {
    
$product $xml->addChild('product');
    
$product->addChild('category'"$this->product->category");
    
$product->addChild('title'"$this->product->title");
..
..
}

Header('Content-type: text/xml');
print(
$xml->asXML());
?>


In which path do you think that i should put this php file? What code do i need in order for me to have $this from virtuemart in my file? Do you propose any other solution for this task?

Thank you in advance
Title: Re: Create custom xml feed
Post by: Studio 42 on June 20, 2016, 10:13:53 AM
Hi,
What are the origin of this xml feed? Category, featured, latest ... ?
Title: Re: Create custom xml feed
Post by: pm4698 on June 20, 2016, 10:25:54 AM
For each product i will have:

<id> id of product
<name> name of product
<mpn> sku of product
<price_with_vat> as salesPrice
<full_price> as initial price (product_price)
<discount> discount percentage (without the % character)
<image> as product image
<link> link for the product
<category> category name of product
<manufacturer> manufacturer of product
<availability> availability of product
<instock> if its in stock or not
<weight> weight of product
Title: Re: Create custom xml feed
Post by: Studio 42 on June 20, 2016, 11:31:19 AM
OK, but how you get $this->products ???

And first declare the header

$document = JFactory::getDocument();
$document->setMimeEncoding( 'text/xml' );
// Output XML header.
echo '<?xml version="1.0" encoding="UTF-8" ?>' . "\n";
$xml = new SimpleXMLElement('<xml/>');

and your loop is bad, it should be:
foreach ($this->products as $product) {
    $item = $xml->addChild('product');
    $item->addChild('category', $product->category);
    $item->addChild('title', $product->title);
..
..
}
echo $xml->asXML();
jexit();


To test, but should be OK.