Jump to content

Fetch category tree for 1.7


Recommended Posts

I have a php-file that export the products into a csv-file.
When I us it on PS 1.6 it works fine, but when I use it on 1.7 the category tree doesn't get exported into the csv-file.

 

The section that export the category tree look like this:

		if ($default_cat == "on") {
			$item['cat_name'] = Tools::getPath($product->id_category_default, '');
		}
		elseif ($field['id_category'] > 0) {
			$item['cat_name'] = Tools::getPath($field['id_category'], '');
		}
		else {
			$category = new Category($product->id_category_default, intval($main_language));
			$item['cat_name'] = (isset($category->id) AND $category->id) ? Tools::getPath($category->id, '') : Tools::getPath($product->id_category_default, '');
		}
		$item['cat_name'] = trim(smfeed_html_to_text($item['cat_name']));

How can I adapt this to work with PS 1.7.0.4?

 

Thanks,
Fredrik

Link to comment
Share on other sites

 

Tools::getPath method changed signature in 1.7. It newly expects url_base as a first parameter. So try to replace all occurrences with something like:

Tools::getPath('', $product->id_category_default, '');

 

Thank you so much!

This did the trick. I'm sure this info will be useful in the future as well.

Link to comment
Share on other sites

  • 1 year later...

@DataKick This does not work for me in PS 1.7.4.0 beta.

This line: 

$path = Tools::getPath('', $this->category->id);

 

Generates the error:

(1/1) ContextErrorException

Notice: Trying to get property of non-object

in Tools.php (line 3997)
at ToolsCore::getPath('', 6)

 

Any ideas?  I could not find a way to get the base_url either. I am calling the function from a FrontOffice module that previously was working just fine in 1.6 . and 1.6 without the new base_url parameter.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...