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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

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, Ed, frankmullenger, biapar, Willr, Ingo, Jedateach, swaiba

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


Go to End


5 Posts   2458 Views

Avatar
coreyheyhey

Community Member, 1 Post

16 February 2009 at 3:41pm

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));

Avatar
Jay-Dee

Community Member, 11 Posts

15 August 2009 at 7:14am

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.

Anyone?

Thanks
Jay

Avatar
bennettpr

Community Member, 37 Posts

18 August 2009 at 3:15pm

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

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.

Avatar
Jay-Dee

Community Member, 11 Posts

19 August 2009 at 1:29am

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
Jay!

Avatar
bennettpr

Community Member, 37 Posts

19 August 2009 at 7:58am

Hi Jay Dee,

Try (something like) this in your template

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

$Year will / should display the year data.

:)
Paul