Jump to content

How to get image URL of categories (PHP)?


MFLM

Recommended Posts

Hi all

 

I'm new of Prestashop, and I need your help.

 

I have PHP code with  a foreach to get the ID and the NAME of CATEGORIES: 


	foreach($categories as $cat)
	{
		foreach($cat as $c)
		{
      
			$row = array();
			$categorie = New Category($c["infos"]["id_category"]); 
			$row['id_category']=$c["infos"]["id_category"];
			$row['titre']=$c["infos"]["name"];	
			
			
		foreach ($row as $key => $value) {
			if ($value == NULL) {
				$row[$key]='';
			}
		}
		$resultat[]=$row;
		}
		
		
	}

all is good here, but now I need to get the image URL for every category, I wrote this:

                        $id_category = $c["infos"]["id_category"];
			$image = Image::getCover($id_category);
			$link = new Link;
			$row['link'] = $link->getImageLink($categories->link_rewrite, $image['id_image'], 'home_default');
	

but the URL is bad, because is the image of PRODUCTS, and I need the image of CATEGORIES.

 

What am I doing wrong?
 
Thanks for your time
Link to comment
Share on other sites

Image::getCover states that it is for Products.  Infact I believe the entire Image class is only applicable to Products

    /**
     *Get product cover
     *
     * @param int $id_product Product ID
     * @return bool result
     */
    public static function getCover($id_product)

Would you use this function of Link instead?   

public function getCatImageLink($name, $id_category, $type = null)

The function is used in category.tpl, but this should give you an idea of what to do in php

$link->getCatImageLink($category->link_rewrite, $category->id_image, 'category_default')
Link to comment
Share on other sites

 

Image::getCover states that it is for Products.  Infact I believe the entire Image class is only applicable to Products

    /**
     *Get product cover
     *
     * @param int $id_product Product ID
     * @return bool result
     */
    public static function getCover($id_product)

Would you use this function of Link instead?   

public function getCatImageLink($name, $id_category, $type = null)

The function is used in category.tpl, but this should give you an idea of what to do in php

$link->getCatImageLink($category->link_rewrite, $category->id_image, 'category_default')

Thanks my friend, this works perfectly 

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...