Jump to content

Adding a new php function - method: getCategoryName [SOLVED]


dr7tbien

Recommended Posts

Hello.

I'd like to insert a new php function - method called getCategoryName.

This is the function:

public function getCategoryName( $id_category ){
  $idLang = Context::getContext()->language->id;
  $categoryObject = $this->getCategoryObject($id_category, $idLang);
  return $categoryObject->name;
}

It happens that I don't know where to place it properly. I've actually placed it at the end of the classes/Link.php file. I think it is a mistake since it is part of the prestashop core and this method should be overridden.

Where should this method be overridden?

Edited by dr7tbien (see edit history)
Link to comment
Share on other sites

Add the function to /override/classes/Link.php

If that file doesn't exist yet, just create it exactly as follows:

<?php

class Link extends LinkCore {

    public function getCategoryName( $id_category ){
        $idLang = Context::getContext()->language->id;
        $categoryObject = $this->getCategoryObject($id_category, $idLang);
        return $categoryObject->name;
    }
    
}

Also, if you need to create the override file, you'll need to regenerate the class index.

To do that, just delete /var/cache/prod/class_index.php and /var/cache/dev/class_index.php

Edited by lordignus
Mistake (see edit history)
  • Like 1
Link to comment
Share on other sites

  • dr7tbien changed the title to Adding a new php function - method: getCategoryName [SOLVED]
2 hours ago, lordignus said:

Add the function to /override/classes/Link.php

If that file doesn't exist yet, just create it exactly as follows:

<?php

class Link extends LinkCore {

    public function getCategoryName( $id_category ){
        $idLang = Context::getContext()->language->id;
        $categoryObject = $this->getCategoryObject($id_category, $idLang);
        return $categoryObject->name;
    }
    
}

Also, if you need to create the override file, you'll need to regenerate the class index.

To do that, just delete /var/cache/prod/class_index.php and /var/cache/dev/class_index.php

Many thanks.

Really I should start reading something about module development in prestashop. I'm doing it all by coding reverse  and reading specific cases like this.

Thanks again

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