Amazzing Posted October 10, 2013 Share Posted October 10, 2013 Hello, I have created an additional field in the shopping cart. Its value is defined in classes/Cart.php (I'll do an override when the modification is complete). I have managed to display this value in shopping-cart.tpl and it works just fine. But I can't find a way to save this value to database together with other fields, when order is complete. I have created a new column in `ps_orders`, so I just need to find a correct file that inserts such data as 'total_wrapping', 'total_products' etc and add my new value there. I spent some time trying to find the place, where these datas are inserted, but the order code is more complex that I thought it would be It looks like there are some additional functions involved in inserting new rows. May be I have missed something obvious, but anyway, I would appreciate if somebody showed me, what is the best way to add a new field value to DB, when the order is complete. Link to comment Share on other sites More sharing options...
bellini13 Posted October 10, 2013 Share Posted October 10, 2013 PaymentModule class Link to comment Share on other sites More sharing options...
Amazzing Posted October 10, 2013 Author Share Posted October 10, 2013 PaymentModule class Thanks, bellini, This is the right file, but it is not the only one. In order to save my new value in the same way as others are saved, I had to make some additional modifications to classes/order/Order.php First of all I had to declare a public variable in order.php public $my_variable; Then I had to add this to $definition array: 'my_variable' => array('type' => self::TYPE_FLOAT, 'validate' => 'validationmethod'), And in PaymentModule class I had to add the following code in foreach ($packageByAddress as $id_package => $package): $order->my_variable = value of the variable; So after that my value is saved in database when order is complete. It works for me, and looks just fine. The only drawback I see now is that this code has to be modified manually each time I update Prestashop. However, if you see any other drawbacks or pitfalls here, please point it out. 2 Link to comment Share on other sites More sharing options...
bellini13 Posted October 10, 2013 Share Posted October 10, 2013 you should extend the Order class using overrides, and not altering the core class file. This was just referenced in a separate thread, and will explain how to accomplish http://nemops.com/extending-prestashop-objects/ 1 Link to comment Share on other sites More sharing options...
Amazzing Posted October 13, 2013 Author Share Posted October 13, 2013 (edited) Thanks for the advice. I did all those modifications using override technique Edited October 13, 2013 by Amazzing (see edit history) Link to comment Share on other sites More sharing options...
gonebdg - webindoshop.com Posted October 14, 2013 Share Posted October 14, 2013 I think the best way to achive modification like this is by creating custom DB table, don't modified the default DB table structure. And then your custom variable can be reffered to id_product or id_order or or anything else depend on your need. You can use the available MODULE HOOK to insert your custom variable. This way you don't have to modify the core file each time prestashop being updated. Link to comment Share on other sites More sharing options...
sarfaraz.r1406 Posted April 29, 2014 Share Posted April 29, 2014 Hi, I have the same problem. I have created a new module and want my variable to reach order.php class from my modules' tpl file. Can you tell me whether I should override PaymentModule.php or Order.php to acheive this. Link to comment Share on other sites More sharing options...
awdhesh Posted June 5, 2015 Share Posted June 5, 2015 (edited) i have same problem as a above question but i created a custom module and hook that page where gift wrap option is available and want to insert value in my new field in database i m very frustred because i have spent 6 to 8 hour but i did not get any solution anybody please help me... Edited June 5, 2015 by awdhesh (see edit history) Link to comment Share on other sites More sharing options...
Todor Inchovski Posted January 7, 2019 Share Posted January 7, 2019 What is the equivalent of this in Prestashop 1.7.4.4? Or how can this be done in Prestashop 1.7.4.4? 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