Author Topic: move $this->extensions->hk_UpdateData($this, __FUNCTION__);  (Read 11172 times)

yonghan

  • Guest
move $this->extensions->hk_UpdateData($this, __FUNCTION__);
« 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.

Offline abolabo

  • core-developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 2046
  • Karma: +318/-13
  • web for all, all for web!
    • View Profile
    • AbanteCart
Re: move $this->extensions->hk_UpdateData($this, __FUNCTION__);
« Reply #1 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.






“No one is useless in this world who lightens the burdens of another.”
― Charles Dickens

yonghan

  • Guest
Re: move $this->extensions->hk_UpdateData($this, __FUNCTION__);
« Reply #2 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?

Offline abolabo

  • core-developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 2046
  • Karma: +318/-13
  • web for all, all for web!
    • View Profile
    • AbanteCart
Re: move $this->extensions->hk_UpdateData($this, __FUNCTION__);
« Reply #3 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
“No one is useless in this world who lightens the burdens of another.”
― Charles Dickens

yonghan

  • Guest
Re: move $this->extensions->hk_UpdateData($this, __FUNCTION__);
« Reply #4 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.

Offline abolabo

  • core-developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 2046
  • Karma: +318/-13
  • web for all, all for web!
    • View Profile
    • AbanteCart
Re: move $this->extensions->hk_UpdateData($this, __FUNCTION__);
« Reply #5 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 :)
“No one is useless in this world who lightens the burdens of another.”
― Charles Dickens

yonghan

  • Guest
Re: move $this->extensions->hk_UpdateData($this, __FUNCTION__);
« Reply #6 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.

Offline abantecart

  • Administrator
  • Hero Member
  • *****
  • Posts: 4358
  • Karma: +298/-10
    • View Profile
    • Ideal Open Source Ecommerce Solution
Re: move $this->extensions->hk_UpdateData($this, __FUNCTION__);
« Reply #7 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?
« Last Edit: December 08, 2015, 03:06:34 PM by abantecart »
Please  rate your experience or leave your review
We need your help to build better free open source ecommerce platform for everyone. See how you can help

Offline abolabo

  • core-developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 2046
  • Karma: +318/-13
  • web for all, all for web!
    • View Profile
    • AbanteCart
Re: move $this->extensions->hk_UpdateData($this, __FUNCTION__);
« Reply #8 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?
“No one is useless in this world who lightens the burdens of another.”
― Charles Dickens

yonghan

  • Guest
Re: move $this->extensions->hk_UpdateData($this, __FUNCTION__);
« Reply #9 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.

Offline abolabo

  • core-developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 2046
  • Karma: +318/-13
  • web for all, all for web!
    • View Profile
    • AbanteCart
Re: move $this->extensions->hk_UpdateData($this, __FUNCTION__);
« Reply #10 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.
“No one is useless in this world who lightens the burdens of another.”
― Charles Dickens

yonghan

  • Guest
Re: move $this->extensions->hk_UpdateData($this, __FUNCTION__);
« Reply #11 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.

Offline abolabo

  • core-developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 2046
  • Karma: +318/-13
  • web for all, all for web!
    • View Profile
    • AbanteCart
Re: move $this->extensions->hk_UpdateData($this, __FUNCTION__);
« Reply #12 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.
“No one is useless in this world who lightens the burdens of another.”
― Charles Dickens

yonghan

  • Guest
Re: move $this->extensions->hk_UpdateData($this, __FUNCTION__);
« Reply #13 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.

Offline abolabo

  • core-developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 2046
  • Karma: +318/-13
  • web for all, all for web!
    • View Profile
    • AbanteCart
Re: move $this->extensions->hk_UpdateData($this, __FUNCTION__);
« Reply #14 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)
“No one is useless in this world who lightens the burdens of another.”
― Charles Dickens

 

Powered by SMFPacks Social Login Mod