I’ve figured out how to add new field to database using Prestashop (1.4.3, but I think for the newer versions would be the same). This solution gives you new field in database and you will be able to edit / save data to this field in your admin panel, for my example I needed a field which was called “number of photos”. Below you can see how it works.
When you want to get it you should make some improvements. First of all just create a new field in your database it will be called “nb_photos” in my case.
1 |
ALTER TABLE `ps_product` ADD `nb_photos` INT UNSIGNED NOT NULL DEFAULT '0' |
And then:
1. Open AdminProducts.php file (/[admin_panel]/tabs/AdminProducts.php) and add this line (line 2194):
1 2 3 4 5 6 7 |
<tr> <td class="col-left">'.$this->l('Number of photos:').'</td> <td style="padding-bottom:5px;"> <input size="55" type="text" name="nb_photos" value="'.htmlentities($this->getFieldValue($obj, 'nb_photos'), ENT_COMPAT, 'UTF-8').'" style="width: 130px; margin-right: 44px;" /> <span class="hint" name="help_box">'.$this->l('Number of photos') . '</span> </td> </tr> |
2. Open Product.php (classes/Product.php) and add:
Line 130
1 2 |
/** @var integer Number of photos */ public $nb_photos; |
Line 231
1 2 3 |
'ean13' => 'isEan13', 'nb_photos' => 'isUnsignedInt', // this field 'upc' => 'isUpc', |
Line 340
1 2 3 |
$fields['ean13'] = pSQL($this->ean13); $fields['nb_photos'] = pSQL($this->nb_photos); $fields['upc'] = pSQL($this->upc); |
And that’s all.
If you need some more information about it just let me know using comments box
Miguel Rojas
/ March 16, 2012hello, great job !!!
any question… for modify ?????
Miguel Rojas
/ March 16, 2012but if field is a text field ???
‘my_new_field’ => ‘isUnsignedInt’, // this field ?????
‘my_new_field’ => ‘isText’ OR I NEED Tools:GetValue() ????????
Giacomo
/ April 2, 2012Thank a lot for your guide!
and to display this value in front office?
strife
/ June 12, 2012Hi,
I think you’ve already found the solution for it but let me anwer (maybe somebody else will need this information).
In frontend you should use something like that:
product.tpl
Let me know if it’s working or if you have any questions.
Thanks!
sepahan
/ April 10, 2012how to show this field in fo????
strife
/ June 12, 2012Have you tried this?
Best,
M
pradyuman
/ April 20, 2012Thank You very much…
I have used your instruction and it is working fine.
pradyuman
/ April 24, 2012Now I have just inserted a field as wholesaler price at admin panel and that is inserted at product table but how the wholesaler price will go to product page and how when a wholesaler will login at that time how he/she can buy their product with their wholesaler price not the retailer price.
I have already tried for grouping but grouping is not fullfilling my requirements then how will I do?
Please help me asap…I expect help from you.
strife
/ June 12, 2012I assume the issue is after getting a payment I am right? You want to put the new price instead of old one? :>
The ugly solution for this is … to make changes in the model. You can simply go to the model and put the condition if person is a wholesaler and then return the appropriate price.
Does it make sense?
Let me know if it’s still ready to solve
Best,
M
ania
/ June 18, 2012so how to make new field for ‘dollar price’, i use prestashop v.1.3.6.
please help me
thanks before
strife
/ June 18, 2012Hi,
That’s pretty simple if I understand well what you’ve said. What you’re gonna do is go to the product details and click to the “Prices” tab. And then you’ll see what you wanna get.
However, I am not sure if this is what you wanted. In other words it’s not necessary to make a new field for this
dollar price
coz you can configure it already (All products can have a specific price for each currency).Even though, if you really want to create a new field you can just do it in the way that I wrote and print it out in the frontend this way (http://strife.pl/2012/06/how-to-change-the-original-price-in-prestashop/).
Let me know if this helps or not
Best,
M
VERO20
/ July 31, 2012Hello! how would you do that for text?
strife
/ September 11, 2012Hi VERO20,
You can do it by the same token as you’re doing it for integer. Check the whole Product.php and try to find any text fields and copy it. If you had problems let me know.
Best,
M
zounars
/ August 7, 2012Hello,
Thank you for your tutorial.
How can I add a datepicker to the custom field?
Thanks
Julius
/ August 11, 2012zounars
Try to use jquery ui datepicker. It is very easy to integrate.
antony
/ August 27, 2012add custom field in Combination tab
arnold
/ September 5, 2012Hello,
I tried your tutorial, the only difference is that custom field is an ENUM just like condition, with Prestashop 1.4.9 i’m getting:
An error occurred while updating object. product (), did anyone encounter this?
strife
/ September 11, 2012Hi arnold,
That’s interesting. Thanks for this spot. Do you have any more errors occurred? It’s quite less information to help you without working on your version …
M
Hernan
/ September 5, 2012Hello,
where insertion is performed on data, ie , the data insert.
in what php document or is in the same product.php
Jashen
/ September 11, 2012Hello every one, I am trying to integrate a date picker in order-carrier.php
But don’t it don’t seems to work. It is as if the css is not taken into consideration.
Any help will be welcome.
Thank you
strife
/ September 11, 2012Hi Jashen,
Tell me what you see in Firebug. Might the path is wrong, what you think about it?
Best,
M
Lucas
/ September 17, 2012Hi,
Im in big need of adding a text field to the check out-process. I need them to write a number (for identification) and I need to receive it.
Can I use any of your code for this?
Thanks.
strife
/ December 6, 2012Sorry for late reply.
Yes sure you can do whatever you do with this.
Best,
M
RBucci
/ December 12, 2012Strife,
I’m really grateful for your tutorial, however taking a closer look, I was wondering if you could give me a hand with what I need to do;
I’m creating a cart for a company that doesn’t have clients but employees. The employees are salesmen that will be connected to the website via a tablet each time they visit a client in order to send the order to the main office. The problem is that they need to be able to have the main price as well as a blank field in which they can input the price with which they agreed on with the final customer.
I’m in need to enable a blank textfield (modifiable by the employees) under the price in all the products pages before the “Add to Cart” button so that afterwards, in the Shopping Cart Summary it will behave like the normal price (adding the total to the bottom) and storing it as a record for the employees to keep track of their comissions in the order history. And if possible, including those prices in the confirmation email.
If there’s any way to do this, I will be able to sleep at night once again.. I’ve been trying very hard to do this but so far I got nowhere near..
Thank you so much for your time!!!
strife
/ December 12, 2012Hi RBucci,
Ok. So I can suggest you to modify the model in the Prestashop. What you need to do is:
Find the model for products and modify it in the way that enables you to affect to the price. I think you can use sessions because each of employers would put the price manually.
I mean something like this:
< ?php function getPrice() { // and here you can check if something is in the sessions // and replace it instead of actual product price } ?>
I don’t know if you want to replace the current price or just only add the new field above/below it. However, I understand that you want to replace it. And this solution should fix your problem. If not let me know.
Any questions feel free to ask.
Best,
Maciej
RBucci
/ December 12, 2012I really don’t understand what you mean with that code, Maciej. Maybe you could exemplify?
Thanks!!
carlos soratto
/ February 8, 2013PERFECT! THANKS!
Bruna
/ February 27, 2013Congratulation for your tutorial, it work very well!
You save my day Strife, thanks a lot!
(VERO20) FOR TEXT:
Instead of adding this:
‘nb_photos’ => ‘isUnsignedInt’, // this field
add this:
‘nb_photos’ => ‘isString’, // this field
and on the first step you need to alter the data type(INT for VARCHAR(100) or char(50))
ALTER TABLE
ps_product
ADDnb_photos
VARCHAR(100) UNSIGNED NOT NULL DEFAULT ‘0’TKS
Bruna
/ March 4, 2013Hi how can i add fields in a module tpl?
Thanks
muhsin
/ April 4, 2013Hai
i am new to prestashop and now i am creating custom API for a mobile app.
i want a custom sql query to get cart and cart products of a loged customer.
Recox
/ July 29, 2013Can you explain , how can we import/export csv the new fields that we created in the products table???
ashish
/ October 9, 2013hey nice work,
I want to add tag field in manufacturer page…
You have any idea what i have to do for that…
Also in tag field array generate so how i insert it in db.
Example:
manufacturer name ashish
tag field aish, aashish, asish
So how i insert it in db ?
Thank you
Nelson
/ November 25, 2013Hi.
Great help.
I just have one question. I need the field to be a Link, instead of text.
Basically i want the field to be called “Manufacturers URL”, insert the product link for the manufacturers webpage in the backoffice and in the front office the client can click on “Manufacturers URL” to get into manufacturers page.
Nelson
/ November 25, 2013I am having difficulties with this on 1.5.6.
I don’t find the AdminProducts.php, only AdminProductsController.php, under /Controllers/Admin
is this file?
Also, in product.php my file does not have this type strings anywere
$fields[‘ean13′] = pSQL($this->ean13);
$fields[‘nb_photos’] = pSQL($this->nb_photos);
$fields[‘upc’] = pSQL($this->upc);
Nevertheless i’ve tried to do this in this files, and the backoffice product page stops working. I had to put back the original files
Roland
/ December 12, 2013Thankyou. Is perfect
Patrick
/ January 6, 2014Hi,
In Prestashop 1.4.7.0, there are only tow lines for the customer address.
Some times, 2 lines is not enough to write a precise address, that can include a building n°, a stair n° and so on.
On some well known sites, I could see up to 4 lines to write the customer address.
Would you know how to add a field to the customer address, both when he orders as a registered customer or as a guest.
Thank you in advance for any help in this matter.
Patrick
Pavlos
/ January 24, 2014Hi,
Can you alter this code so an extra text field for various comments is shown in each order seperately?
Regards
Faran ALi
/ February 28, 2014Where have to place this
$fields[‘nb_photos’] = pSQL($this->nb_photos);
not working on classes/product.php
line 340
matteo
/ March 6, 2014Hi,
If i want to add a label with check field to show a icon (like best offers) inside a product image in frontend what can i do?
Thank you in advance for your help
M
Roberto
/ April 11, 2014I think coding will be tough for a non-technical person, mos website owners will not have that expertise to code it, here a forum thread from prestashop that talks about a module that allows you to add custom checkout fields prestashop.com/forums/topic/315353-module-prestashop-checkout-custom-fields/?hl=%2Bcustom+%2Bcheckout#entry1624217
strife
/ April 11, 2014Hi there,
Thank you all for comments.
@Roberto – It looks pretty nice but you have to pay for this module. Might I should write something for free for the community. There are lots of feedbacks about this post on Google and ppl really want to have it.
Thank you once again. I will keep you posted guys.
M
Marie
/ September 15, 2014Hi,
Sorry for my bad English.
I want to add extra fields on my checkout page like I want to add “refer to friend”, ID card number & Blood group. how I can add?
Thanks,
asdfjklm
/ January 23, 2015Hey! I don’t know the right solution. But its bad idea to modify the core of prestashop. Because, If you upgrade prestashop to newer version, changes may be lost. You should try to override the classes by putting in override directory of your theme.
strife
/ February 26, 2015You’re right. It’s ugly solution. I will update this post soon to provide more elegant solution for this problem.
Thanks,
M
marian
/ July 14, 2015heloo sfrife.. When
Amelia
/ July 15, 2015Hi, I was just looking to add some field on checkout page of my shop at checkout step#4, in fact adding a text box there. I looked on your tutorial but it seems out dated as depicted in comments. I also looked for modules to get solution for my site and found one. http://bit.ly/1DgrsLi
I have to ask from you that you are going to update the tutorial or I will go for a paid solution.
Thanks in advance
ceny
/ June 4, 2016Ahaa, its pleasant conversation on the topic of thos pos here at this blog,
I have readd all that, so nnow me also commenting here.
Dipak Chatterjee
/ November 28, 2016How to add file type fields in registration ?
Dipak Chatterjee
/ November 28, 2016Say we want to upload the customer image in the same table. The field name will be Upload Your Profile Picture. How to do that in prestashop ?
test
/ May 5, 2017Thanks for another magnificent post. Where else may just anyone get that type of information in such
an ideal means of writing? I’ve a presentation next week, and I’m at the look for such
info.
www.theentertaininghouse.com
/ May 29, 20175 Blogging Tips To Start Internet Home Business
boris https://yandex.ru
/ June 18, 2021boris https://yandex.ru