Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

full categories path in XML file


drferrari

Recommended Posts

Posted

how can I get with some function Full categories Path for all my product in XML file.

 

e.g. Home > Auto > Ferrari > F40

 

NOT only F40

 

something like <?php echo $breadcrumb->trail(' » '); ?> but this not work in xml file.

 

my code:

 

<?php
header("Content-type: text/xml");
require('includes/application_top.php');
$navigation->remove_current_page();
define('STORE_URL', 'http://localhost/STORE NAME');
function xmlencode($string) {
$string = str_replace("&", "&", $string);
$string = str_replace("<", "<", $string);
return $string;
}
?>
<?php
echo '<?xml version="1.0" encoding="utf-8"?>';?>
<store>
<?php $timestamp = date("Y-m-d G:i"); ?>
<date><?php echo $timestamp; ?></date>
<products>
<?php
$new_products_query = tep_db_query("select distinct
p.products_id, p.products_quantity, p.products_model, p.products_image, p.products_tax_class_id, pd.products_name, if(s.status, s.specials_new_products_price, p.products_price) as products_price, cd.categories_name, cd.categories_id, p2m.manufacturers_name,
pd.products_description from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c,
" . TABLE_CATEGORIES_DESCRIPTION . " cd, " .TABLE_MANUFACTURERS . " p2m " . " where p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and p.products_status = '1' and p.products_id = pd.products_id and
c.categories_id = cd.categories_id and pd.language_id = '" . (int)$languages_id . "'");
while ($new_products = tep_db_fetch_array($new_products_query)) {

?>
<product>
<productId><?php echo $new_products['products_id']; ?></productId>
<productName><?php echo xmlencode($new_products['products_name']); ?></productName>
<productDescription><?php echo xmlencode($new_products['products_description']); ?></productDescription>
<productURL><?php echo STORE_URL . '/' . FILENAME_PRODUCT_INFO . '?products_id=' . $new_products['products_id'];?></productURL>
<imageURL><?php echo STORE_URL . '/' . DIR_WS_IMAGES . $new_products['products_image']; ?></imageURL>
<price><?php echo tep_round(tep_add_tax($new_products['products_price'], tep_get_tax_rate($new_products['products_tax_class_id'])), 2); ?></price>
<categoryID><?php echo $new_products['categories_id']; ?></categoryID>
<category><?php echo STORE_URL . '/' . FILENAME_DEFAULT . '?cPath=' . $new_products['categories_id']; ?></category>
<categoryPath><?php echo tep_get_path($new_products['categories_id']); ?></categoryPath>
</product>
<?php } ?>
</products>
</store>

Posted

#14steve14, I looking for something like tep_get_path($new_products['categories_id']);

 

did you have any code example

Posted

tep_get_product_path($products_id); give you e.g. 39_51

 

39=Auto, 51=ferrari

 

how can I convert 39_51 to words => Auto > Ferrari

 

I think I must create new tep_get_product_path2

Posted

includes/functions/general.php

 

add 2 new functions

 

////
// FOR MY XML FILE TO FIND ***FULL CATEGORIES PATH *******
//
function tep_get_parent_categories_xml_file(&$categories, $categories_id) {
$parent_categories_query = tep_db_query("select c.parent_id, cd.categories_id, cd.categories_name
from " . TABLE_CATEGORIES . " c,". TABLE_CATEGORIES_DESCRIPTION ." cd
where
c.categories_id = '" . (int)$categories_id . "' and
c.parent_id = cd.categories_id limit 1");

while ($parent_categories = tep_db_fetch_array($parent_categories_query)) {
 if ($parent_categories['parent_id'] == 0) return true;
 $categories[sizeof($categories)] = $parent_categories['categories_name'];
 if ($parent_categories['parent_id'] != $categories_id) {
 tep_get_parent_categories_xml_file($categories, $parent_categories['parent_id']);
 }
}
}
////
// FOR MY XML FILE TO FIND ***FULL CATEGORIES PATH *******
//
function tep_get_product_path_xml_file($products_id) {
$cPath = '';
$category_query = tep_db_query("select p2c.categories_id, cd.categories_id, cd.categories_name
from" . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, ". TABLE_CATEGORIES_DESCRIPTION ." cd
where
p.products_id = '" . (int)$products_id . "' and
p.products_status = '1' and
p.products_id = p2c.products_id and
cd.categories_id = p2c.categories_id limit 1");

if (tep_db_num_rows($category_query)) {
 $category = tep_db_fetch_array($category_query);
 $categories = array();
 tep_get_parent_categories_xml_file($categories, $category['categories_id']);
 $categories = array_reverse($categories);
 $cPath = implode('_', $categories);
 if (tep_not_null($cPath)) $cPath .= ' > ';
 $cPath .= $category['categories_name'];
}
return HEADER_TITLE_TOP ." > ".$cPath;
}

 

add to xml file:

<categoryPath><?php echo tep_get_product_path_xml_file($new_products['products_id']); ?></categoryPath>

 

this is the solution for Full categories Path.

Posted

@@drferrari

 

the breadchrump do this for you at bottom of application_top.php.

how can I get with some function Full categories Path for all my product in XML file.

 

e.g. Home > Auto > Ferrari > F40

 

NOT only F40

 

something like <?php echo $breadcrumb->trail(' » '); ?> but this not work in xml file.

 

 

 

$breadcrumb->trail is an object array where you can find everything. You need define $languages_id before the code.

 

 

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


// include the breadcrumb_xml class and start the breadcrumb_xml trail
 $breadcrumb_xml = new breadcrumb;
 $languages_id = '1';

 $new_products_query = tep_db_query("select distinct p.products_id, p.products_quantity, p.products_model, p.products_image, p.products_tax_class_id, pd.products_name, if(s.status, s.specials_new_products_price, p.products_price) as products_price, cd.categories_name, cd.categories_id, p2m.manufacturers_name, pd.products_description from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd, " .TABLE_MANUFACTURERS . " p2m " . " where p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and p.products_status = '1' and p.products_id = pd.products_id and c.categories_id = cd.categories_id and pd.language_id = '" . (int)$languages_id . "'");
 while ($new_products = tep_db_fetch_array($new_products_query)) {

   $breadcrumb_xml->reset();
   $products_id = $new_products['products_id'];  //by while
   //$manufacturers_id = 1; //by while

 // calculate category path
   $cPath = tep_get_product_path($products_id);

   if (tep_not_null($cPath)) {
  $cPath_array = tep_parse_category_path($cPath);
  $cPath = implode('_', $cPath_array);
  $current_category_id = $cPath_array[(sizeof($cPath_array)-1)];
   } else {
  $current_category_id = 0;
   }



   $breadcrumb_xml->add(HEADER_TITLE_TOP, HTTP_SERVER);
   $breadcrumb_xml->add(HEADER_TITLE_CATALOG, tep_href_link(FILENAME_DEFAULT));

 // add category names or the manufacturer name to the breadcrumb_xml trail
   if (isset($cPath_array)) {
  for ($i=0, $n=sizeof($cPath_array); $i<$n; $i++) {
    $categories_query = tep_db_query("select categories_name from " . TABLE_CATEGORIES_DESCRIPTION . " where categories_id = '" . (int)$cPath_array[$i] . "' and language_id = '" . (int)$languages_id . "'");
    if (tep_db_num_rows($categories_query) > 0) {
	  $categories = tep_db_fetch_array($categories_query);
	  $breadcrumb_xml->add($categories['categories_name'], tep_href_link(FILENAME_DEFAULT, 'cPath=' . implode('_', array_slice($cPath_array, 0, ($i+1)))));
    } else {
	  break;
    }
  }
   } elseif (isset($manufacturers_id)) {
  $manufacturers_query = tep_db_query("select manufacturers_name from " . TABLE_MANUFACTURERS . " where manufacturers_id = '" . (int)$manufacturers_id . "'");
  if (tep_db_num_rows($manufacturers_query)) {
    $manufacturers = tep_db_fetch_array($manufacturers_query);
    $breadcrumb_xml->add($manufacturers['manufacturers_name'], tep_href_link(FILENAME_DEFAULT, 'manufacturers_id=' . $manufacturers_id));
  }
   }

 // add the products model to the breadcrumb_xml trail
   if (isset($products_id)) {
  $model_query = tep_db_query("select products_model from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");
  if (tep_db_num_rows($model_query)) {
    $model = tep_db_fetch_array($model_query);
    $breadcrumb_xml->add($model['products_model'], tep_href_link(FILENAME_PRODUCT_INFO, 'cPath=' . $cPath . '&products_id=' . $products_id));
  }
   }

   print_r($breadcrumb_xml->_trail);  //use for something the array object
 }
// ******************************************************
//end of do-while of for or something you like
// ******************************************************
?>

 

maybe works

:blink:
osCommerce based shop owner with minimal design and focused on background works. When the less is more.
Email managment with tracking pixel, package managment for shipping, stock management, warehouse managment with bar code reader, parcel shops management on 3000 pickup points without local store.

  • 4 weeks later...
Posted

@@drferrari

 

I tried your code for xml output and I got in xml:

 

<categoryPath><font color="#000000"><b>1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'p, products_to_categories p2c, categories_description cd
where
p.products_id = '' at line 2<br><br>select p2c.categories_id, cd.categories_id, cd.categories_name
fromproducts p, products_to_categories p2c, categories_description cd
where
p.products_id = '75' and
p.products_status = '1' and
p.products_id = p2c.products_id and
cd.categories_id = p2c.categories_id limit 1<br><br><small><font color="#ff0000">[TEP STOP]</font></small><br><br></b></font>

  • 1 month later...

Archived

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

×
×
  • Create New...