Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

XML Export, need to export also product url, please help


DonStefano

Recommended Posts

this is the code that i am using and i need to add also product url there for export

<?php
require('includes/application_top.php');

function unhtmlentities($string) {
 $trans_tbl = get_html_translation_table (HTML_ENTITIES);
 $trans_tbl = array_flip ($trans_tbl);
 return strtr ($string, $trans_tbl);
}

$xml_export_filename = 'exportfile';  // default XML filename
$export_folder = 'dataexport';  // folder name that XML files to be created. should be under /catalog/ main folder.


if ($_POST['action']=='export') {

 $xml_file='';

 function SaveFile($data, $fname = "products"){
       global $export_folder;
       $filename  = DIR_FS_CATALOG . $export_folder . '/' . $fname;

       if ($fp = fopen($filename, 'w+')){
               fwrite($fp, $data);
               fclose($fp);
               return true;
       }
       else  return false;
 }

 function get_categories_ids($parent_id=0) {
   $categories=tep_db_query("select categories_id from ".TABLE_CATEGORIES." where parent_id='".$parent_id."'");
   while ($category=tep_db_fetch_array($categories)) {
    	$categories_ids[]=$category['categories_id'];
	$current_categories_id = get_categories_ids($category['categories_id']);
	if(is_array($current_categories_id)){
		$categories_ids=array_merge($categories_ids, $current_categories_id);
	}
   }
   return $categories_ids;
 }

 $categories_ids[]=$categories_id;

 $current_categories_id = get_categories_ids($_POST['categories_id']);
 if(is_array($current_categories_id)){
	$categories_ids=array_merge($categories_ids, $current_categories_id);
 }

 $categories_ids = array_filter($categories_ids);

$already_sent = array();

// Varsayύlan CURRENCY nedir bakalύm
$query_currency = tep_db_query("SELECT configuration_value FROM " . TABLE_CONFIGURATION . " WHERE configuration_key = 'DEFAULT_CURRENCY'");
$row_currency = tep_db_fetch_array( $query_currency );

// Varsayύlan DέL nedir bakalύm
$query_language_code = tep_db_query("SELECT configuration_value FROM " . TABLE_CONFIGURATION . " WHERE configuration_key = 'DEFAULT_LANGUAGE'");
$row_language_code = tep_db_fetch_array( $query_language_code );

// Varsayύlan DέL ID nedir bakalύm
$query_language_id = tep_db_query("SELECT languages_id FROM " . TABLE_LANGUAGES . " WHERE code = '" . $row_language_code['configuration_value'] . "'");
$row_language_id = tep_db_fetch_array( $query_language_id );

// άrόn bilgilerini alalύm
$products_query = tep_db_query("SELECT
manuf.manufacturers_Name AS manufacturer,
prd.products_id AS id,
prd.products_id AS mpc,
prd.products_model AS model,
prd.products_quantity AS qty,
prdsc.products_Name AS name,
prdsc.products_description AS description,
prd.products_price AS price,
prd.products_image AS image,
prd.products_weight AS weight,
prd.products_status AS status,
prd.products_date_available AS date_available,
prd.products_last_modified AS last_modified,
prd.products_tax_class_id AS tax_id,

catdescparent4.categories_Name AS parent4_cat,
catdescparent3.categories_Name AS parent3_cat,
catdescparent2.categories_Name AS parent2_cat,
catdescparent1.categories_Name AS parent1_cat,
catdesccurrent.categories_Name AS current_cat,

catdescparent4.categories_id AS parent4_id,
catdescparent3.categories_id AS parent3_id,
catdescparent2.categories_id AS parent2_id,
catdescparent1.categories_id AS parent1_id,
catdesccurrent.categories_id AS current_id

FROM (" . TABLE_CATEGORIES . " ,
" . TABLE_PRODUCTS . " prd,
" . TABLE_PRODUCTS_DESCRIPTION . " AS prdsc,
" . TABLE_CATEGORIES_DESCRIPTION . " AS catdesccurrent,
" . TABLE_PRODUCTS_TO_CATEGORIES . " AS prdtocat)

LEFT JOIN " . TABLE_CATEGORIES_DESCRIPTION . " AS catdescparent1 on ( catdescparent1.categories_id = " . TABLE_CATEGORIES . ".parent_id AND catdescparent1.language_id = '" . $row_language_id['languages_id'] . "' )
LEFT JOIN " . TABLE_CATEGORIES . " AS cat2 on ( cat2.categories_id = " . TABLE_CATEGORIES . ".parent_id )
LEFT JOIN " . TABLE_CATEGORIES_DESCRIPTION . " AS catdescparent2 on ( catdescparent2.categories_id = cat2.parent_id AND catdescparent2.language_id = '" . $row_language_id['languages_id'] . "' )
LEFT JOIN " . TABLE_CATEGORIES . " AS cat3 on ( cat3.categories_id = cat2.parent_id )
LEFT JOIN " . TABLE_CATEGORIES_DESCRIPTION . " AS catdescparent3 on ( catdescparent3.categories_id = cat3.parent_id AND catdescparent3.language_id = '" . $row_language_id['languages_id'] . "' )
LEFT JOIN " . TABLE_CATEGORIES . " AS cat4 on ( cat4.categories_id = cat3.parent_id )
LEFT JOIN " . TABLE_CATEGORIES_DESCRIPTION . " AS catdescparent4 on ( catdescparent4.categories_id = cat4.parent_id AND catdescparent4.language_id = '" . $row_language_id['languages_id'] . "' )

LEFT JOIN " . TABLE_MANUFACTURERS . " AS manuf ON ( manuf.manufacturers_id = prd.manufacturers_id )

WHERE
( prd.products_id = prdsc.products_id AND prdsc.language_id = '" . $row_language_id['languages_id'] . "' )
AND prd.products_id = prdtocat.products_id
AND prdtocat.categories_id = " . TABLE_CATEGORIES . ".categories_id
AND ( catdesccurrent.categories_id = " . TABLE_CATEGORIES . ".categories_id AND catdesccurrent.language_id = '" . $row_language_id['languages_id'] . "' )
AND prdtocat.categories_id in (".implode($categories_ids, ', ').")
LIMIT 10000");

// άrόne ait φzel fiyat varmύ bakalύm
$specials_query = tep_db_query("SELECT
" . TABLE_SPECIALS . ".products_id AS idS,
FORMAT(" . TABLE_SPECIALS . ".specials_new_products_price, 2) AS priceS
FROM
" . TABLE_SPECIALS . ", " . TABLE_PRODUCTS . "
WHERE
" . TABLE_SPECIALS . ".products_id = " . TABLE_PRODUCTS . ".products_id
AND " . TABLE_SPECIALS . ".status != 0
AND " . TABLE_PRODUCTS . ".products_status != 0");

while( $row_s = tep_db_fetch_array( $specials_query )) foreach ($row_s as $i=>$v) $SPECIALS[$row_s['idS']][$i] = $v;

 if (tep_db_num_rows($products_query)) {
   $xml_file.="<?xml version=\"1.0\" encoding=\"ISO-8859-7\"?>\n";
//	$xml_file.="<date>2011-04-30 17:17</date>\n";
   $xml_file.="<store>\n";

   while ($product=tep_db_fetch_array($products_query)) {
// Eπer aynύ kodda bir όrόn datasύ gφndermiώsek diπerini artύk gφndermeyelim.
if ($already_sent[$product['mpc']] == 1) continue;
   // Φzel fiyatύ varsa όrόnόn onu kullanalύm
if( $SPECIALS[$product['id']]['idS'] ) $product['price_special'] = $SPECIALS[$product['id']]['priceS'];
if($product['image']) $product['image_url'] = HTTP_SERVER . DIR_WS_CATALOG . DIR_WS_IMAGES . $product['image'];
if($product['product_url']) $product['product_url'] = HTTP_SERVER . DIR_WS_CATALOG . $product['product_url'];

     $xml_file.="\t" . "<Product>\n";
if($product['parent4_cat']){
     $xml_file.="\t\t" . "<Main_Category_id>".$product['parent4_id']."</Main_Category_id>\n";
  $xml_file.="\t\t" . "<Main_Category_Name>".htmlspecialchars($product['parent4_cat'])."</Main_Category_Name>\n";
     $xml_file.="\t\t" . "<Sub_Category_1_id>".$product['parent3_id']."</Sub_Category_1_id>\n";
  $xml_file.="\t\t" . "<Sub_Category_1_Name>".htmlspecialchars($product['parent3_cat'])."</Sub_Category_1_Name>\n";
     $xml_file.="\t\t" . "<Sub_Category_2_id>".$product['parent2_id']."</Sub_Category_2_id>\n";
     $xml_file.="\t\t" . "<Sub_Category_2_Name>".htmlspecialchars($product['parent2_cat'])."</Sub_Category_2_Name>\n";
     $xml_file.="\t\t" . "<Sub_Category_3_id>".$product['parent1_id']."</Sub_Category_3_id>\n";
     $xml_file.="\t\t" . "<Sub_Category_3_Name>".htmlspecialchars($product['parent1_cat'])."</Sub_Category_3_Name>\n";
     $xml_file.="\t\t" . "<Sub_Category_4_id>".$product['current_id']."</Sub_Category_4_id>\n";
     $xml_file.="\t\t" . "<Sub_Category_4_Name>".htmlspecialchars($product['current_cat'])."</Sub_Category_4_Name>\n";
}
elseif($product['parent3_cat']){
     $xml_file.="\t\t" . "<Main_Category_id>".$product['parent3_id']."</Main_Category_id>\n";
  $xml_file.="\t\t" . "<Main_Category_Name>".htmlspecialchars($product['parent3_cat'])."</Main_Category_Name>\n";
     $xml_file.="\t\t" . "<Sub_Category_1_id>".$product['parent2_id']."</Sub_Category_1_id>\n";
  $xml_file.="\t\t" . "<Sub_Category_1_Name>".htmlspecialchars($product['parent2_cat'])."</Sub_Category_1_Name>\n";
     $xml_file.="\t\t" . "<Sub_Category_2_id>".$product['parent1_id']."</Sub_Category_2_id>\n";
     $xml_file.="\t\t" . "<Sub_Category_2_Name>".htmlspecialchars($product['parent1_cat'])."</Sub_Category_2_Name>\n";
     $xml_file.="\t\t" . "<Sub_Category_3_id>".$product['current_id']."</Sub_Category_3_id>\n";
     $xml_file.="\t\t" . "<Sub_Category_3_Name>".htmlspecialchars($product['current_cat'])."</Sub_Category_3_Name>\n";
}
elseif($product['parent2_cat']){
     $xml_file.="\t\t" . "<Main_Category_id>".$product['parent2_id']."</Main_Category_id>\n";
  $xml_file.="\t\t" . "<Main_Category_Name>".htmlspecialchars($product['parent2_cat'])."</Main_Category_Name>\n";
     $xml_file.="\t\t" . "<Sub_Category_1_id>".$product['parent1_id']."</Sub_Category_1_id>\n";
  $xml_file.="\t\t" . "<Sub_Category_1_Name>".htmlspecialchars($product['parent1_cat'])."</Sub_Category_1_Name>\n";
     $xml_file.="\t\t" . "<Sub_Category_2_id>".$product['current_id']."</Sub_Category_2_id>\n";
     $xml_file.="\t\t" . "<Sub_Category_2_Name>".htmlspecialchars($product['current_cat'])."</Sub_Category_2_Name>\n";
}
elseif($product['parent1_cat']){
     $xml_file.="\t\t" . "<Sub_Category_1_id>".$product['current_id']."</Sub_Category_1_id>\n";
  $xml_file.="\t\t" . "<categoryPath>".htmlspecialchars($product['parent1_cat'])."->".htmlspecialchars($product['current_cat'])."</categoryPath>\n";
}
else { // 	 !!!
     $xml_file.="\t\t" . "<Main_Category_id>".$product['current_id']."</Main_Category_id>\n";
  $xml_file.="\t\t" . "<Main_Category_Name>".htmlspecialchars($product['current_cat'])."</Main_Category_Name>\n";
}

     $xml_file.="\t\t" . "<Product_id>".$product['id']."</Product_id>\n";
     $xml_file.="\t\t" . "<Product_Model>".htmlspecialchars($product['model'])."</Product_Model>\n";
     $xml_file.="\t\t" . "<title>".htmlspecialchars($product['name'])."</title>\n";
     $xml_file.="\t\t" . "<description>".htmlspecialchars($product['description'])."</description>\n";
     $xml_file.="\t\t" . "<Product_Price>".number_format($product['price'],2,'.','')."</Product_Price>\n";

//      $xml_file.="\t\t" . "<Product_Price_Special>".number_format($product['price_special'],2,'.','')."</Product_Price_Special>\n";
//      $xml_file.="\t\t" . "<Product_Currency>".DEFAULT_CURRENCY."</Product_Currency>\n";
//     $xml_file.="\t\t" . "<Product_Vat_Rate>".tep_get_tax_rate($product['tax_id'])."</Product_Vat_Rate>\n";
 //    $xml_file.="\t\t" . "<Product_Image>".$product['image']."</Product_Image>\n";
     $xml_file.="\t\t" . "<image>".$product['image_url']."</image>\n";
//     $xml_file.="\t\t" . "<Product_Quantity>".$product['qty']."</Product_Quantity>\n";
//     $xml_file.="\t\t" . "<Product_Weight>".$product['weight']."</Product_Weight>\n";
 //    $xml_file.="\t\t" . "<Product_Status>".$product['status']."</Product_Status>\n";
   //  $xml_file.="\t\t" . "<Product_Manufacturer>".$product['manufacturer']."</Product_Manufacturer>\n";
 //    $xml_file.="\t\t" . "<Product_Last_Modified>".$product['last_modified']."</Product_Last_Modified>\n";
  //   $xml_file.="\t\t" . "<Product_Date_Available>".$product['date_available']."</Product_Date_Available>\n";
     $xml_file.="\t" .   "</Product>\n";

     $already_sent[$product['mpc']] = 1;
   }
   $xml_file.="</store>\n";
 }

 switch ($_POST['XML_archive']) {
   case 'xml': $ext='.xml';
               break;
   case 'zip': $ext='.xml.zip';
               $zipfile = new zipfile();
               $zipfile->addFile($xml_file, $_POST['filename'].'.xml');
               $xml_file=$zipfile->file();
               break;
   case 'gzip':$ext='.xml.gz';
               $xml_file=gzencode($xml_file);
               break;
 }

if ($_POST['download']){
  header("Content-Type: application/octetstream");
  header("Content-Disposition: attachment; filename=".$_POST['filename'].$ext);
  header("Content-Length: ".strlen($xml_file));
  header("Expires: 0");
  echo $xml_file;
  exit();
}
else {
   if(SaveFile($xml_file, $_POST['filename'].$ext) == 'false') echo 'XML file successfully created..';
   else echo 'XML file not created..';
   exit();
}
}
?>

<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo TITLE; ?></title>
</head>
<body>

<table border="1" width="100%" cellspacing="0" cellpadding="2">
     <tr bgcolor="#CCCCCC">
       <td colspan="2"><strong>Dimiourgia Xml gia  BestPrice</strong></td>
     </tr>
     <tr>
       <td>Epelekse katigoria gia aeksagogi</td>
       <td class="main">
   	    <?php echo tep_draw_form('xml-export', basename($_SERVER['PHP_SELF']), '', 'post') ."\n". tep_draw_pull_down_menu('categories_id', tep_get_category_tree(), $categories_id) ."\n"; ?>
       	<input type="hidden" name="action" value="export">
       </td>
      </tr>
      <tr>
        	<td>Typos kai onoma arxeiou (Xoris tin epektasi)</td>
        	<td>
        		<select name="XML_archive">
            <option value="xml">Plain XML</option>
           <?php if (@function_exists('gzcompress')) { ?>
            <option value="zip">ZIP'ped XML</option>
           <?php } if (@function_exists('gzencode')) { ?>
            <option value="gzip">GZIP'ped XML</option>
           <?php } ?>
           </select>
        <input type="text" name="filename" value="<?php echo $xml_export_filename; ?>">
        <input name="download" type="checkbox" value="ON"> katevase to arxeio ston H/Y
           </td>
      <tr>
           <td colspan="2"><input type="submit" value="dimiourgia xml"></form></td>
     </tr>
</table>
</body>
</html>

Link to comment
Share on other sites

  • 8 months later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...