SG Informatica Posted March 29, 2013 Share Posted March 29, 2013 (edited) Hi I created a new field in the database called applied. I show in the back office modifying _product_line.tpl but needs to be updated in the database, what function is responsible of updating the line. I need perform as quantity. Thanks for your replies Edited April 1, 2013 by sginfoocio (see edit history) Link to comment Share on other sites More sharing options...
axelmdp Posted March 29, 2013 Share Posted March 29, 2013 On 3/29/2013 at 12:30 PM, sginfoocio said: Hi I created a new field in the database called applied. I show in the back office modifying _product_line.tpl but needs to be updated in the database, what function is responsible of updating the line. I need perform as quantity. Thanks for your replies Hello sginfoocio. I'd suggest you that you try to do it implementing a module, whenever is possible. However, we know that it's not always possible. Analysing your situation, I infered that you are using PS 1.5.x (because _product_line.tpl is not present on PS 1.4), and also that you are talking about Order Edit within Order Details on BO. It is important that you add this information on your post in order to put in context to all users that are willing to help you. Assuming that, I followed the code, and when the user press the Update button, there is a Javascript function that is reached (if you want to trace it, look into admin_order.js, on line 651 approx at "$('input[name=submitProductChange]').click(function() {"). If you added the "applied" field to be editable and it is a visible input or select, you won't need to modify nothing on this javascript function, because the function will include it (this is regarding edit an order line) However, when the user adds a new order detail, the procedure is different, and maybe you will have to modify the JS funtion in order to include your new field (look near line 425, "$('#submitAddProduct').click(function(e) {"; the url params are built using id instead element selectors) After that, and after the ajax invocation to the AdminOrdersController.php file, the methods finally reached are these three (depending on the action that the user has performed): ajaxProcessAddProductOnOrder ajaxProcessEditProductOnOrder ajaxProcessDeleteProductLine Please notice that all these three methods ends with a "die" php sentence, so when you include your saving functionality, you won't be able to do nothing after the methods finish. You must do it before. I'm not sure if it is the best approach, but I'd suggest you to override the sendChangedNotification method, that is is called just before the die sentence from all the three methods. My suggestion is based on keeping the override functionality to the minimum (if not zero) and I wouldn't suggest the approach of overriding the three methods, because inside of each one there are some validations that could prevent the proper processing. When the sendChangedNotification method is called, every validation was properly passed and there weren't errors, so there is a good point for you to add your add/update/delete functionality. You could do something like this on override/controllers/admin/AdminOrdersController.php: public function sendChangedNotification(Order $order = null) { //calling to the parent method parent::sendChangedNotification($order); //Your code here: $action = Tools::getValue('action'); if($action == 'addProductOnOrder') { //Add the value of your field $applied = Tools::getValue('applied'); $product_id = $_POST['add_product']['product_id']; //... } else if($action == 'editProductOnOrder') { //Update your field value $product_id_order_detail = Tools::getValue('product_id_order_detail'); $applied = Tools::getValue('applied'); //... } else if($action == 'delete_product_line') { //Delete your field $id_order_detail = Tools::getValue('id_order_detail'); //... } } I hope this will help you I look forward for your comments. Kind Regards, Axel ------------------ Check this cool modules (must have) : LoginAsCustomer for PS1.5 Cart Details 1 Link to comment Share on other sites More sharing options...
SG Informatica Posted March 31, 2013 Author Share Posted March 31, 2013 I think I have not understood, I need a field called applied, used from the backoffice in OrderDetails to put the amount already used for each order line, buy 5 used 4 My steps are as follows: Create the field in the database Modify _product_line.tpl view.tpl and to show the new value and allow modify when you press edit. Quote Assuming that, I followed the code, and when the user press the Update button, there is a Javascript function that is reached (if you want to trace it, look into admin_order.js, on line 651 approx at "$('input[name=submitProductChange]').click(function() {"). If you added the "applied" field to be editable and it is a visible input or select, you won't need to modify nothing on this javascript function, because the function will include it (this is regarding edit an order line) I understand that I have nothing to change in admin_order.js, becouse i added "applied" as editable?¿but when change it the value is not updated in the database. which performs the function?? ajaxProcessEditProductOnOrder? I do several tests but can´t update the value. Thank you very much for your response and patience Link to comment Share on other sites More sharing options...
axelmdp Posted March 31, 2013 Share Posted March 31, 2013 On 3/31/2013 at 12:47 PM, sginfoocio said: I think I have not understood, I need a field called applied, used from the backoffice in OrderDetails to put the amount already used for each order line, buy 5 used 4 My steps are as follows: Create the field in the database Modify _product_line.tpl view.tpl and to show the new value and allow modify when you press edit. I understand that I have nothing to change in admin_order.js, becouse i added "applied" as editable?¿but when change it the value is not updated in the database. which performs the function?? ajaxProcessEditProductOnOrder? I do several tests but can´t update the value. Thank you very much for your response and patience Hello sginfoocio. Since you have added a new field, this is not automatically updated on prestashop. So, you have to add code in order to process it. I tried to guide you through this process. Please take a look to the code that I've put on post #2. You should use that code as base. However, it is incomplete, because I don't know where have you added the new field, and I'm not sure if the name of the input field that you use for editing is "applied". Also, please have in mind that there are three actions that the user is allowed to do with any order detail: add, edit and delete. That's why I've added the "if" for processing. Inside each block, you will be sure about what action is beeing performed. So you will have to add the code for updating/adding or delete any row with the proper value. For example, if you've added the new field on the same table "ps_order_detail", you could add this line inside the "if" block if($action == 'editProductOnOrder') : Db::getInstance()->Execute( 'UPDATE `'._DB_PREFIX_.'order_detail` SET `applied` = '.(int)$applied. ' WHERE `id_order_detail` = '.(int)$product_id_order_detail ); Regarding to change the admin_order.js file, I think you would have to change it. On my post #2 I mean you won't have to change the EDIT function, but I think you will have to change the ADD function (the function associated to "submitAddProduct" button), because it doesn't consider new fields in a general way. I hope this would be helpful for you. Best Regards, Axel 1 Link to comment Share on other sites More sharing options...
SG Informatica Posted April 1, 2013 Author Share Posted April 1, 2013 Hello again, Thanks for your answer helped me to understand the operation of the orders. My fault was the update of field I thought it was responsible of objectmodel.php from the call // Save order detail $res &= $order_detail->update(); Previously assigning $product_aplicado = Tools::getValue('product_aplicado'); $order_detail->product_aplicado = $product_aplicado; Thanks for everything. Link to comment Share on other sites More sharing options...
axelmdp Posted April 1, 2013 Share Posted April 1, 2013 (edited) Great sgnifoocio. I'm glad I could help you. So, if it is solved, you can edit your first post and add the "[sOLVED]" suffix for a better understanding. Thank you and regards, Axel ------------------ Check this cool modules (must have) : LoginAsCustomer for PS1.5 Cart Details MultiTabsForProducts Edited April 3, 2013 by axelmdp (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts