Jump to content

Override method in Class, Controller?


Recommended Posts

Hi all,

I wanna modify Class but I don't wanna touch Original File. So I choose way write a file located at folder "Override".

Example, I wanna override Class ProductDownload.php, I create a file ProductDownload.php in folder "Override/classes" and content below...

<?php


class ProductDownload extends ProductDownloadCore
{
    public static function getIdFromIdProduct($id_product)
	{
		if (!ProductDownload::isFeatureActive())
			return false;
		if (array_key_exists((int)$id_product, self::$_productIds))
			return self::$_productIds[$id_product];
		$sql = '
		SELECT `id_product_download`
		FROM `'._DB_PREFIX_.'product_download`
		WHERE `id_product` = '.(int)$id_product.' 
		AND `active` = 1
        ';
        $res = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);        
        foreach($res as $re){
            self::$_productIds[$id_product][] = $re;
                            
        }
		return self::$_productIds[$id_product];        
	}
}
?>

But my ProductDownload.php code is like above, not change. Can anyone help me, is there any other additional steps needed to override?

Link to comment
Share on other sites

when manually installing an override you must then delete cache/class_index.php

 

then it will recognize your override

 

OH! I got it! Thanks so much! And now i want to override file tpl. Not .tpl of module. Just .tpl example: virtualproduct.tpl or orderdetail.tpl Can you help me. Thanks U very much!

Link to comment
Share on other sites

Maybe I wrong...

 

 

Overriding other behaviors

PrestaShop has certain files you can use to override elements such as displaying redirections (Tools.php) and measuring hook execution time (_Module.php), etc. you can enable them by removing the "_" prefix. For instance, rename _Tools.php into Tools.php. If there already exists aTools.php override, you will have to merge it with yours.

It not say about .tpl files... 

Anybody help me?

Link to comment
Share on other sites

×
×
  • Create New...