but43r Posted March 25, 2012 Share Posted March 25, 2012 Hi guys, I'm trying to add custom fields to Customer in One Page Checkout and I'm running into problems. I'm trying to add checkbox and that's what I have modified so far: Customer.php At the top I have, /** @var boolean My Checkbox */ public $my_checkbox; In getFields() function I have added, $fields['my_checkbox'] = (int)($this->my_checkbox); OrderOpcController.php in case 'editCustomer': I have added $customer->my_checkbox) = (int)Tools::isSubmit('my_checkbox'); In _getGuestInformations() function 'my_checkbox' => (int)($customer->my_checkbox) And finally in order-opc-new-account.tpl I added: <input type="checkbox" name="my_checkbox" id="my_checkbox" value="0" {if isset($guestInformations) && $guestInformations.my_checkbox}checked="checked"{/if} style="float:right;" /> I have also added my_checkbox field to database on ps_customer table. The strange thing is - It works if I do following: Add product to shopping cart - Fill in my details and Check the checkbox - Click save - Select my payment method - Click checkout AGAIN - have to check my checkbox again - click save - select payment method and click Confirm my order. The checkbox field gets updated and everthing works. If I do the following my_checkbox field in database doesn't get set. Add product to shopping cart - Fill in my detaisls and Check my checkbox - click save - select my payment - click Confirm my order. What am I missing here? Have I missed a step along the way? Any help appreciated. Link to comment Share on other sites More sharing options...
but43r Posted March 25, 2012 Author Share Posted March 25, 2012 Just in case if someone is looking for an answer for this - found what the problem was. I just had to add my_checkbox field to fieldsValidate array in Customer.php and it worked like a charm. 1 Link to comment Share on other sites More sharing options...
Amazzing Posted April 8, 2012 Share Posted April 8, 2012 Hello, Thank you for this guide. I have managed to add an additional checkbox to my site. But I need to make this checkbox a required field. For this, I have added 'my_checkbox' to $fieldsRequired = array in customer.php So, it works fine when you complete the form for the first time. You cannot save informations uless you check this box. BUT: if you hit "save" and then uncheck the box, and then hit "save" again no any warning is displayed and a message appears: infomation was saved successfully. Any ideas, why this is happening? Link to comment Share on other sites More sharing options...
but43r Posted April 8, 2012 Author Share Posted April 8, 2012 It sounds like what you need is Radio button instead of Checkbox. It makes sense that it would let you save it second time as it's not null anymore. Link to comment Share on other sites More sharing options...
Amazzing Posted April 8, 2012 Share Posted April 8, 2012 It sounds like what you need is Radio button instead of Checkbox. It makes sense that it would let you save it second time as it's not null anymore. Thank you for the reply, I got your idea. But radio button is not exactly what I need. It doesnt' give an option to "uncheck". May be there is a function, that can make checkbox null when it is unchecked? Link to comment Share on other sites More sharing options...
but43r Posted April 8, 2012 Author Share Posted April 8, 2012 Why do you need a checkbox that has to be checked? It makes no sense (unless its something like I have read and I accept the terms and conditions). I mean you are only allowing 1 valid state for your checkbox which means you don't need it. If it is something like terms and conditions that I mentioned above then you can validate your checkbox input in Customer.php Link to comment Share on other sites More sharing options...
Amazzing Posted April 9, 2012 Share Posted April 9, 2012 If it is something like terms and conditions that I mentioned above then you can validate your checkbox input in Customer.php It is exactly something like "terms and conditions". I did the followings for validation: 1) added 'my_checkbox' => 'isBool' to the $fieldsValidate = array 2) added $fields['my_checkbox'] = (int)($this->my_checkbox) to the public function getFields() { parent::validateFields(); Anything else need to be done for validation? Link to comment Share on other sites More sharing options...
but43r Posted April 12, 2012 Author Share Posted April 12, 2012 It is exactly something like "terms and conditions". I did the followings for validation: 1) added 'my_checkbox' => 'isBool' to the $fieldsValidate = array 2) added $fields['my_checkbox'] = (int)($this->my_checkbox) to the public function getFields() { parent::validateFields(); Anything else need to be done for validation? Yes, you will have to validate that the value of your checkbox field is set to true. Have a look at Address.php and how phone number validation is done and implement something similar for Customer.php where the value of your checkbox field is checked. Btw, there is Termos of Service checkbox that you can enable in the Back Office - is that not sufficient? Link to comment Share on other sites More sharing options...
eduard02 Posted July 1, 2014 Share Posted July 1, 2014 Hi, Can you please explain where exactly on line you add changes, using prestashop 1.5.6.2 and can't find exactly all this lines. Thank you. In getFields() function I have added,$fields['my_checkbox'] = (int)($this->my_checkbox); OrderOpcController.php in case 'editCustomer': I have added$customer->my_checkbox) = (int)Tools::isSubmit('my_checkbox');In _getGuestInformations() function'my_checkbox' => (int)($customer->my_checkbox) 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