Moggen Posted October 7, 2010 Share Posted October 7, 2010 HiI have created module for displaying discount price based on third party api and I have created a custom hook in my module and in category.php. So far everything is good I can display test message any where I wont by moving my {hook} in the product-list template. Now my problem is that the hook i called once when category.php smarty assign is called but is there a way for my module to know witch product is displayed in the loop. Because I cant figure out how to calculate each product price based on the list witch is give by $params and some how assign correct price to the module template. Thanks for any help Link to comment Share on other sites More sharing options...
MrBaseball34 Posted October 7, 2010 Share Posted October 7, 2010 I'm interested in this, too as I will be writing a module to get real-time stock status and need to understand the hooks for something like this.Can you explain how you created your custom hook? Link to comment Share on other sites More sharing options...
Moggen Posted October 7, 2010 Author Share Posted October 7, 2010 Well the hook its self is realy easyI have in my install function something like this:simplefied not comleatfunction install() {if(!parren::install()){return false;}$db = Db::getInstance()$db->Execute("insert into ps_hook name title description position values myHook, title, desc, 1 ");if(!Hook:registerHook("myHook"){return false}return true}This will do 3 inserts first add my module in parrent::install (this must be done first to get id to hook register). Then I do a simple insert of my hook to ps_hook table. Last I execute registerHook this function will add myHook to module_hook and like the hook to this module.the I just create myHook function something like this function myHook($params) {}Then I add the Hook execute function in the assign to smart in category.php Link to comment Share on other sites More sharing options...
MrBaseball34 Posted October 7, 2010 Share Posted October 7, 2010 I'm not understanding this. Link to comment Share on other sites More sharing options...
Moggen Posted October 8, 2010 Author Share Posted October 8, 2010 Ok I think what I am trying to do is not possible with a hook but I will try to explain my code a bit moreMy modulemonthlycost class MonthlyCost extends Module { function __construct() { $this->name = 'monthlycost'; $this->tab = 'Payment'; $this->version = '0.1'; parent::__construct(); $this->displayName = $this->l('Monthly Cost'); $this->description = $this->l('Display monthly cost for part payment'); $this->confirmUninstall = $this->l('Are you sure you want to delete your module ?'); } function install() { if (!parent::install()) { return false; } $db = Db::getInstance(); $db->Execute( "INSERT INTO `ps_hook` (`name`, `title`, `description`) VALUES ('monthlyCost', 'Part payment', 'Part payment')" ); if (!$this->registerHook('monthlyCost')) { return false; } return true; } function uninstall() { $idHook = Hook::get( 'monthlyCost' ) ; $db = Db::getInstance(); $db->Execute(" DELETE FROM " . _DB_PREFIX_ . "hook WHERE id_hook = " . $idHook ); $this->unregisterHook( $idHook ); if( !parent::uninstall() ) { return false; } else { return true; } } public function hookMonthlyCost( $params ) { api calculations on price return $this->display(__FILE__, 'monthlycost.tpl'); } } and in category.php row 64 I have added following row:'HOOK_PART_PAYMENT' => Module::hookExec('monthlyCost',array("products" => $cat_products)),And in product-list.tpl{$HOOK_PART_PAYMENT}But the thing is that when i Exec monthlyCost i will return a html rendered by the template in the module.Then when the product-list.tpl loops $HOOK_PART_PAYMENTit will off course display the same price over and over again.So basically what I need is a way to execute the hook foreach row in the template and supply a id like.{EXEC_HOOK v=$product.id} or something like that. Link to comment Share on other sites More sharing options...
MrBaseball34 Posted October 8, 2010 Share Posted October 8, 2010 Cool, that was what I was looking for, thanks. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now