Do you like AbanteCart? Please rate AbanteCart or share your experience with other eCommerce entrepreneurs. Go to Softaculous rating page to add your rating or write a review

move $this->extensions->hk_UpdateData($this, __FUNCTION__);

Started by yonghan, December 06, 2015, 07:23:32 AM

Previous topic - Next topic

yonghan

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.

abolabo

You do not need to move calls.

Just try to paste this inside your updateData hook

$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

Thanks abolabo. What if i want to change existing code and not the data's within the function?

abolabo

Quote from: handoyo 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?

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

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.

abolabo

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

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.

abantecart

#7
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?
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

abolabo

Quote from: handoyo 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.

what core controller do you mean?
"No one is useless in this world who lightens the burdens of another."
― Charles Dickens

yonghan

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: Fatal error: Call to a member function isLogged() on null in C:\xampp\htdocs\testing\t125\storefront\model\catalog\product.php on line 1149.

abolabo

Quote from: handoyo 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: 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

Yes Abolabo, I get that error on admin side. I didn't hook or use is logged in function.

abolabo

Quote from: handoyo on December 10, 2015, 07:58:12 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

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.

abolabo

Quote from: handoyo 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.

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

Forum Rules Code of conduct
AbanteCart.com 2010 -