Jump to content

How to add a new field to the order table


Diachronic

Recommended Posts

Hello

 

 

I want to ask, in case i have added a new field in the order table in the Database,

and it want to do the following --> 

I have a drop down in an custom cms page(its a payment selection screen which the customer will be redirected upon completing the checkout registration process), this drop down will contains a list of options.

Upon selecting an item in the drop down , i want to save the value in the newly added field in the order table , for the current order

 

How to modify the code in my website in order, to been able to access the newly added field and set it values in the created order using the context.

knowing that the user will select this value before saving the order 

Link to comment
Share on other sites

The problem you face is that the order object isn't created until after the payment is made. You may have to store the data in the cart object instead. You do have access to that cart object from the order when it finally IS created though.

 

You can access the current cart object from the context during the form submission handling though very easily (on the plus side).

 

EDIT: To add the field "properly" you should also override the Cart class and add your variable e.g.

class Cart extends CartCore
{
  public $my_var;

  $definition['fields']['my_var'] = array('type' => self::TYPE_STRING);

}

I haven't got the source to hand to check the syntax but I'm pretty sure that above is the form that the definition takes. Obviously you need to adjust to suit your variable type and add any necessary constraints, as required. Also remember to clear the object cache otherwise your override won't take effect (i.e. delete ./cache/class_index.php).

Edited by Paul C (see edit history)
Link to comment
Share on other sites

Hello

 

 

Thank you Paul C for your support

 

I have modified my order table in db and the order class and it worked fine(i've test it with static values upon saving the order)

but know i want to store the selected value(from the select options) in order to retrieve it in the order-confirmation page

how to do that?? using session variable or cache variables??? and what is the best controller to call it and to store this value?

do i need to call the cart controller using json with a custom method that store this value in a session/cache variable

 

 

Thanks In Advance

Best Regards 

Edited by Diachronic (see edit history)
Link to comment
Share on other sites

Well that's what I'm saying. It sounds to me like the point at which you're capturing the data is before the order exists - so no database record to store the value in. If you store the value in the Cart object (and therefor table) instead however you can save it right at the point you capture it from the user (on submission of the form). If you really need to store it in the Order, then you're going to need to hold it somewhere else until the order is created (so I would suggest that again, the place to store it is in the Cart object).

 

Payment modules kick off the order creation in their ValidateOrder() member function but that can be called within a return/callback controller from the payment provider, so not so easily accessible. There are hooks in the order creation process that you can use from your module though to take action on a new order but I don't think you can guarantee that you'll have any access to the user session or cookie. There's a very good reason that all the other data captured during the checkout process (e.g. the delivery and invoice addresses) are stored initially in the Cart object ;)

 

EDIT: I just noticed that you only mention displaying it on the order confirmation page. If that's really the only place you need to see it then there's probably no need to store it in anything other than the user cookie, although I suspect you need that information after the order has completed too?

Edited by Paul C (see edit history)
Link to comment
Share on other sites

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...