Jump to content

Displaying custom field from ps_product


GaZoink

Recommended Posts

I've learned a great deal by getting hands-on and under the hood with PrestaShop, but there's something I'm battling with and I'm sure someone would be able to point me in the right direction.

 

I've created a new column in the ps_product and ps_product_shop (not sure which one is pulled from) table called 'msrp' (decimal - 20,6) which captures the msrp of a product. I use it to create my "regular" product pricing (tiered formula run in PHPmyAdmin via SQL formula). However, I think it would aid in conversions if I could display the MSRP on the product page somwhere (below the description or availability, etc).

 

This is where I get a little lost...

 

I'm using the default template and think I need to adjust the theme's product.tpl file and the controller product.php file. However, I can't seem to get it to work.

 

Any guidance that someone could provide would be greatly appreciated.

 

Thanks in advance!

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

Hi,

First of all, you should create a Product class override. You must declare your new column as a publi variable there (just have a look at how it's done in the default product class.

 

Then, redeclare getFields, call parent::getfields to get all the default fields, then add your column to the array (again, look at how it's done in the default class).

 

Finally, in the product page call $product->column_name.

 

That's it!

 

This way you can also change the value from the back office if you add the proper input field

  • Like 1
Link to comment
Share on other sites

Quick follow up question ...

 

Do I copy the "old" product.php file to the override directory and add the variable or do I simply need to create a small php file that just instatiates the new variable?

Link to comment
Share on other sites

More or less.

 

You have to extend the productcore clas with one named Product, then declare your variables and extend getFields to be sure it gets assigned and properly saved. I believe in 1.5 it also needs to be added to the default fields, you can see them in the default file

 

 

 

I should definitely make a tut about this!

Link to comment
Share on other sites

I should definitely make a tut about this!

 

 

Yes please!!!!

 

Hi, I'm trying to add some functionality to my shop, I want to create a purchasing system parallel to the existing.

So I need some new output (setted by the admin) and input (setted by the user) fields, they will be showed at the product template besides to the info already shown, with an extra button created to submit and execute the new service.

 

I've tryed to override the ProductController and product.tpl, but i'm not sure how to show my product.tpl, because if I copy the original ProductController to mine, and define as:

 

class ProductController extends ProductControllerCore

 

If I define, at my class, and copy the function initContent() that's the function, that sets the template to be shown, and change the template path, this function calls to parent::initContent();, at the original ProductController.php (the core) its parent is the FrontController, but on my new class the parent is the ProductControllerCore, so it will call the initContent() from ProductController.php and this will call the initContent() from FrontController.php, so it will be shown 2 product templates (my template at the top and the original surrounded by the FrontController content), like this:

http://img62.imageshack.us/img62/1450/paraborrar.jpg

 

If you can give some advice, would be great.

 

Thanks.

 

PS: sorry if i have some mistakes on my english

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