Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

E-Commerce Modules

Discuss about the various e-commerce modules available:
Ecommerce, SS Shop, SilverCart and SwipeStripe
Alternatively, have a look the shared mailinglist.

Moderators: martimiz, Nicolaas, Sean, frankmullenger, biapar, Willr, Ingo, Jedateach, swaiba, simon_w

How to add a new field to the product.php file?


5 Posts   1786 Views


16 February 2009 at 3:41pm Community Member, 1 Post

After I added a new field in the product page, I got a problem to save the content. I got the Content Save Error.
I tried to change some .SS files but still the same error.
What else i should chage?
      $fields->addFieldToTab("Root.Content.Main", new TextField("Weight", "Weight (kg)", "", 12));
      $fields->addFieldToTab("Root.Content.Main", new TextField("Price", "Price", "", 12));
      $fields->addFieldToTab("Root.Content.Main", new TextField("Model", "Author", "", 50));
      $fields->addFieldToTab("Root.Content.Main", new TextField("Workshop", "Speaker", "", 50));


15 August 2009 at 7:14am Community Member, 11 Posts

I would also like to know how to do this.

I've added extra fields, and after doing db/build, I don't get any errors after saving and publishing. However, the new fields won't show up on the product page.




18 August 2009 at 3:15pm Community Member, 37 Posts

you need to make sure the fields are added in the model as well.

static $db = array(
      'Price' => 'Currency',
      'Weight' => 'Decimal(9,2)',
      'Model' => 'Varchar',
      'FeaturedProduct' => 'Boolean',
      'AllowPurchase' => 'Boolean',
      "InternalItemID" => "Varchar(30)",

That way SilverStripe will know where to save the data.


19 August 2009 at 1:29am Community Member, 11 Posts

Hey Bennett, thanks for your reply. I have done this already.. I added the following line to that array.

'Year' => 'Varchar',

And the following line to the getCMSFields function.

$fields->addFieldToTab("Root.Content.Main", new TextField("Year", "Year", "", 50));

I can see the field when I want to create a new product, I can type in the YEAR, I can save it and publish it, but when I go to the product page, "Year" is not displayed.

Do you know why this is happening?
Thank you


19 August 2009 at 7:58am Community Member, 37 Posts

Hi Jay Dee,

Try (something like) this in your template

<div class="year">
Year: $Year

$Year will / should display the year data.