Jump to content

Which files are responsible for inserting new rows to `ps_orders`?


Amazzing

Recommended Posts

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

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.

  • Like 2
Link to comment
Share on other sites

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

  • 6 months later...
  • 1 year later...

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 by awdhesh (see edit history)
Link to comment
Share on other sites

  • 3 years later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...