Page 1 of 1

inserting custom field to order table

Posted: Tue Dec 20, 2011 3:00 pm
by giri_ptl
I am facing a problem while inserting custom field value to order table

below is the code

1. catalog\language\english\checkout\checkout.php

Code: Select all

    $_['entry_salutation']      = 'Salutation:';
2. catalog\view\theme\default\template\checkout\payment.tpl

Code: Select all

      <tr>
          <td><?php echo $entry_salutation; ?></td>
          <td><input type="text" name="salutation" value="<?php echo $salutation; ?>" /></td>
        </tr>
       <tr>
3. \catalog\controller\checkout\payment.php

Code: Select all

     $this->data['entry_salutation'] = $this->language->get('entry_salutation');
     if (isset($this->request->post['salutation'])) {
                    $this->data['salutation'] = $this->request->post['salutation'];
                } else {
                    $this->data['salutation'] = '';
                }
4. \catalog\model\checkout\order.php

Code: Select all

      salutation  = '" . $this->db->escape($data['salutation']) . "'
this is wat i am doing to insert the field value to order table

but i am getting error please help me

thanks
vinay

Re: inserting custom field to order table

Posted: Tue Dec 20, 2011 4:18 pm
by alin
What is your error information?

Re: inserting custom field to order table

Posted: Tue Dec 20, 2011 5:41 pm
by giri_ptl
SyntaxError: Unexpected token ILLEGAL

Re: inserting custom field to order table

Posted: Tue Dec 20, 2011 6:13 pm
by jimmyphong
Yes you get erorr is right !

you mean you add an input in step payment (same comment) on checkout page ?

if right !
please check file :catalog/view/theme/default/template/checkout/checkout.tpl (line 902)
when you click continue button in payment methol step : the code with this action:

Code: Select all

$('#button-payment').live('click', function() {
	$.ajax({
		url: 'index.php?route=checkout/payment', 
		type: 'post',
		data: $('#payment-method input[type=\'radio\']:checked, #payment-method input[type=\'checkbox\']:checked, #payment-method textarea'),
		dataType: 'json',
		beforeSend: function() {
			$('#button-payment').attr('disabled', true);
			$('#button-payment').after('<span class="wait">&nbsp;<img src="catalog/view/theme/default/image/loading.gif" alt="" /></span>');
		},	
		complete: function() {
			$('#button-payment').attr('disabled', false);
			$('.wait').remove();
		},			
		success: function(json) {
			$('.warning').remove();
			
			if (json['redirect']) {
				location = json['redirect'];
			}
			
			if (json['error']) {
				if (json['error']['warning']) {
					$('#payment-method .checkout-content').prepend('<div class="warning" style="display: none;">' + json['error']['warning'] + '</div>');
					
					$('.warning').fadeIn('slow');
				}			
			} else {
				$.ajax({
					url: 'index.php?route=checkout/confirm',
					dataType: 'json',
					success: function(json) {
						if (json['redirect']) {
							location = json['redirect'];
						}	
					
						if (json['output']) {
							$('#confirm .checkout-content').html(json['output']);
							
							$('#payment-method .checkout-content').slideUp('slow');
							
							$('#confirm .checkout-content').slideDown('slow');
							
							$('#payment-method .checkout-heading a').remove();
							
							$('#payment-method .checkout-heading').append('<a><?php echo $text_modify; ?></a>');	
						}
					},
					error: function(xhr, ajaxOptions, thrownError) {
						alert(thrownError);
					}
				});					
			}
		}
	});	
});
see the code with this ajax:

Code: Select all

data: $('#payment-method input[type=\'radio\']:checked, #payment-method input[type=\'checkbox\']:checked, #payment-method textarea'),
you must add more element for the input post data
//post data to payment
ex:

Code: Select all

data: $('#payment-method input[type=\'radio\']:checked, #payment-method input[type=\'checkbox\']:checked, #payment-method textarea,#payment-method input[name=\'salutation\']'),
openfile :
catalog\controller\checkout\payment.php

find (line 48)

Code: Select all

$this->session->data['comment'] = strip_tags($this->request->post['comment']);
add
//get salution value

Code: Select all

$this->session->data['salutation'] = strip_tags($this->request->post['salutation']);
openfile catalog\controller\checkout\confirm.php
find :

Code: Select all

$data['comment'] = $this->session->data['comment'];
add
//get salution when complete payment
find :

Code: Select all

$data['salutation'] = $this->session->data['salutation'];
Note :
and do step add in model :


try agian !

Re: inserting custom field to order table

Posted: Tue Dec 20, 2011 7:51 pm
by giri_ptl
yes sir this is working

thank u very much for your post, i am trying this from 3 days but no output, now i got it

thanks once again

Re: inserting custom field to order table

Posted: Sat Mar 29, 2014 4:36 am
by pablich
I'm trying to do the same, and jumps me the following error
sshot-3.png

sshot-3.png (26.46 KiB) Viewed 5210 times

I Detect the error appeared when I add this code

Code: Select all

$this->session->data['id_transporte'] = strip_tags($this->request->post['id_transporte']);

Re: inserting custom field to order table

Posted: Fri Jan 25, 2019 2:30 am
by escurooo
I have the same issue, I need to know if I can add field in the order table I want to add total quantity (sum the totals of each item quantity) and shows in the order table. I am using OC 3.0.2.0

Re: inserting custom field to order table

Posted: Sat Feb 02, 2019 6:44 pm
by beautyepic
First thing: custom fields are not only text fields. You'll likely want to add dates, booleans, arrays...
You also have to deal with privileges and mandatory fields.
The best approach I think is to have a preference table and a data table separately.
Concerning your initial fields, it will be easier to manage them as custom fields, maybe with some "system" privileges in your pref table.
Another important point is custom fields groups. Most likely, your users will ask for it so build it from the start. That's another table.
At Sellsy we added CF long after releasing the software and we would have been faster if we took all this into consideration from the ground up.