AbanteCart Community

AbanteCart Development => New Features Discussion => Topic started by: yonghan on December 06, 2015, 07:23:32 AM

Title: move $this->extensions->hk_UpdateData($this, __FUNCTION__);
Post by: yonghan on December 06, 2015, 07:23:32 AM
Hi, admins, I would like to request to move $this->extensions->hk_UpdateData($this, __FUNCTION__); above the processTemplate so the hook can be called before processTemplate or other functions. Thanks.
Title: Re: move $this->extensions->hk_UpdateData($this, __FUNCTION__);
Post by: abolabo on December 08, 2015, 07:55:23 AM
You do not need to move calls.

Just try to paste this inside your updateData hook

Code: [Select]
$var = $this->baseObject->view->getData('some_tpl_var_name');
$var .= 'hello world!';
$this->baseObject->view->assign('some_tpl_var_name', $var);

and you will see that you can change any variable inside your tpl.






Title: Re: move $this->extensions->hk_UpdateData($this, __FUNCTION__);
Post by: yonghan on December 08, 2015, 08:29:36 AM
Thanks abolabo. What if i want to change existing code and not the data's within the function?
Title: Re: move $this->extensions->hk_UpdateData($this, __FUNCTION__);
Post by: abolabo on December 08, 2015, 11:14:03 AM
Thanks abolabo. What if i want to change existing code and not the data's within the function?

you should not to change core code. it's a bad practice.
Just create your custom hook vars and add it into tpl.. Please read our docs about it.
http://docs.abantecart.com/pages/developer/template_customization_or_development_guide.html
Title: Re: move $this->extensions->hk_UpdateData($this, __FUNCTION__);
Post by: yonghan on December 08, 2015, 11:34:14 AM
Thanks, I understand it is a bad practice. It just in some situation the hook vars itself is not sufficient. And actually not replacinf the core code, But adding some more routines to it.
Title: Re: move $this->extensions->hk_UpdateData($this, __FUNCTION__);
Post by: abolabo on December 08, 2015, 11:44:27 AM
ic. also do not forget about core upgrades. To change code via hooks more safely because all code placed in your custom extension directory.
If you do  not plan upgrade core - you can do anything you want :)
Title: Re: move $this->extensions->hk_UpdateData($this, __FUNCTION__);
Post by: yonghan on December 08, 2015, 12:06:37 PM
I do remember that, and that's why i asked abantecart to consider by adding hooks within the ValidateData function and on other hooks which i request it in my other post.
Title: Re: move $this->extensions->hk_UpdateData($this, __FUNCTION__);
Post by: abantecart on December 08, 2015, 02:13:26 PM
You can implement your own controller and  completely replace the data in main controller with your hook.
Can you give an example of the code you need to change?
Title: Re: move $this->extensions->hk_UpdateData($this, __FUNCTION__);
Post by: abolabo on December 09, 2015, 07:20:20 AM
I do remember that, and that's why i asked abantecart to consider by adding hooks within the ValidateData function and on other hooks which i request it in my other post.

what core controller do you mean?
Title: Re: move $this->extensions->hk_UpdateData($this, __FUNCTION__);
Post by: yonghan on December 09, 2015, 08:03:42 PM
Hi abantecart and abolabo. I was trying to change the code in pages/sale/order/recalc. I'm trying to use custom order manager lib. I tried using hook init data, it works in ab v1.2.2 but not in 1.2.3-1.2.5. it gives me error:
Code: [Select]
Fatal error: Call to a member function isLogged() on null in C:\xampp\htdocs\testing\t125\storefront\model\catalog\product.php on line 1149.
Title: Re: move $this->extensions->hk_UpdateData($this, __FUNCTION__);
Post by: abolabo on December 10, 2015, 06:47:29 AM
Hi abantecart and abolabo. I was trying to change the code in pages/sale/order/recalc. I'm trying to use custom order manager lib. I tried using hook init data, it works in ab v1.2.2 but not in 1.2.3-1.2.5. it gives me error:
Code: [Select]
Fatal error: Call to a member function isLogged() on null in C:\xampp\htdocs\testing\t125\storefront\model\catalog\product.php on line 1149.

i guess you got this error on admin side. Add check for admin (i mean if(IS_ADMIN!==true)) before isLogged() func call.
Abantecart have two models with rt catalog/product, on admin and sf.
Title: Re: move $this->extensions->hk_UpdateData($this, __FUNCTION__);
Post by: yonghan on December 10, 2015, 07:58:12 AM
Yes Abolabo, I get that error on admin side. I didn't hook or use is logged in function.
Title: Re: move $this->extensions->hk_UpdateData($this, __FUNCTION__);
Post by: abolabo on December 10, 2015, 08:09:02 AM
I didn't hook or use is logged in function.
it's a model rt collision.
Your error is in $this->customer->isLogged() call but $this->customer object not exists for admin side. Check your hooks.
Title: Re: move $this->extensions->hk_UpdateData($this, __FUNCTION__);
Post by: yonghan on December 10, 2015, 09:32:29 AM
Thanks abolabo, I will check it. Btw is it correct to use the extended orderanager lib im initdata instead of updateData? If I use it in updateData I didn't get the error message.
Title: Re: move $this->extensions->hk_UpdateData($this, __FUNCTION__);
Post by: abolabo on December 10, 2015, 11:43:11 AM
Thanks abolabo, I will check it. Btw is it correct to use the extended orderanager lib im initdata instead of updateData? If I use it in updateData I didn't get the error message.

it depends on data process. Usually you send some data with POST request and core controller validate and save it. If data is valid - page send redirect to the this controller but as GET request. _UpdateData will no call in that case. If you want to validate data the best way do this inside InitData.. ( or validateData if you can)
Title: Re: move $this->extensions->hk_UpdateData($this, __FUNCTION__);
Post by: yonghan on December 10, 2015, 06:40:48 PM
Hi abolabo, I suppose validateData is usable if there is as hk_validateData function within the controller, isn't it?
Title: Re: move $this->extensions->hk_UpdateData($this, __FUNCTION__);
Post by: abolabo on December 11, 2015, 08:11:47 AM
yes. but it can be also in models too.
we plan to add more calls in our models.
Title: Re: move $this->extensions->hk_UpdateData($this, __FUNCTION__);
Post by: yonghan on December 11, 2015, 08:26:23 AM
That would be great. Please consider to add in the customer account, address model and admin add customer account, address model too.