Question

im trying to add a filed to the checkout page to request a telephone number beofre the order is processed.

Im my checkout.tpl i have added

 <label for"telephone">Phone Number</label><input type="text" name="telephone" value="<?php echo $telephone; ?>" required="required" />

in the checkout.php controller

$this->data['telephone'] = $this->customer->getTelephone();

So it displays the available telephone number in the profile by default and gives the chance for the user to change it.

But the problem im having is when i a order is processed with a new phone number, in the order it saves the old number.

when i print the value in $this->request->post['telephone'] it says

Undefined index: telephone

even that input filed holds a value. Can someone please tell me what am i doing wrong here?

Was it helpful?

Solution

Its because the field you made never get posted to checkout.php.

See in checkout page everything happens by ajax calls. when you are in initial checkout page, it will get the content of one of the tpl ( payement_address.tpl, guest_shipping.tpl etc) depending on the option the user selects like register account or guest checkout or it opens directly the billing address if user is already logged in

Now after these respective tpl are loaded via ajax, fields in them are posted to their respective controller via ajax. controllers are located at catalog/controller/checkout

So you would not want to add the field randomly in checkout.tpl but in one of these stage like shipping_address.tpl

then add your $this->session->data['telephone'] = $this->request->post['telephone'] in public function validate() of shipping_address controller

beware there is condition of if(existing address) else if (new address) so add it accordingly after thing for few minutes (don't ask question for that in SO :P )

then finally you will need to add this telephone to confirm.php controller

replace

$data['telephone'] = $this->customer->getTelephone();

with

$data['telephone'] = $this->session->data['telephone'];

and

$data['telephone'] = $this->session->data['guest']['telephone'];

to

$data['telephone'] = $this->session->data['telephone'];

This should be all. I might have missed something but that's the whole purpose you gotta learn things yourself

P.S. from next time try little harder, you must have known by looking at tpl file that post request never goes to checkout.php controller and just adding a variable to controller file is not enough you also have to make changes at the places where data is about to get saved in databse

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top