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?
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?
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='.$pr oduct_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
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,
I Think, Therefore I Zen. I Zen, Therefore, I AM!
Personalized Flowers!
Flowertown Speaking Roses using version 1.5.7-06232020
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.
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!
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.
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.
I haven't done any number formatting on the price element, so you may want to look at satpromo's code for that.Code:<?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"); ?>
Does anyone have an example 3rd party product feed?
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
Last edited by jamie2k; 25 May 2008 at 06:03 PM. Reason: typo
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!
Bookmarks