stopher Posted July 29, 2015 Share Posted July 29, 2015 Hi all, i have a problem with one of my modules, i can't update one object field value in the hook method, as you can see below public function hookActionValidateOrder($params){ $params['order']->customerRefOrder = $params['cart']->customerRefOrder; $params['order']->update(); } With this code, nothing is updated .However my variable "$params['cart']->customerRefOrder" contain a value.But the update method seem not to work in my case . Have you got any idea to help me to resolve my issue?Thank youCh. Link to comment Share on other sites More sharing options...
vekia Posted July 30, 2015 Share Posted July 30, 2015 you see some errors when you're trying to use this function ? Link to comment Share on other sites More sharing options...
stopher Posted July 30, 2015 Author Share Posted July 30, 2015 (edited) Hello thank you for your answer, no, no error . Note: i use v 1.6.0 I investigated this issue, and i remarked that the method "getFields()" in Object Model class not return my added fields in overridden class declaration. In fact my added fields disappear when i use the "update()" method in my Hook. To patch this problem i have to create a simple method in my overridden class ( see the code below ) class Order extends OrderCore{ public $customerRefOrder; public function __construct($id = null, $id_lang = null){ self::$definition['fields']['customerRefOrder'] = array('type' => self::TYPE_STRING); parent::__construct($id, $id_lang); } //My patch public function patchNewFields(){ $this->def['fields'] = array_merge($this->def['fields'], self::$definition['fields']); } } Now in my Hook method i call my method "patchNewFields", public function hookActionValidateOrder($params){ $params['order']->patchNewFields();//Patch $params['order']->customerRefOrder = $params['cart']->customerRefOrder; $params['order']->update(); } And it works but i don't think that is a normal situation. And to complete my investigation, i noticed different results depending on hook used. As exemple : public function hookActionValidateOrder($params){ $order - new Order(10); $order->customerRefOrder = "foo"; $order->update();//Not work } The code above not work ( no error ) public function hookDisplayAdminOrder($params){ $order - new Order(10); $order->customerRefOrder = "foo"; $order->update();//Works } The code above works fine public function hookActionObjectOrderAddAfter($params){ $order - new Order(10); $order->customerRefOrder = "foo"; $order->update();//Not work } The code above not work ( no error ) Edited July 30, 2015 by stopher (see edit history) 1 Link to comment Share on other sites More sharing options...
rafaurl Posted April 18, 2016 Share Posted April 18, 2016 thanks a million, I was crazy with same problem on hookActionValidateOrder. ps developers: A fix in core would be appreciated. Link to comment Share on other sites More sharing options...
stopher Posted April 18, 2016 Author Share Posted April 18, 2016 So you are trying to add a field dynamically to the object? How does the value get saved in the database? Did you add another column? I don't really follow what you are doing in the code. Not really , the new fields declared inside the constructor are not inside the result of getFields() method . 2 solutions : Call a "patch" method before update object . Copy all definition fields ( and add the new felds ) inside the overrided class, don't use a declaration inside the constructor. exemple This comportement is very strange, so i decided to use the second method by default. Now all works fine. Regards, Ch. Link to comment Share on other sites More sharing options...
stopher Posted April 18, 2016 Author Share Posted April 18, 2016 That is not a dynamic field.It's a standard field which exist in the database table. Link to comment Share on other sites More sharing options...
w3bsolutions Posted December 21, 2021 Share Posted December 21, 2021 On 7/30/2015 at 9:48 PM, stopher said: I investigated this issue, and i remarked that the method "getFields()" in Object Model class not return my added fields in overridden class declaration. In fact my added fields disappear when i use the "update()" method in my Hook. I just stumbled upon this issue (in PS 1.6.1.20) after losing so much time trying to figure out what was happening. Sad this was never fixed in PS 1.6 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