Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Full category path for product


genata93

Recommended Posts

Hello,

I am trying to write a file that outputs all my products and custom data for them. I have success when trying to get the category_name, but it outputs just the current category_name not the whole category path.

Here's my code:

<?php
header ('Content-type: text/xml;');
require('includes/application_top.php');
mysql_connect('localhost', 'user', 'pass');
mysql_select_db('db');
$rs=mysql_query('SELECT * FROM `products`,`products_description`,`products_to_categories`,`categories_description`
			 WHERE `products`.`products_id`=`products_description`.`products_id`
 AND `products`.`products_id` = `products_to_categories`.`products_id`
	 AND `products_to_categories`.`categories_id` = `categories_description`.`categories_id`');
//<-- Connect end -->
$breadcrumb_xml = new breadcrumb;
$languages_id = '1';
function category_path($row) {
$breadcrumb_xml->reset();
$products_id = $row['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
}

$rss='<?xml version="1.0" encoding="UTF-8" ?>
<catalog>
';
while($row=mysql_fetch_assoc($rs))
{
if ($row['products_status']>0) {
 $rss.='
<product>
<id>' .$row['products_id']. '</id>
<name><![CDATA[' .$row['products_name']. ']]></name>
<price>' .$row['products_price']. '</price>
<pricewithshipping>' .delivery_price_cat($row). '</pricewithshipping>
<stock>true</stock>
<itemid>' .$row['products_model']. '</itemid>
<urlproduct><![CDATA[' .$row['products_id']. ']]></urlproduct>
<urlpicture><![CDATA[' .rawurlencode($row['products_image']). ']]></urlpicture>
<description><![CDATA[' .html_clear_cat($row). ']]></description>
<category><![CDATA[' .$row['categories_name']. ']]></category>
<FullCategory>' . category_path($row) . '</FullCategory>
</product>
';
}
}
$rss.='
</catalog>';
$rss = mb_convert_encoding($rss, "UTF-8", "WINDOWS-1251");
echo $rss
?>

I saw this topic: http://www.oscommerce.com/forums/topic/391546-full-categories-path-in-xml-file/#entry1662453 and tryied to make my code work this way but I'm getting the following error:

<b>Fatal error</b>: Call to a member function reset() on a non-object in <b>my_file.php</b> on line <b>17</b><br />

The error line 17 is this: $breadcrumb_xml->reset();

 

Can somebody please point me out the problem or show me the right way how to solve this because I've been banging my head for nearly 4 hours without success?

Link to comment
Share on other sites

Hello,

please I am still having this problem and it is urgent for me to solve it. I know there are people in this forum that are very good programmers, which I am surely not, so please take a quick look at my code and give me some comment on it. I will really appreciate it! Thank you!

Link to comment
Share on other sites

I have tried to specify $breadcrumb_xml as a global to my category_path($row) function. It is still not working. Is the line that I should add this:

global $breadcrumb_xml;

Link to comment
Share on other sites

  • 2 weeks later...

Archived

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

×
×
  • Create New...