Jump to content

override class and call functions


Recommended Posts

Hi guys, I override the Product.php class in Prestashop 1.6

 My file looks like this in mymodule/override/classes/Product.php

class Product extends ProductCore{

  public function getProductByTag($id_tags)
  {

    $list_product = [];
    $product_list = (Db::getInstance()->execute('
      SELECT pt.`id_product`
      FROM `'._DB_PREFIX_.'product_tag` pt
      WHERE cp.`id_tag` = '.(int)$id_tags.'')
    ); 

    foreach ($product_list as $product) {
      $item_product = (Db::getInstance()->execute('
        SELECT pl.`name`
        FROM `'._DB_PREFIX_.'product_lang` pl
        WHERE cp.`id_product` = '.(int)$product.'')
      ); 
      array_push($list_product, $item_product);
    }
    return $list_product;
  }



  public static function getAllTags(){
    $sql = 'SELECT  `name` FROM `'._DB_PREFIX_.'tag`';
    $productTags = Db::getInstance()->ExecuteS($sql);
    return  $nameTag;
  }

  public static function test(){
    return "testing";
  }


}

 

Now I what to use this function in my own module, I try this

$productTags = Product::test(); 

 But I received this error,

 

Call to undefined method Product::test()

 

any idea  what I am missing

 

Thanks in advances!

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

I fix the problem... when we develop a module in prestashop first we create and install, after that we'll include the functionality.

 

If our module use class and controller we have to override it, so we put inside the override file into the our module  new class and controller and when we call them don't work.

 

The solution is put the same file in the main override folder too.

 

When prestashop install the module do the same. The problem is that we create this file before install.

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