Yuriy Posted November 7, 2017 Share Posted November 7, 2017 Hi, what function enables a Customer? It seems not AdminCustomersController.php processGuestToCustomer(), nor AdminCustomerPreferencesControllerCore updateOptionPsB2bEnable($value), checked overriden also. Used logging. PrestaShop™ 1.6.0.14 We need to add a php code at the point of enabling Customer. So, when a Customer becomes enabled, an http post request should go somewhere. In general, how to find a needed function? I'm new to php. Restart of server is undesired. Link to comment Share on other sites More sharing options...
cristic Posted November 8, 2017 Share Posted November 8, 2017 The function responsible for enabling/disabling a model (in this case Customer class) is AdminController::processStatus(). Link to comment Share on other sites More sharing options...
Yuriy Posted November 8, 2017 Author Share Posted November 8, 2017 4 hours ago, cristic said: The function responsible for enabling/disabling a model (in this case Customer class) is AdminController::processStatus(). Mmm... cristic, I can't detect the call of function classes\controller\AdminController::processStatus(). Tried to put inside the function: error_log, debug_backtrace, echo '<script>alert("Controller run()");</script>'; and print_r Exception trace - the ways I know, and nothing of this showed. Meanwhile, function of the same file AdminController::__construct() was called, ran. And CustomerCore::__construct() also seen. Maybe processStatus() was overriden? But no, here are all the files that contain text "processStatus()": AdminCategoriesController was not called. Also I tried another methods to find the function, but nothing. Miracles. Link to comment Share on other sites More sharing options...
bellini13 Posted November 8, 2017 Share Posted November 8, 2017 You want to try and find a hook that is executed upon the change of customer status. If we start with AdminController processStatus function. We see that it uses the following code when the status of any object is changed (in this case the customer object) if ($object->toggleStatus()) So if we open the Customer class now, and search for toggleStatus we see that it calls the parent toggleStatus parent::toggleStatus(); The parent class is ObjectModel, so we search for toggleStatus in ObjectModel and find that it changes the active variable of the object, and then calls the update function // Update active status on object $this->active = !(int)$this->active; // Change status to active/inactive return $this->update(false); So then we locate the update function, first in the customer class and then in the objectmodule class. Nothing really going on in the customer class, certainly no hooks have been found yet. However we find update in the ObjectModel and we see hooks being executed // @hook actionObject*UpdateBefore Hook::exec('actionObjectUpdateBefore', array('object' => $this)); Hook::exec('actionObject'.get_class($this).'UpdateBefore', array('object' => $this)); .... // @hook actionObject*UpdateAfter Hook::exec('actionObjectUpdateAfter', array('object' => $this)); Hook::exec('actionObject'.get_class($this).'UpdateAfter', array('object' => $this)); That is how you trace code to find what you are looking for So now that we know there are hooks that can be used to detect the change in status, now you need to create a module that will register one of these hooks, and react to it. Now You might find it difficult to figure out what exactly was changed, and if that is the case, then perhaps hooks will not work for you, and instead you might consider creating an override of the Customer class, and extending the toggleStatus function. Link to comment Share on other sites More sharing options...
Yuriy Posted November 8, 2017 Author Share Posted November 8, 2017 1 hour ago, bellini13 said: creating an override of the Customer class, and extending the toggleStatus function Thank God for your reply, bellini13 Alright, I tried. public_html//override/classes/Customer.php already existed, just added: public function toggleStatus() { parent::toggleStatus(); ini_set("log_errors", 1); ini_set("error_log", "log.log"); error_log("Customer toggleStatus()"); } And that's strange: no "toggleStatus" in log. At the same time AdminController::__construct() and CustomerCore::__construct() appear in log. Of course I tried to log outside parent public_html//classes/Customer.php - just for test - and no result also. That's the problem: the functions that should be called seem to be not. But system is working well since 2015. And customers become enabled/disabled. Why the functions don't print in log? and debug_backtrace, js popup, print_r Exception don't act too. Not understood where the functions that do logic dwell then. Directories in public_html: Link to comment Share on other sites More sharing options...
Yuriy Posted November 9, 2017 Author Share Posted November 9, 2017 (edited) Dear community, the issue is not new. Similar topics (still not solved): 473073-need-to-implement-a-custom-build-feature-but-stuck-once-again 484762-further-action-during-status-update-activeinactive 279295-send-email-to-user-after-activation-in-bo-14x 269483-admin-action-sur-un-champs-bool-dans-liste-product-comme-statut 182152-what-hook-gets-executed-on-customer-enable - not confirmed as solution. The same I tried with no success. A strange issue: functions that are supposed to act just don't act. I'm thinking of upgrading Prestashop because these issues stop appearing after 2015. But update is additional headache, undesired now... Edited November 9, 2017 by Yuriy (see edit history) Link to comment Share on other sites More sharing options...
bellini13 Posted November 10, 2017 Share Posted November 10, 2017 add your debugging code directly to the toggleStatus function in the core Customer class and then to the ObjectModel class just to see if those core functions are being called. That will help rule out if this is an override issue, or just an issue in that the expected functions are not being called. Link to comment Share on other sites More sharing options...
Yuriy Posted November 10, 2017 Author Share Posted November 10, 2017 (edited) Added already. classes/Customer.php - no effect in log: public function toggleStatus() { ini_set("log_errors", 1); ini_set("error_log", "log.log"); error_log("CustomerCore toggleStatus() begin"); parent::toggleStatus(); error_log("CustomerCore toggleStatus() 1"); /* Change status to active/inactive */ return Db::getInstance()->execute(' UPDATE `'._DB_PREFIX_.bqSQL($this->def['table']).'` SET `date_upd` = NOW() WHERE `'.bqSQL($this->def['primary']).'` = '.(int)$this->id); try { ............ classes/ObjectModel.php - no effect: public function toggleStatus() { ini_set("log_errors", 1); ini_set("error_log", "log.log"); error_log("ObjectModel toggleStatus() begin"); echo "ObjectModel toggleStatus()"; echo '<script>alert("ObjectModel toggleStatus()");</script>'; // Object must have a variable called 'active' if (!array_key_exists('active', $this)) throw new PrestaShopException('property "active" is missing in object '.get_class($this)); // Update only active field $this->setFieldsToUpdate(array('active' => true)); // Update active status on object $this->active = !(int)$this->active; // Change status to active/inactive return $this->update(false); } But! classes/Customer.php constructor is shown in log. I even tried to insert http request code into the constructor - it launches successfully. public function __construct($id = null) { $this->id_default_group = (int)Configuration::get('PS_CUSTOMER_GROUP'); parent::__construct($id); ini_set("log_errors", 1); ini_set("error_log", "log.log"); error_log("CustomerCore __construct end"); } Now these are all the files in the whole public_html dir, that contain "toggleStatus": What to say more? It's interesting issue Prestashop welcomes me hardly. I guess that answer is somewhere near, maybe very simple... Edited November 10, 2017 by Yuriy (see edit history) Link to comment Share on other sites More sharing options...
bellini13 Posted November 11, 2017 Share Posted November 11, 2017 Well you need to trace through the CustomerController and the AdminController then to see what function is called upon the change of the active variable of a customer. Link to comment Share on other sites More sharing options...
Yuriy Posted November 15, 2017 Author Share Posted November 15, 2017 (edited) Good news. I found the place in code: override/controllers/admin/AdminCustomersController.php::processChangeStatusVal(). It was obvious from the begining, still don't know why it didn't show any logging and debug popups, or echos. But it sends http POST fine. Thank God for all the generous help by people here. So the main caveat was impossibility of detecting the function run because logging/debug popups/echos didn't show up. SOLVED Edited November 15, 2017 by Yuriy (see edit history) 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