Zen Cart Logo
Forums / General Questions / Real time XML product feed integration?

Real time XML product feed integration?

Views: 13,451

Results 1 to 13 of 13
5 Nov 2006, 5:20 PM
#1
ahreno avatar

ahreno

New Zenner

Join Date:
Sep 2005
Posts:
15
Plugin Contributions:
0

Real time XML product feed integration?

I havea supplier that offers a realtime xml feed of inventory/prices etc... is it possible to integrate this into Zen cart and keep it real time?

28 Nov 2006, 2:27 PM
#2
satpromo avatar

satpromo

New Zenner

Join Date:
Nov 2005
Posts:
5
Plugin Contributions:
0

Re: Real time XML product feed integration?

Yes it is possible

<?php require('includes/application_top.php'); Header( 'Content-Type: text/xml' ); echo '<?xml version="1.0" encoding="ISO-8859-1"?>'.chr(10);

// Déclaration du catalogue. Il est recommandé d'indiquer correctement la langue et le fuseau horaire GMT.
echo '<catalogue lang="FR" date="'. date('Y-m-d H:i'). '" GMT="+1" version="2.0">'.chr(10);

$language_code = 'es';
$currency_code = 'EUR';

//on reccupere l'id languade en fonction du code language, donc de la langue du site
$id_language_qry = 'SELECT languages_id FROM languages WHERE code = "'.$language_code.'"';
$id_language_res = $db->Execute($id_language_qry);
$id_language = $id_language_res->fields['languages_id'];

//on reccupere le taux pour convertir dans la bonne devise
$currency_rate_qry = 'SELECT value FROM currencies WHERE code = ''.$currency_code.''';
$currency_rate_res = $db->Execute($currency_rate_qry);
$currency_rate = $currency_rate_res->fields['value'];

//on reccupere les infos des produits
/*
$qry = 'SELECT T_pdt.products_id as refInterne,T_pdt.products_model as modele ,T_pdt.products_model AS name, T_pdt_desc.products_description AS description,T_pdt.products_image AS img, ';
$qry .= 'T_pdt.products_price AS price , specials.specials_new_products_price as discount_price , manufacturers.manufacturers_name as marque, ';
$qry .= 'T_cat.categories_name AS cat , products_tax_class_id ';
$qry .= 'FROM manufacturers, products_description AS T_pdt_desc, categories_description AS T_cat ,products AS T_pdt LEFT JOIN specials ON specials.products_id = T_pdt.products_id ';
$qry .= 'WHERE T_pdt.master_categories_id = T_cat.categories_id ';
$qry .= 'AND T_cat.language_id =2 AND T_pdt.products_status = 1 AND T_pdt.products_id = T_pdt_desc.products_id AND T_pdt_desc.language_id =2 AND manufacturers.manufacturers_id = T_pdt.manufacturers_id';

$qry = '
SELECT T_pdt.products_id as refInterne,T_pdt.products_model as modele ,manufacturers.manufacturers_name as marque, T_pdt_desc.products_name AS name,
T_pdt_desc.products_description AS description,T_pdt.products_image AS img, T_pdt.products_price AS price , specials.specials_new_products_price as discount_price , T_cat.categories_name AS cat , products_tax_class_id
FROM products_description AS T_pdt_desc, categories_description AS T_cat ,(products AS T_pdt
LEFT JOIN specials ON (specials.products_id = T_pdt.products_id) )
LEFT JOIN manufacturers ON (manufacturers.manufacturers_id = T_pdt.manufacturers_id)
WHERE T_pdt.master_categories_id = T_cat.categories_id AND T_cat.language_id =2
AND T_pdt.products_status = 1 AND T_pdt.products_id = T_pdt_desc.products_id AND T_pdt_desc.language_id =2 ';
*/

$qry = '
SELECT T_pdt.products_id as refInterne,T_pdt.products_model as modele ,manufacturers.manufacturers_name as marque,
T_pdt_desc.products_name AS name , T_pdt_desc.products_description AS description,T_pdt.products_image AS img, T_pdt.products_price AS price , specials.specials_new_products_price as discount_price ,

T_cat.categories_name AS cat , products_tax_class_id

FROM products_to_categories , products_description AS T_pdt_desc, categories_description AS T_cat ,(products AS T_pdt
LEFT JOIN specials ON (specials.products_id = T_pdt.products_id) )
LEFT JOIN manufacturers ON (manufacturers.manufacturers_id = T_pdt.manufacturers_id)
WHERE products_to_categories.products_id = T_pdt.products_id AND products_to_categories.categories_id = T_cat.categories_id

AND T_cat.language_id ='.$id_language.'
AND T_pdt.products_status = 1 AND T_pdt.products_id = T_pdt_desc.products_id
AND T_pdt_desc.language_id = '.$id_language.' group by T_pdt.products_id ORDER BY T_pdt.products_id;
';
echo '<!--'.$qry.chr(10).'-->';

$product_list = $db->Execute($qry);
$i = 1;
while(!$product_list->EOF)
{
$buffer = '<product num="'.$i++.'">';
$buffer .= '<offer_id>'.$product_list->fields['refInterne'].'</offer_id>';
$buffer .= '<model>'.$product_list->fields['modele'].'</model>';
$buffer .= '<name><![CDATA['.$product_list->fields['name'].']]></name>';
$buffer .= '<description><![CDATA['.$product_list->fields['description'].']]></description>';
$buffer .= '<brand><![CDATA['.$product_list->fields['marque'].']]></brand>';
$buffer .= '<category><![CDATA['.$product_list->fields['cat'].']]></category>';

//prix
$_prix = number_format(zen_round($product_list->fields['price'] * $currency_rate, 2), 2 , '.' , '');

//prix_barre
if ($new_price = zen_get_products_special_price($product_list->fields['refInterne'])) {
$_prix_barre = $_prix;
$_prix = number_format(zen_round($new_price * $currency_rate, 2), 2 , '.' , '');
}

$buffer .= '<discount_price>'.$_prix.'</discount_price>';
$buffer .= '<regular_price>'.$_prix_barre.'</regular_price>';
$buffer .= '<fp></fp>';
$buffer .= '<img><![CDATA['.HTTP_SERVER.DIR_WS_CATALOG.DIR_WS_IMAGES.$product_list->fields['img'].']]></img>';
$buffer .= '<url><![CDATA['.HTTP_SERVER.DIR_WS_CATALOG.'index.php?main_page=product_info&products_id='.$product_list->fields['refInterne'].'&language='.$language_code.']]></url>';
$buffer .= '</product>';
echo $buffer.chr(10);
flush();
$product_list->MoveNext();
}
echo '</catalogue>';
flush();

require(DIR_WS_INCLUDES . 'application_bottom.php');

?>
Test this

Best regard

https://www.satpromo.com

1 Dec 2006, 10:48 AM
#3
stuartforrest avatar

stuartforrest

New Zenner

Join Date:
Nov 2006
Location:
Edinburgh, Scotland
Posts:
11
Plugin Contributions:
0

Re: Real time XML product feed integration?

satpromo:

Yes it is possible

<?php require('includes/application_top.php'); Header( 'Content-Type: text/xml' ); echo '<?xml version="1.0" encoding="ISO-8859-1"?>'.chr(10);

// Déclaration du catalogue. Il est recommandé d'indiquer correctement la langue et le fuseau horaire GMT.
echo '<catalogue lang="FR" date="'. date('Y-m-d H:i'). '" GMT="+1" version="2.0">'.chr(10);

$language_code = 'es';
$currency_code = 'EUR';

//on reccupere l'id languade en fonction du code language, donc de la langue du site
$id_language_qry = 'SELECT languages_id FROM languages WHERE code = "'.$language_code.'"';
$id_language_res = $db->Execute($id_language_qry);
$id_language = $id_language_res->fields['languages_id'];

//on reccupere le taux pour convertir dans la bonne devise
$currency_rate_qry = 'SELECT value FROM currencies WHERE code = ''.$currency_code.''';
$currency_rate_res = $db->Execute($currency_rate_qry);
$currency_rate = $currency_rate_res->fields['value'];

//on reccupere les infos des produits
/*
$qry = 'SELECT T_pdt.products_id as refInterne,T_pdt.products_model as modele ,T_pdt.products_model AS name, T_pdt_desc.products_description AS description,T_pdt.products_image AS img, ';
$qry .= 'T_pdt.products_price AS price , specials.specials_new_products_price as discount_price , manufacturers.manufacturers_name as marque, ';
$qry .= 'T_cat.categories_name AS cat , products_tax_class_id ';
$qry .= 'FROM manufacturers, products_description AS T_pdt_desc, categories_description AS T_cat ,products AS T_pdt LEFT JOIN specials ON specials.products_id = T_pdt.products_id ';
$qry .= 'WHERE T_pdt.master_categories_id = T_cat.categories_id ';
$qry .= 'AND T_cat.language_id =2 AND T_pdt.products_status = 1 AND T_pdt.products_id = T_pdt_desc.products_id AND T_pdt_desc.language_id =2 AND manufacturers.manufacturers_id = T_pdt.manufacturers_id';

$qry = '
SELECT T_pdt.products_id as refInterne,T_pdt.products_model as modele ,manufacturers.manufacturers_name as marque, T_pdt_desc.products_name AS name,
T_pdt_desc.products_description AS description,T_pdt.products_image AS img, T_pdt.products_price AS price , specials.specials_new_products_price as discount_price , T_cat.categories_name AS cat , products_tax_class_id
FROM products_description AS T_pdt_desc, categories_description AS T_cat ,(products AS T_pdt
LEFT JOIN specials ON (specials.products_id = T_pdt.products_id) )
LEFT JOIN manufacturers ON (manufacturers.manufacturers_id = T_pdt.manufacturers_id)
WHERE T_pdt.master_categories_id = T_cat.categories_id AND T_cat.language_id =2
AND T_pdt.products_status = 1 AND T_pdt.products_id = T_pdt_desc.products_id AND T_pdt_desc.language_id =2 ';
*/

$qry = '
SELECT T_pdt.products_id as refInterne,T_pdt.products_model as modele ,manufacturers.manufacturers_name as marque,
T_pdt_desc.products_name AS name , T_pdt_desc.products_description AS description,T_pdt.products_image AS img, T_pdt.products_price AS price , specials.specials_new_products_price as discount_price ,

T_cat.categories_name AS cat , products_tax_class_id

FROM products_to_categories , products_description AS T_pdt_desc, categories_description AS T_cat ,(products AS T_pdt
LEFT JOIN specials ON (specials.products_id = T_pdt.products_id) )
LEFT JOIN manufacturers ON (manufacturers.manufacturers_id = T_pdt.manufacturers_id)
WHERE products_to_categories.products_id = T_pdt.products_id AND products_to_categories.categories_id = T_cat.categories_id

AND T_cat.language_id ='.$id_language.'
AND T_pdt.products_status = 1 AND T_pdt.products_id = T_pdt_desc.products_id
AND T_pdt_desc.language_id = '.$id_language.' group by T_pdt.products_id ORDER BY T_pdt.products_id;
';
echo '<!--'.$qry.chr(10).'-->';

$product_list = $db->Execute($qry);
$i = 1;
while(!$product_list->EOF)
{
$buffer = '<product num="'.$i++.'">';
$buffer .= '<offer_id>'.$product_list->fields['refInterne'].'</offer_id>';
$buffer .= '<model>'.$product_list->fields['modele'].'</model>';
$buffer .= '<name><![CDATA['.$product_list->fields['name'].']]></name>';
$buffer .= '<description><![CDATA['.$product_list->fields['description'].']]></description>';
$buffer .= '<brand><![CDATA['.$product_list->fields['marque'].']]></brand>';
$buffer .= '<category><![CDATA['.$product_list->fields['cat'].']]></category>';

//prix
$_prix = number_format(zen_round($product_list->fields['price'] * $currency_rate, 2), 2 , '.' , '');

//prix_barre
if ($new_price = zen_get_products_special_price($product_list->fields['refInterne'])) {
$_prix_barre = $_prix;
$_prix = number_format(zen_round($new_price * $currency_rate, 2), 2 , '.' , '');
}

$buffer .= '<discount_price>'.$_prix.'</discount_price>';
$buffer .= '<regular_price>'.$_prix_barre.'</regular_price>';
$buffer .= '<fp></fp>';
$buffer .= '<img><![CDATA['.HTTP_SERVER.DIR_WS_CATALOG.DIR_WS_IMAGES.$product_list->fields['img'].']]></img>';
$buffer .= '<url><![CDATA['.HTTP_SERVER.DIR_WS_CATALOG.'index.php?main_page=product_info&products_id='.$product_list->fields['refInterne'].'&language='.$language_code.']]></url>';
$buffer .= '</product>';
echo $buffer.chr(10);
flush();
$product_list->MoveNext();
}
echo '</catalogue>';
flush();

require(DIR_WS_INCLUDES . 'application_bottom.php');

?>
Test this

Best regard

www.satpromo.com

Hello there, Can I ask where this code is supposed to go please?

23 Dec 2006, 6:28 PM
#4
wtashby avatar

wtashby

Totally Zenned

Join Date:
Feb 2006
Posts:
594
Plugin Contributions:
0

Re: Real time XML product feed integration?

I too would like to try this code. Where does it go, and what xml structure does it work with? How is it implemented? Does it work with any xml file for product feed?

Thanks,

24 Jun 2007, 10:36 PM
#5
spbennett avatar

spbennett

Zen Follower

Join Date:
Feb 2007
Location:
Leicester UK
Posts:
230
Plugin Contributions:
0

Re: Real time XML product feed integration?

The code appears to be in spanish and gives a parse error whe you run it.

There is a module available for oscommerce and creloaded but it seems kind of expensive for something thats based on free code. In the next week, time permitting, I'll do some research and attempt to re-write the oscommerce version to work with Zencart.

25 Jun 2007, 10:16 AM
#6
stuartforrest avatar

stuartforrest

New Zenner

Join Date:
Nov 2006
Location:
Edinburgh, Scotland
Posts:
11
Plugin Contributions:
0

Re: Real time XML product feed integration?

You would be an absoloute legend if you could do that... I posted here months ago and been actively searching for a solution since! You would make alot of people very happy!

25 Jun 2007, 4:55 PM
#7
spbennett avatar

spbennett

Zen Follower

Join Date:
Feb 2007
Location:
Leicester UK
Posts:
230
Plugin Contributions:
0

Re: Real time XML product feed integration?

Seems it might be more difficult than I first thought.

Anyone care to take a look at the code and help out a little?

My XML knowledge is pretty good but my PHP knowledge is not up to much.

25 Jul 2007, 2:26 PM
#8
freezing_cold avatar

freezing_cold

New Zenner

Join Date:
Feb 2007
Location:
Glasgow, UK
Posts:
1
Plugin Contributions:
0

Re: Real time XML product feed integration?

The OP was looking for code to import not export a product feed and this isn't any help to them either :(

Placing this code in the root of your Zen Cart install will generate an XML export of the products.

Tested on v1.3.7.

<?php
require("includes/application_top.php");
?>
<?php
  // We'll be outputting XML
header('Content-type: application/xml');
?>
<?php

  /**
   * Get the default language for the site
   * @return array An array containing the lanugage id and two-letter code.
   */

function get_default_language() {
  global $db;

  $sql = "select languages_id, code from ".TABLE_LANGUAGES.", ".TABLE_CONFIGURATION." where configuration.configuration_value=languages.code AND configuration.configuration_key='DEFAULT_LANGUAGE'";

  $result = $db->Execute($sql);

  return array('code' => $result->fields['code'],
      'languages_id' => $result->fields['languages_id']);
}


/**
 * Fetch back a list of products with their details in the language specified by $language_id.
 * @param int $language_id Specify the language that product descriptions should be returned as.
 * @return queryFactory A list of products wrapped in a queryFactory. 
 */

function get_product_list($language_id) {

  global $db;

  $sql = "select p.products_id as id, p_d.products_name as name, p_d.products_description as description, p_d.products_url as url, p.products_image as image, p.products_quantity as stock, m.manufacturers_name as manufacturers_name, p.products_price as price from ".TABLE_PRODUCTS." as p inner join ".TABLE_PRODUCTS_DESCRIPTION." as p_d on p.products_id=p_d.products_id left outer join ".TABLE_MANUFACTURERS." as m on p.manufacturers_id=m.manufacturers_id where p_d.language_id=".$language_id;

  $result = $db->Execute($sql);

  return $result;
}


/**
 * Fetch back a list of products and their categories.
 * This a 1-to-many relationship
 * @return array An array keyed by the product and listing the categories it's in.
 */

function get_product_categories() {

  global $db;

  $sql = "select products_id as p_id, categories_id as cat_id from ".TABLE_PRODUCTS_TO_CATEGORIES." order by products_id";

  $result = $db->Execute($sql);

  //Loop and store result as a hash with the product_id the key

  $product_categories = array();

  while(!$result->EOF) {

    $key = $result->fields['p_id'];

    if (array_key_exists($key, $product_categories)) {
      
      array_push($product_categories[$key], $result->fields['cat_id']);

    } else { 
      $product_categories[$key] = array($result->fields['cat_id']);
    }
    
    $result->MoveNext();
  }

  return $product_categories;
}


/**
 * Get the list of categories for the specified language.
 * @param int $language_id The language of the category name and description.
 * @return array An array keyed by category id and storing its name and description.
 */

function get_categories($language_id) {

  global $db;

  $sql = "select categories_id, categories_name as name, categories_description as description from ".TABLE_CATEGORIES_DESCRIPTION." where language_id=".$language_id;

  $result = $db->Execute($sql);

  //convert this to hash with the category id as the key

  $categories = array();
  
  if ($result->RecordCount() > 0) {
    while(!$result->EOF) {

      $categories[$result->fields['categories_id']] = array("name" => $result->fields['name'],
                                "description" => $result->fields['description']);     
      $result->MoveNext();
    }
  }

  return $categories;
}

/**
 * Fetch back all the attributes used to make up a product feed..
 * @param int $language_id The language used within the feed.
 * @return array The product, product description and categories.
 */

function get_products($language_id) {

  $products = get_product_list($language_id);
  $categories = get_categories($language_id);
  $product_categories = get_product_categories();
  
  return array($products, $product_categories, $categories);
}

/**
 * On which server are we running?
 * @global const $request_type 
 * @return const HTTP_SERVER or HTTPS_SERVER.
 */

function get_server() {
  global $request_type; //SSL or NONSSL ?

  $server = HTTP_SERVER;

  if ($request_type == 'SSL') {
    if (ENABLE_SSL == 'true') {
      $server = HTTPS_SERVER ;
    }
  }

  return $server;
}

?>
<?php

$server_protocol = get_server(); //SSL or NONSSL ?

$lang = get_default_language();
$result = get_products($lang['languages_id']);

$products = $result[0];
$product_categories = $result[1];
$categories = $result[2];


//Ready to start flushing output buffers?
while (ob_get_level()) {
    ob_end_flush();
}

if (ob_get_length() === false) {
    ob_start();
}


//Write the response

echo "<?xml version=\"1.0\"?>"."\n";

echo "<products>"."\n";

//flush
ob_flush();
flush();

if ($products->RecordCount() >0) {
  while(!$products->EOF) {

    echo "<product id=\"".$products->fields['id']."\">"."\n";
    echo "<name lang=\"".$lang['code']."\"><![CDATA[".$products->fields['name']."]]></name>"."\n";
    echo "<description lang=\"".$lang['code']."\"><![CDATA[".$products->fields['description']."]]></description>"."\n";
    echo "<url lang=\"".$lang['code']."\">".zen_href_link("product_info", "products_id=".$products->fields['id']."&language=".$lang['code'], $request_type, false)."</url>"."\n";

    //Product image is optional
    
    if (zen_not_null($products->fields['image'])) {
      echo "<image>".$server_protocol."/".DIR_WS_IMAGES.$products->fields['image']."</image>"."\n";
    } 

    //echo the categories that the product belongs to
    
    if (array_key_exists($products->fields['id'], $product_categories)) {
      foreach($product_categories[$products->fields['id']] as $cat_id) {
    echo "<category lang=\"".$lang['code']."\"><![CDATA[".$categories[$cat_id]['name']."]]></category>"."\n";
      }
    }

    //Product manufacturer is optional
    if (zen_not_null($products->fields['manufacturers_name'])) {
      echo "<manufacturer><![CDATA[".$products->fields['manufacturers_name']."]]></manufacturer>"."\n";
    }

    echo "<price>".$products->fields['price']."</price>"."\n";
    echo "<stock>".$products->fields['stock']."</stock>"."\n";
    echo "</product>"."\n";
    $products->MoveNext();

    //flush
    ob_flush();
    flush();
  }
 }
echo "</products>"."\n";
?>

<?php
require(DIR_WS_INCLUDES."application_bottom.php");
?>

I haven't done any number formatting on the price element, so you may want to look at satpromo's code for that.

Does anyone have an example 3rd party product feed?

25 May 2008, 5:02 PM
#9
jamie2k avatar

jamie2k

New Zenner

Join Date:
Oct 2006
Location:
Suffolk UK
Posts:
55
Plugin Contributions:
1

Re: Real time XML product feed integration?

Does anyone know if this principal would work with setup of a connection to a couriers NDXML job booking system.

I am trying to get connected to a courier system , which uses NDXML

Please help... anyone

any posts you have seen that integrate xml would be great if you found them usefull when integrating XML into Zen so please let me know.

Kind regards

Jamie 2K

freezing_cold:

The OP was looking for code to import not export a product feed and this isn't any help to them either :(

Placing this code in the root of your Zen Cart install will generate an XML export of the products.

Tested on v1.3.7.

<?php require("includes/application_top.php"); ?> <?php // We'll be outputting XML header('Content-type: application/xml'); ?> <?php /** * Get the default language for the site * @return array An array containing the lanugage id and two-letter code. */ function get_default_language() { global $db; $sql = "select languages_id, code from ".TABLE_LANGUAGES.", ".TABLE_CONFIGURATION." where configuration.configuration_value=languages.code AND configuration.configuration_key='DEFAULT_LANGUAGE'"; $result = $db->Execute($sql); return array('code' => $result->fields['code'], 'languages_id' => $result->fields['languages_id']); } /** * Fetch back a list of products with their details in the language specified by $language_id. * @param int $language_id Specify the language that product descriptions should be returned as. * @return queryFactory A list of products wrapped in a queryFactory. */ function get_product_list($language_id) { global $db; $sql = "select p.products_id as id, p_d.products_name as name, p_d.products_description as description, p_d.products_url as url, p.products_image as image, p.products_quantity as stock, m.manufacturers_name as manufacturers_name, p.products_price as price from ".TABLE_PRODUCTS." as p inner join ".TABLE_PRODUCTS_DESCRIPTION." as p_d on p.products_id=p_d.products_id left outer join ".TABLE_MANUFACTURERS." as m on p.manufacturers_id=m.manufacturers_id where p_d.language_id=".$language_id; $result = $db->Execute($sql); return $result; } /** * Fetch back a list of products and their categories. * This a 1-to-many relationship * @return array An array keyed by the product and listing the categories it's in. */ function get_product_categories() { global $db; $sql = "select products_id as p_id, categories_id as cat_id from ".TABLE_PRODUCTS_TO_CATEGORIES." order by products_id"; $result = $db->Execute($sql); //Loop and store result as a hash with the product_id the key $product_categories = array(); while(!$result->EOF) { $key = $result->fields['p_id']; if (array_key_exists($key, $product_categories)) { array_push($product_categories[$key], $result->fields['cat_id']); } else { $product_categories[$key] = array($result->fields['cat_id']); } $result->MoveNext(); } return $product_categories; } /** * Get the list of categories for the specified language. * @param int $language_id The language of the category name and description. * @return array An array keyed by category id and storing its name and description. */ function get_categories($language_id) { global $db; $sql = "select categories_id, categories_name as name, categories_description as description from ".TABLE_CATEGORIES_DESCRIPTION." where language_id=".$language_id; $result = $db->Execute($sql); //convert this to hash with the category id as the key $categories = array(); if ($result->RecordCount() > 0) { while(!$result->EOF) { $categories[$result->fields['categories_id']] = array("name" => $result->fields['name'], "description" => $result->fields['description']); $result->MoveNext(); } } return $categories; } /** * Fetch back all the attributes used to make up a product feed.. * @param int $language_id The language used within the feed. * @return array The product, product description and categories. */ function get_products($language_id) { $products = get_product_list($language_id); $categories = get_categories($language_id); $product_categories = get_product_categories(); return array($products, $product_categories, $categories); } /** * On which server are we running? * @global const $request_type * @return const HTTP_SERVER or HTTPS_SERVER. */ function get_server() { global $request_type; //SSL or NONSSL ? $server = HTTP_SERVER; if ($request_type == 'SSL') { if (ENABLE_SSL == 'true') { $server = HTTPS_SERVER ; } } return $server; } ?> <?php $server_protocol = get_server(); //SSL or NONSSL ? $lang = get_default_language(); $result = get_products($lang['languages_id']); $products = $result[0]; $product_categories = $result[1]; $categories = $result[2]; //Ready to start flushing output buffers? while (ob_get_level()) { ob_end_flush(); } if (ob_get_length() === false) { ob_start(); } //Write the response echo "<?xml version=\"1.0\"?>"."\n";

echo "<products>"."\n";

//flush
ob_flush();
flush();

if ($products->RecordCount() >0) {
while(!$products->EOF) {

echo "<product id=\"".$products->fields['id']."\">"."\n";
echo "<name lang=\"".$lang['code']."\"><![CDATA[".$products->fields['name']."]]></name>"."\n";
echo "<description lang=\"".$lang['code']."\"><![CDATA[".$products->fields['description']."]]></description>"."\n";
echo "<url lang=\"".$lang['code']."\">".zen_href_link("product_info", "products_id=".$products->fields['id']."&language=".$lang['code'], $request_type, false)."</url>"."\n";

//Product image is optional

if (zen_not_null($products->fields['image'])) {
  echo "<image>".$server_protocol."/".DIR_WS_IMAGES.$products->fields['image']."</image>"."\n";
} 

//echo the categories that the product belongs to

if (array_key_exists($products->fields['id'], $product_categories)) {
  foreach($product_categories[$products->fields['id']] as $cat_id) {
echo "<category lang=\"".$lang['code']."\"><![CDATA[".$categories[$cat_id]['name']."]]></category>"."\n";
  }
}

//Product manufacturer is optional
if (zen_not_null($products->fields['manufacturers_name'])) {
  echo "<manufacturer><![CDATA[".$products->fields['manufacturers_name']."]]></manufacturer>"."\n";
}

echo "<price>".$products->fields['price']."</price>"."\n";
echo "<stock>".$products->fields['stock']."</stock>"."\n";
echo "</product>"."\n";
$products->MoveNext();

//flush
ob_flush();
flush();

}
}
echo "</products>"."\n";
?>

<?php require(DIR_WS_INCLUDES."application_bottom.php"); ?>
>  
> I haven't done any number formatting on the price element, so you may want to look at satpromo's code for that.
>  
> Does anyone have an example 3rd party product feed?
3 Dec 2008, 10:10 PM
#10
lmelton avatar

lmelton

New Zenner

Join Date:
Dec 2008
Posts:
2
Plugin Contributions:
0

Re: Real time XML product feed integration?

I need a programmer who can load an xml product feed into our Zen Cart we want to integrate Tech Data into our site. Can anyone help with that. Will pay!

3 Dec 2008, 10:51 PM
#11
yellow1912 avatar

yellow1912

Totally Zenned

Join Date:
Oct 2006
Posts:
5,422
Plugin Contributions:
0

Re: Real time XML product feed integration?

lmelton:

I need a programmer who can load an xml product feed into our Zen Cart we want to integrate Tech Data into our site. Can anyone help with that. Will pay!
Post the details in the Commercial help forum will be better.

25 May 2009, 1:26 PM
#12
jimchin avatar

jimchin

New Zenner

Join Date:
Mar 2009
Posts:
2
Plugin Contributions:
0

Re: Real time XML product feed integration?

I've found a company that can help with this problem. For not a lot of money they can host your zencart shop. I have a shop with them. They also have a module that in my case is taking my suppliers xml product feed and keeps my product inventory updated in real time. Saving me hours of time.

If you want to learn more then visit http://www.pcs-pcs.com/solutions.html

I hope that helps

7 Apr 2011, 6:19 PM
#13
orange_juice avatar

orange_juice

Zen Follower

Join Date:
Apr 2009
Location:
Athens, Europe
Posts:
125
Plugin Contributions:
0

Re: Real time XML product feed integration?

freezing_cold:

The OP was looking for code to import not export a product feed and this isn't any help to them either :(

Placing this code in the root of your Zen Cart install will generate an XML export of the products.

Tested on v1.3.7.

<?php require("includes/application_top.php"); ?> <?php // We'll be outputting XML header('Content-type: application/xml'); ?> <?php /** * Get the default language for the site * @return array An array containing the lanugage id and two-letter code. */ function get_default_language() { global $db; $sql = "select languages_id, code from ".TABLE_LANGUAGES.", ".TABLE_CONFIGURATION." where configuration.configuration_value=languages.code AND configuration.configuration_key='DEFAULT_LANGUAGE'"; $result = $db->Execute($sql); return array('code' => $result->fields['code'], 'languages_id' => $result->fields['languages_id']); } /** * Fetch back a list of products with their details in the language specified by $language_id. * @param int $language_id Specify the language that product descriptions should be returned as. * @return queryFactory A list of products wrapped in a queryFactory. */ function get_product_list($language_id) { global $db; $sql = "select p.products_id as id, p_d.products_name as name, p_d.products_description as description, p_d.products_url as url, p.products_image as image, p.products_quantity as stock, m.manufacturers_name as manufacturers_name, p.products_price as price from ".TABLE_PRODUCTS." as p inner join ".TABLE_PRODUCTS_DESCRIPTION." as p_d on p.products_id=p_d.products_id left outer join ".TABLE_MANUFACTURERS." as m on p.manufacturers_id=m.manufacturers_id where p_d.language_id=".$language_id; $result = $db->Execute($sql); return $result; } /** * Fetch back a list of products and their categories. * This a 1-to-many relationship * @return array An array keyed by the product and listing the categories it's in. */ function get_product_categories() { global $db; $sql = "select products_id as p_id, categories_id as cat_id from ".TABLE_PRODUCTS_TO_CATEGORIES." order by products_id"; $result = $db->Execute($sql); //Loop and store result as a hash with the product_id the key $product_categories = array(); while(!$result->EOF) { $key = $result->fields['p_id']; if (array_key_exists($key, $product_categories)) { array_push($product_categories[$key], $result->fields['cat_id']); } else { $product_categories[$key] = array($result->fields['cat_id']); } $result->MoveNext(); } return $product_categories; } /** * Get the list of categories for the specified language. * @param int $language_id The language of the category name and description. * @return array An array keyed by category id and storing its name and description. */ function get_categories($language_id) { global $db; $sql = "select categories_id, categories_name as name, categories_description as description from ".TABLE_CATEGORIES_DESCRIPTION." where language_id=".$language_id; $result = $db->Execute($sql); //convert this to hash with the category id as the key $categories = array(); if ($result->RecordCount() > 0) { while(!$result->EOF) { $categories[$result->fields['categories_id']] = array("name" => $result->fields['name'], "description" => $result->fields['description']); $result->MoveNext(); } } return $categories; } /** * Fetch back all the attributes used to make up a product feed.. * @param int $language_id The language used within the feed. * @return array The product, product description and categories. */ function get_products($language_id) { $products = get_product_list($language_id); $categories = get_categories($language_id); $product_categories = get_product_categories(); return array($products, $product_categories, $categories); } /** * On which server are we running? * @global const $request_type * @return const HTTP_SERVER or HTTPS_SERVER. */ function get_server() { global $request_type; //SSL or NONSSL ? $server = HTTP_SERVER; if ($request_type == 'SSL') { if (ENABLE_SSL == 'true') { $server = HTTPS_SERVER ; } } return $server; } ?> <?php $server_protocol = get_server(); //SSL or NONSSL ? $lang = get_default_language(); $result = get_products($lang['languages_id']); $products = $result[0]; $product_categories = $result[1]; $categories = $result[2]; //Ready to start flushing output buffers? while (ob_get_level()) { ob_end_flush(); } if (ob_get_length() === false) { ob_start(); } //Write the response echo "<?xml version=\"1.0\"?>"."\n";

echo "<products>"."\n";

//flush
ob_flush();
flush();

if ($products->RecordCount() >0) {
while(!$products->EOF) {

echo "<product id=\"".$products->fields['id']."\">"."\n";
echo "<name lang=\"".$lang['code']."\"><![CDATA[".$products->fields['name']."]]></name>"."\n";
echo "<description lang=\"".$lang['code']."\"><![CDATA[".$products->fields['description']."]]></description>"."\n";
echo "<url lang=\"".$lang['code']."\">".zen_href_link("product_info", "products_id=".$products->fields['id']."&language=".$lang['code'], $request_type, false)."</url>"."\n";

//Product image is optional

if (zen_not_null($products->fields['image'])) {
  echo "<image>".$server_protocol."/".DIR_WS_IMAGES.$products->fields['image']."</image>"."\n";
} 

//echo the categories that the product belongs to

if (array_key_exists($products->fields['id'], $product_categories)) {
  foreach($product_categories[$products->fields['id']] as $cat_id) {
echo "<category lang=\"".$lang['code']."\"><![CDATA[".$categories[$cat_id]['name']."]]></category>"."\n";
  }
}

//Product manufacturer is optional
if (zen_not_null($products->fields['manufacturers_name'])) {
  echo "<manufacturer><![CDATA[".$products->fields['manufacturers_name']."]]></manufacturer>"."\n";
}

echo "<price>".$products->fields['price']."</price>"."\n";
echo "<stock>".$products->fields['stock']."</stock>"."\n";
echo "</product>"."\n";
$products->MoveNext();

//flush
ob_flush();
flush();

}
}
echo "</products>"."\n";
?>

<?php require(DIR_WS_INCLUDES."application_bottom.php"); ?>
> 
> I haven't done any number formatting on the price element, so you may want to look at satpromo's code for that.
> 
> Does anyone have an example 3rd party product feed?

Hallo, this worked just fine for its purpose on 1.3.9h. 

I performed some php modifications to suit the needs of the xml specifications they asked me.

It saved me from a lot of trouble:

The only xml customizable feeder available is from magneticone and it is encoded (ioncube or zend). 

It is very strong but it had some issues with the second language of my site. Moreover, I wanted to add a <date> YYY-MM-DD HH:MM </date> field at the top of the file, and they told me that this is not possible ... OK!

Thanx! 

:clap:

Kind regards,
orange_juice