Products To Custom Xml

Hello



i am trying to export products of a cscart multivendor from mysql to xml. I created an php file that creates an xml file. The code at the moment is:



//Create Database connection
$db = mysql_connect('','','');
if (!$db) {
die('Could not connect to db: ' . mysql_error());
}

//Select the Database
mysql_select_db("",$db);

$result = mysql_query("select * from cscart_products, cscart_products_categories, cscart_category_descriptions, cscart_product_descriptions, cscart_product_prices, cscart_product_options where cscart_products.product_id = cscart_products_categories.product_id and cscart_products_categories.category_id = cscart_category_descriptions.category_id and cscart_products.product_id = cscart_product_descriptions.product_id and cscart_products.product_id = cscart_product_prices.product_id", $db);


//Create SimpleXMLElement object
$xml = new SimpleXMLElement('');

//Add each column value a node of the XML object
while($row = mysql_fetch_assoc($result)) {
$mydata = $xml->addChild('mydata');
$mydata->addChild('sku',$row['product_code']);
$mydata->addChild('name',$row['product']);
$mydata->addChild('oldprice',$row['list_price']);
$mydata->addChild('price',$row['price']);
$mydata->addChild('description',$row['meta_description']);
$mydata->addChild('Category',$row['category']);
}

mysql_close($db);
//Create the XML file
$fp = fopen("test.xml","wb");

//Write the XML nodes
fwrite($fp,$xml->asXML());

//Close the database connection
fclose($fp);

?>


[b]My first problem is that i cant find in sql some more fields that i need like product url and main image.

The second problem is that i need to have all options including to xml.[/b]

For be more specific i need an xml exactly like this one:

[url="https://www.fashionbay.gr/XmlSamples/b2b4all.xml"]https://www.fashionb...les/b2b4all.xml[/url]

Any ideas?

thanks in advance

Please create the app/addons/my_changes/controllers/frontend/products.post.php file with the following content:


```php

use Tygh\Registry;
if (!defined('BOOTSTRAP')) { die('Access denied'); }

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
return;
}

if ($mode == 'xml_export') {
$params = $_REQUEST;
$params['extend'] = array('description');
list($products, $search) = fn_get_products($params, Registry::get('settings.Appearance.products_per_page'));
fn_gather_additional_products_data($products, array('get_icon' => false, 'get_detailed' => false, 'get_additional' => true, 'get_options'=> true));

$xml = new SimpleXMLElement('');
foreach ($products as $product) {
$mydata = $xml->addChild('mydata');
$mydata->addChild('sku',$product['product_code']);
$mydata->addChild('name',$product['product']);
$mydata->addChild('oldprice',$product['list_price']);
$mydata->addChild('price',$product['price']);
$mydata->addChild('description',$product['meta_description']);
$mydata->addChild('Category',fn_get_category_name($product['main_category']));
}
$fp = fopen("test.xml","wb");
//Write the XML nodes
fwrite($fp,$xml->asXML());
//Close the database connection
fclose($fp);

fn_print_die('Done');
}
```

and run the following URL:

```php http://domain.com/index.php?dispatch=products.xml_export ```

[quote name='eComLabs' timestamp='1413968469' post='194805']

Please create the app/addons/my_changes/controllers/frontend/products.post.php file with the following content:


```php

use Tygh\Registry;
if (!defined('BOOTSTRAP')) { die('Access denied'); }

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
return;
}

if ($mode == 'xml_export') {
$params = $_REQUEST;
$params['extend'] = array('description');
list($products, $search) = fn_get_products($params, Registry::get('settings.Appearance.products_per_page'));
fn_gather_additional_products_data($products, array('get_icon' => false, 'get_detailed' => false, 'get_additional' => true, 'get_options'=> true));

$xml = new SimpleXMLElement('');
foreach ($products as $product) {
$mydata = $xml->addChild('mydata');
$mydata->addChild('sku',$product['product_code']);
$mydata->addChild('name',$product['product']);
$mydata->addChild('oldprice',$product['list_price']);
$mydata->addChild('price',$product['price']);
$mydata->addChild('description',$product['meta_description']);
$mydata->addChild('Category',fn_get_category_name($product['main_category']));
}
$fp = fopen("test.xml","wb");
//Write the XML nodes
fwrite($fp,$xml->asXML());
//Close the database connection
fclose($fp);

fn_print_die('Done');
}
```

and run the following URL:

```php http://domain.com/index.php?dispatch=products.xml_export ```
[/quote]

Thanks so much Ecom labs for this code I was looking for this.

Just one more request I need the following fields added in this , how can we do so?

```php
1 URL
2 Prod_Image
3 Category_Name
4 SubCategory_Name
5 SubSubCategory_Name
```

Code modifications are required. Feel free to contact us

How do you generate an xml file so that some one can access it from a URL like the sitemap.xml can be viewed in browser itself when accessed with a similar link ?

You need to add the following code to the .htaccess file to get this URL working: RewriteRule ^myname\.xml$ ./index.php?dispatch=products.xml_export [L].



Add this line after the # RewriteBase / line.

Thanks Ecom labs it works.

You are welcome!