News:

Support the VirtueMart project and become a member

Main Menu

Create custom xml feed

Started by pm4698, June 20, 2016, 09:21:52 AM

Previous topic - Next topic

pm4698

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

Studio 42

Hi,
What are the origin of this xml feed? Category, featured, latest ... ?

pm4698

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

Studio 42

#3
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.